Class ReadEnvelopeChunkedDeserializer<V>
- java.lang.Object
-
- com.linkedin.venice.client.store.streaming.ReadEnvelopeChunkedDeserializer<V>
-
- Type Parameters:
V-
- Direct Known Subclasses:
ComputeResponseRecordV1ChunkedDeserializer,MultiGetResponseRecordV1ChunkedDeserializer
public abstract class ReadEnvelopeChunkedDeserializer<V> extends java.lang.ObjectThis class provides support to deserialize customized records even the input doesn't contain the full record. The user could usewrite(ByteBuffer)to keep writing more data, and the user can useconsume()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
Nested Classes Modifier and Type Class Description static classReadEnvelopeChunkedDeserializer.NotEnoughBytesExceptionException when the deserialization hits partial record.protected static classReadEnvelopeChunkedDeserializer.ValueContainer<V>This class contains two fields: 1.
-
Field Summary
Fields Modifier and Type Field Description static ReadEnvelopeChunkedDeserializer.NotEnoughBytesExceptionNOT_ENOUGH_BYTES_EXCEPTION
-
Constructor Summary
Constructors Constructor Description ReadEnvelopeChunkedDeserializer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.List<V>consume()protected byte[]readBytes(int bytesStartOffset, int bytesLen)Utility method to read byte arrays.protected ReadEnvelopeChunkedDeserializer.ValueContainer<java.lang.Integer>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.protected ReadEnvelopeChunkedDeserializer.ValueContainer<java.lang.Integer>tryReadInt(int currentOffset)The following implementation is equivalent toBinaryDecoder.readIndex()voidwrite(java.nio.ByteBuffer bytes)
-
-
-
Field Detail
-
NOT_ENOUGH_BYTES_EXCEPTION
public static final ReadEnvelopeChunkedDeserializer.NotEnoughBytesException NOT_ENOUGH_BYTES_EXCEPTION
-
-
Method Detail
-
consume
public java.util.List<V> consume()
-
write
public void write(java.nio.ByteBuffer bytes)
-
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<java.lang.Integer> tryReadInt(int currentOffset) throws ReadEnvelopeChunkedDeserializer.NotEnoughBytesException
The following implementation is equivalent toBinaryDecoder.readIndex()
-
readBytesMeta
protected ReadEnvelopeChunkedDeserializer.ValueContainer<java.lang.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.NotEnoughBytesExceptionUtility method to read byte arrays. We could not reuse the underlying byte array even the requested bytes are fully contained by one singleReadEnvelopeChunkedDeserializer.BytesContainersince the internalByteBufferis 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
-
-