getBaseXCodec
getBaseXCodec(
alphabet
):VariableSizeCodec
<string
>
Returns a codec for encoding and decoding base-X strings.
This codec serializes strings using a custom alphabet, treating the length of the alphabet as the base. The encoding process converts the input string into a numeric value in base-X, which is then encoded as bytes. The decoding process reverses this transformation to reconstruct the original string.
This codec supports leading zeroes by treating the first character of the alphabet as the zero character.
Parameters
Parameter | Type | Description |
---|---|---|
alphabet | string | The set of characters defining the base-X encoding. |
Returns
VariableSizeCodec
<string
>
A VariableSizeCodec<string>
for encoding and decoding base-X strings.
Example
Encoding and decoding a base-X string using a custom alphabet.
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 getBaseXEncoder and getBaseXDecoder functions are available.