getBaseXResliceCodec
getBaseXResliceCodec(
alphabet
,bits
):VariableSizeCodec
<string
>
Returns a codec for encoding and decoding base-X strings using bit re-slicing.
This codec serializes strings by dividing the input into custom-sized bit chunks, mapping them to a given alphabet, and encoding the result into bytes. It is particularly suited for encoding schemes where the alphabet's length is a power of 2, such as base-16 or base-64.
Parameters
Parameter | Type | Description |
---|---|---|
alphabet | string | The set of characters defining the base-X encoding. |
bits | number | The number of bits per encoded chunk, typically log2(alphabet.length) . |
Returns
VariableSizeCodec
<string
>
A VariableSizeCodec<string>
for encoding and decoding base-X strings using bit re-slicing.
Example
Encoding and decoding a base-X string using bit re-slicing.
Remarks
This codec does not enforce a size boundary. It will encode and decode all bytes necessary to represent the string.
If you need a fixed-size base-X codec, consider using fixCodecSize.
If you need a size-prefixed base-X codec, consider using addCodecSizePrefix.
Separate getBaseXResliceEncoder and getBaseXResliceDecoder functions are available.