Class BinaryDtoIndexedCodec<T extends BaseBinaryDto<T>>
java.lang.Object
io.datarouter.bytes.binarydto.codec.BinaryDtoIndexedCodec<T>
- All Implemented Interfaces:
Codec<T,byte[]>
public class BinaryDtoIndexedCodec<T extends BaseBinaryDto<T>> extends Object implements Codec<T,byte[]>
For encoding non-key fields.
The output is not comparable, but it allows adding and removing fields while staying backwards compatible with data
serialized by previous dto versions.
Note that index re-use is dangerous unless you are certain that persisted data is free of the previous index. There
is not much benefit to reusing an index, only a tiny bit if you are exceeding index 127, which is where the varint
encoding starts taking a second byte.
Fields are made of 3 pieces:
- index, as specified in the field's annotation or inferred by alphabetical field order
- length, the number of bytes in the value section.
- We need this to know how many bytes to skip in case the field is removed from the dto.
- value, the actual value bytes for the field
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.datarouter.bytes.Codec
Codec.FunctionalCodec<A,B>, Codec.NullPassthroughCodec<A,B> -
Field Summary
Fields Modifier and Type Field Description Class<T>dtoClassList<Field>fieldsList<? extends BinaryDtoFieldSchema<?>>fieldSchemas -
Method Summary
Modifier and Type Method Description Tdecode(byte[] bytes)Tdecode(byte[] bytes, int offset, int length)byte[]encode(T dto)List<Field>getFieldsOrdered()static <T extends BaseBinaryDto<T>>
BinaryDtoIndexedCodec<T>of(Class<? extends T> dtoClass)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.datarouter.bytes.Codec
encodeAndDecode
-
Field Details
-
dtoClass
-
fields
-
fieldSchemas
-
-
Method Details
-
of
public static <T extends BaseBinaryDto<T>> BinaryDtoIndexedCodec<T> of(Class<? extends T> dtoClass) -
getFieldsOrdered
-
encode
- Specified by:
encodein interfaceCodec<T extends BaseBinaryDto<T>,byte[]>
-
decode
- Specified by:
decodein interfaceCodec<T extends BaseBinaryDto<T>,byte[]>
-
decode
-