Interface declaring handling of received packets. When receiving a packet, its content is sent to feed(), and codec is supposed to emit packet or error event when packet is parsed.

interface IPacketCodec {
    decode: (buf: Bytes, eof: boolean) => MaybePromise<null | Uint8Array>;
    encode: (frame: Uint8Array, into: ISyncWritable) => MaybePromise<void>;
    reset: () => void;
    setup(crypto: ICryptoProvider, log: Logger): void;
    tag(): MaybePromise<Uint8Array>;
}

Hierarchy

  • IFrameDecoder
  • IFrameEncoder
    • IPacketCodec

Implemented by

Properties

Methods

Properties

decode: (buf: Bytes, eof: boolean) => MaybePromise<null | Uint8Array>

Decode a frame from a buffer

Important implementation notice: When returning byte arrays, make sure that the returned array is not a view into the original buffer, as the underlying buffer may get invalidated

encode: (frame: Uint8Array, into: ISyncWritable) => MaybePromise<void>

Encode a frame into a writable stream

reset: () => void

Reset the encoder, should it have any internal state

Methods

  • For codecs that use crypto functions and/or logging. This method is called before any other.

    Parameters

    Returns void

  • Initial tag of the codec. Will be sent immediately once connected.

    Returns MaybePromise<Uint8Array>