addCodecSizePrefix
Call Signature
addCodecSizePrefix<
TFrom
,TTo
>(codec
,prefix
):FixedSizeCodec
<TFrom
,TTo
>
Stores the byte size of any given codec as an encoded number prefix.
This sets a limit on variable-size codecs and tells us when to stop decoding. When encoding, the size of the encoded data is stored before the encoded data itself. When decoding, the size is read first to know how many bytes to read next.
Type Parameters
Type Parameter | Description |
---|---|
TFrom | The type of the value to encode. |
TTo | The type of the decoded value. |
Parameters
Parameter | Type |
---|---|
codec | FixedSizeCodec <TFrom , TTo > |
prefix | FixedSizeNumberCodec |
Returns
FixedSizeCodec
<TFrom
, TTo
>
Example
For example, say we want to bound a variable-size base-58 string using a u32
size prefix.
Here’s how you can use the addCodecSizePrefix
function to achieve that.
Remarks
Separate addEncoderSizePrefix and addDecoderSizePrefix functions are also available.
See
Call Signature
addCodecSizePrefix<
TFrom
,TTo
>(codec
,prefix
):VariableSizeCodec
<TFrom
,TTo
>
Stores the byte size of any given codec as an encoded number prefix.
This sets a limit on variable-size codecs and tells us when to stop decoding. When encoding, the size of the encoded data is stored before the encoded data itself. When decoding, the size is read first to know how many bytes to read next.
Type Parameters
Type Parameter | Description |
---|---|
TFrom | The type of the value to encode. |
TTo | The type of the decoded value. |
Parameters
Parameter | Type |
---|---|
codec | Codec <TFrom , TTo > |
prefix | NumberCodec |
Returns
VariableSizeCodec
<TFrom
, TTo
>
Example
For example, say we want to bound a variable-size base-58 string using a u32
size prefix.
Here’s how you can use the addCodecSizePrefix
function to achieve that.
Remarks
Separate addEncoderSizePrefix and addDecoderSizePrefix functions are also available.