UNPKG

@cartbc/codecs-strings

Version:

Codecs for strings of different sizes and encodings

26 lines (25 loc) 1.46 kB
import { BaseCodecOptions, Codec, Decoder, Encoder } from '@cartbc/codecs-core'; import { NumberCodec, NumberDecoder, NumberEncoder } from '@cartbc/codecs-numbers'; /** Defines the options for string codecs. */ export type StringCodecOptions<TPrefix extends NumberCodec | NumberEncoder | NumberDecoder, TEncoding extends Codec<string> | Encoder<string> | Decoder<string>> = BaseCodecOptions & { /** * The size of the string. It can be one of the following: * - a {@link NumberCodec} that prefixes the string with its size. * - a fixed number of bytes. * - or `'variable'` to use the rest of the byte array. * @defaultValue u32 prefix. */ size?: TPrefix | number | 'variable'; /** * The codec to use for encoding and decoding the content. * @defaultValue UTF-8 encoding. */ encoding?: TEncoding; }; /** Encodes strings from a given encoding and size strategy. */ export declare const getStringEncoder: (options?: StringCodecOptions<NumberEncoder, Encoder<string>>) => Encoder<string>; /** Decodes strings from a given encoding and size strategy. */ export declare const getStringDecoder: (options?: StringCodecOptions<NumberDecoder, Decoder<string>>) => Decoder<string>; /** Encodes and decodes strings from a given encoding and size strategy. */ export declare const getStringCodec: (options?: StringCodecOptions<NumberCodec, Codec<string>>) => Codec<string>; //# sourceMappingURL=string.d.ts.map