import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from './codec'; import { ReadonlyUint8Array } from './readonly-uint8array'; /** * Creates an encoder that writes a `Uint8Array` sentinel after the encoded value. * This is useful to delimit the encoded value when being read by a decoder. * * See {@link addCodecSentinel} for more information. * * @typeParam TFrom - The type of the value to encode. * * @see {@link addCodecSentinel} */ export declare function addEncoderSentinel(encoder: FixedSizeEncoder, sentinel: ReadonlyUint8Array): FixedSizeEncoder; export declare function addEncoderSentinel(encoder: Encoder, sentinel: ReadonlyUint8Array): VariableSizeEncoder; /** * Creates a decoder that continues reading until * a given `Uint8Array` sentinel is found. * * See {@link addCodecSentinel} for more information. * * @typeParam TTo - The type of the decoded value. * * @see {@link addCodecSentinel} */ export declare function addDecoderSentinel(decoder: FixedSizeDecoder, sentinel: ReadonlyUint8Array): FixedSizeDecoder; export declare function addDecoderSentinel(decoder: Decoder, sentinel: ReadonlyUint8Array): VariableSizeDecoder; /** * Creates a Codec that writes a given `Uint8Array` sentinel after the encoded * value and, when decoding, continues reading until the sentinel is found. * * This sets a limit on variable-size codecs and tells us when to stop decoding. * * @typeParam TFrom - The type of the value to encode. * @typeParam TTo - The type of the decoded value. * * @example * ```ts * const codec = addCodecSentinel(getUtf8Codec(), new Uint8Array([255, 255])); * codec.encode('hello'); * // 0x68656c6c6fffff * // | └-- Our sentinel. * // └-- Our encoded string. * ``` * * @remarks * Note that the sentinel _must not_ be present in the encoded data and * _must_ be present in the decoded data for this to work. * If this is not the case, dedicated errors will be thrown. * * ```ts * const sentinel = new Uint8Array([108, 108]); // 'll' * const codec = addCodecSentinel(getUtf8Codec(), sentinel); * * codec.encode('hello'); // Throws: sentinel is in encoded data. * codec.decode(new Uint8Array([1, 2, 3])); // Throws: sentinel missing in decoded data. * ``` * * Separate {@link addEncoderSentinel} and {@link addDecoderSentinel} functions are also available. * * ```ts * const bytes = addEncoderSentinel(getUtf8Encoder(), sentinel).encode('hello'); * const value = addDecoderSentinel(getUtf8Decoder(), sentinel).decode(bytes); * ``` * * @see {@link addEncoderSentinel} * @see {@link addDecoderSentinel} */ export declare function addCodecSentinel(codec: FixedSizeCodec, sentinel: ReadonlyUint8Array): FixedSizeCodec; export declare function addCodecSentinel(codec: Codec, sentinel: ReadonlyUint8Array): VariableSizeCodec; //# sourceMappingURL=add-codec-sentinel.d.ts.map