Class PacketDecoder<ContextType>

Type Parameters

  • ContextType = any

Hierarchy

  • PacketDecoder

Methods

  • Returns void

  • Emit a decoded message to all listeners concurrently, also emits the message's children recursively.

    Parameters

    • message: Serializable

      The message to emit.

    • direction: MessageDirection

      The direction that the message was sent.

    • context: ContextType

      Additional metadata for the message, e.g. the context.

    Returns Promise<void>

  • Emit a decoded message to all listeners serially, also emits the message's children recursively.

    Parameters

    • message: Serializable

      The message to emit.

    • direction: MessageDirection

      The direction that the message was sent.

    • context: ContextType

      Additional metadata for the message, e.g. the context.

    Returns Promise<void>

  • Remove a listener from a message.

    Type Parameters

    Parameters

    Returns void

  • Remove a listener from several messages being listened to.

    Type Parameters

    Parameters

    Returns void

  • Listen to a message being sent through the decoder.

    Returns

    A function to remove the listener.

    Type Parameters

    Parameters

    • messageClass: T

      The message to listen for.

    • listener: MessageListener<GetSerialized<T>, ContextType>

      The callback for when the message is decoded.

    Returns (() => void)

      • (): void
      • Listen to a message being sent through the decoder.

        Returns

        A function to remove the listener.

        Returns void

  • Listen to any of several messages being sent through the decoder.

    Returns

    A function to remove the listener.

    Type Parameters

    Parameters

    • messageClass: T

      The messages to listen for.

    • listener: MessageListener<GetSerialized<T[number]>, ContextType>

      The callback for when one of the messages is decoded.

    Returns (() => void)

      • (): void
      • Listen to any of several messages being sent through the decoder.

        Returns

        A function to remove the listener.

        Returns void

  • Listen to a message being sent through the decoder once.

    Returns

    A function to remove the listener.

    Type Parameters

    Parameters

    • messageClass: T

      The message to listen for.

    • listener: MessageListener<GetSerialized<T>, ContextType>

      The callback for when the message is decoded.

    Returns (() => void)

      • (): void
      • Listen to a message being sent through the decoder once.

        Returns

        A function to remove the listener.

        Returns void

  • Listen to any of several messages being sent through the decoder once.

    Returns

    A function to remove the listener.

    Type Parameters

    Parameters

    • messageClass: T

      The messages to listen for.

    • listener: MessageListener<GetSerialized<T[number]>, ContextType>

      The callback for when one of the messages is decoded.

    Returns (() => void)

      • (): void
      • Listen to any of several messages being sent through the decoder once.

        Returns

        A function to remove the listener.

        Returns void

  • Parse a buffer or reader in place, without emitting the resultant message.

    Returns

    The parsed message.

    Parameters

    • reader: HazelReader | Buffer

      The buffer or reader to parse.

    • Optional direction: MessageDirection

      The direction that the packet was sent.

    Returns null | Serializable

  • Register a message or several messages to the packet decoder.

    Parameters

    • Rest ...messageClasses: Deserializable[]

      The packet or packets to register.

    Returns void

  • Reset the packet decoder, removing all custom packets and removing listeners.

    Returns void

  • Asynchronously wait for a message to be decoded.

    Returns

    A promise containing the message, direciton and context metadata for the message.

    Type Parameters

    Parameters

    • messageClass: T

      The message to listen for.

    Returns Promise<{
        context: ContextType;
        direction: MessageDirection;
        message: GetSerialized<T>;
    }>

  • Asynchronously wait for a specific message to be decoded.

    Returns

    A function to remove the listener.

    Type Parameters

    Parameters

    Returns Promise<{
        context: ContextType;
        direction: MessageDirection;
        message: GetSerialized<T>;
    }>

  • Write a buffer or reader to the decoder.

    Parameters

    • reader: HazelReader | Buffer

      The buffer or reader to decode.

    • direction: undefined | MessageDirection

      The direction that the packet was sent.

    • context: ContextType

      Additional metadata for the context.

    Returns Promise<null | Serializable>

Properties

listeners: Map<`${string}:${number}`, MessageListener<Serializable, ContextType>[]>
types: Map<`${string}:${number}`, Deserializable>

Constructors

Generated using TypeDoc