Class ReadEnvelopeChunkedDeserializer<V>
java.lang.Object
com.linkedin.venice.client.store.streaming.ReadEnvelopeChunkedDeserializer<V>
- Type Parameters:
V
-
- Direct Known Subclasses:
ComputeResponseRecordV1ChunkedDeserializer
,MultiGetResponseRecordV1ChunkedDeserializer
This class provides support to deserialize customized records even the input doesn't contain
the full record.
The user could use
write(ByteBuffer)
to keep writing more data, and the user can use
consume()
to consume all the available records so far.
All the records can only be consumed once, and after the consumption, the underlying byte array
might be freed to reduce GC.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Exception when the deserialization hits partial record.protected static class
This class contains two fields: 1. -
Field Summary
Modifier and TypeFieldDescription -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionconsume()
protected byte[]
readBytes
(int bytesStartOffset, int bytesLen) Utility method to read byte arrays.readBytesMeta
(int currentOffset) Utility method to read bytes array metadata, which contains the byte length and the byte length to store the serialized byte-length.protected abstract ReadEnvelopeChunkedDeserializer.ValueContainer<V>
tryDeserializeRecord
(int currentPos) All the derived class will implement this function to provide the customized logic to deserialize a record, and when hitting partial record, it should throwReadEnvelopeChunkedDeserializer.NotEnoughBytesException
.tryReadInt
(int currentOffset) The following implementation is equivalent toBinaryDecoder.readIndex()
void
write
(ByteBuffer bytes)
-
Field Details
-
NOT_ENOUGH_BYTES_EXCEPTION
public static final ReadEnvelopeChunkedDeserializer.NotEnoughBytesException NOT_ENOUGH_BYTES_EXCEPTION
-
-
Constructor Details
-
ReadEnvelopeChunkedDeserializer
public ReadEnvelopeChunkedDeserializer()
-
-
Method Details
-
consume
-
write
-
tryDeserializeRecord
protected abstract ReadEnvelopeChunkedDeserializer.ValueContainer<V> tryDeserializeRecord(int currentPos) throws ReadEnvelopeChunkedDeserializer.NotEnoughBytesException All the derived class will implement this function to provide the customized logic to deserialize a record, and when hitting partial record, it should throwReadEnvelopeChunkedDeserializer.NotEnoughBytesException
.- Parameters:
currentPos
- : current global offset to deserialize- Returns:
- Throws:
ReadEnvelopeChunkedDeserializer.NotEnoughBytesException
-
tryReadInt
protected ReadEnvelopeChunkedDeserializer.ValueContainer<Integer> tryReadInt(int currentOffset) throws ReadEnvelopeChunkedDeserializer.NotEnoughBytesException The following implementation is equivalent toBinaryDecoder.readIndex()
-
readBytesMeta
protected ReadEnvelopeChunkedDeserializer.ValueContainer<Integer> readBytesMeta(int currentOffset) throws ReadEnvelopeChunkedDeserializer.NotEnoughBytesException Utility method to read bytes array metadata, which contains the byte length and the byte length to store the serialized byte-length. The reason to introduce this method is to avoid the unnecessary byte array copy until current record is a full record.- Parameters:
currentOffset
-- Returns:
- Throws:
ReadEnvelopeChunkedDeserializer.NotEnoughBytesException
-
readBytes
protected byte[] readBytes(int bytesStartOffset, int bytesLen) throws ReadEnvelopeChunkedDeserializer.NotEnoughBytesException Utility method to read byte arrays. We could not reuse the underlying byte array even the requested bytes are fully contained by one singleReadEnvelopeChunkedDeserializer.BytesContainer
since the internalByteBuffer
is read-only sinceByteBuffer.array()
will throwReadOnlyBufferException
. You could refer toByteString.asByteBuffer()
to find more details, which is being used byD2TransportClient
.- Parameters:
bytesStartOffset
-bytesLen
-- Returns:
- Throws:
ReadEnvelopeChunkedDeserializer.NotEnoughBytesException
-