Interfaces
VariableSizeCodec
An object that can encode and decode a value to and from a variable-size byte array.
See Codec to learn more about creating and composing codecs.
Example
See
Type Parameters
Type Parameter | Default type | Description |
---|---|---|
TFrom | - | The type of the value to encode. |
TTo extends TFrom | TFrom | The type of the decoded value. |
Properties
Property | Modifier | Type | Description |
---|---|---|---|
decode | readonly | (bytes , offset? ) => TTo | Decodes the provided byte array at the given offset (or zero) and returns the value directly. |
encode | readonly | (value ) => ReadonlyUint8Array | Encode the provided value and return the encoded bytes directly. |
getSizeFromValue | readonly | (value ) => number | Returns the size of the encoded value in bytes for a given input. |
maxSize? | readonly | number | The maximum possible size of an encoded value in bytes, if applicable. |
read | readonly | (bytes , offset ) => [TTo , number ] | Reads the encoded value from the provided byte array at the given offset. Returns the decoded value and the offset of the next byte after the encoded value. |
write | readonly | (value , bytes , offset ) => number | Writes the encoded value into the provided byte array at the given offset. Returns the offset of the next byte after the encoded value. |