dataview-stream - v2.0.2
    Preparing search index...

    Class Packet<T, U>

    Capture fields from a packet in a way that allows accessing the previously- read fields while reading subsequent fields.

    Type Parameters

    • T extends object

      Structure of the packet.

    • U = object

      Structure for other temporary fields that you want to reference, but don't want in the final packet.

    Index

    Constructors

    • Type Parameters

      • T extends object

        Structure of the packet.

      • U = object

        Structure for other temporary fields that you want to reference, but don't want in the final packet.

      Parameters

      Returns Packet<T, U>

    Accessors

    • get allowTruncation(): boolean

      Get the truncation mode of the underlying reader.

      Returns boolean

      True if truncation allowed.

    • set allowTruncation(val: boolean): void

      Sets the truncation mode of the underlying reader. May not be set to false.

      Parameters

      • val: boolean

      Returns void

    • get left(): number

      How many bytes are left to be read?

      Returns number

    • get littleEndian(): boolean

      Is the packet in littleEndian mode by default?

      Returns boolean

    • set littleEndian(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get offset(): number

      The current offset into the reader.

      Returns number

    • get packet(): T

      Packet. Only the fields that you have already read may be accessed.

      Returns T

      Possibly-incomplete packet, even though the type is complete.

    • get temp(): U

      Temporary storage. Only the fields that you have already read may be accessed.

      Returns U

      Possibly-incomplete temp data, even though the type is complete.

    • get truncated(): boolean

      Is this underlying reader truncated?

      Returns boolean

      True if truncated.

    • set truncated(val: boolean): void

      Some higher-level processor has detected truncation. Must not be set to false.

      Parameters

      • val: boolean

      Returns void

    Methods

    • Store some number of bytes, interpreted as an ASCII string.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: NotTemp<string, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store some number of bytes, interpreted as an ASCII string.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: MatchingType<T, V, string>

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      Returns this

      This, for chaining.

    • Store some number of bytes, interpreted as an ASCII string.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: HasTemp<string, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Copy some of the bits from one existing field to another. Does not work for fields larger than 53 bits. For fields larger than 32 bits, use bigints, as returned from u64(). Should only be applied to unsigned from fields. Bits are numbered with 0 on the right, MSB on the left. Start and finish can be in either order.

      Type Parameters

      • V extends string | number | symbol
      • W extends string | number | symbol

      Parameters

      • desc: { from: T[V] extends number | bigint | undefined ? V : never; to: W } & BitsConfig<
            T[V],
            T[W],
        >

        Description of bits to capture.

      Returns this

    • Copy some of the bits from one existing field to another. Does not work for fields larger than 53 bits. For fields larger than 32 bits, use bigints, as returned from u64(). Should only be applied to unsigned from fields. Bits are numbered with 0 on the right, MSB on the left. Start and finish can be in either order.

      Type Parameters

      • V extends string | number | symbol
      • W extends string | number | symbol

      Parameters

      • desc: { fromTemp: U[V] extends number | bigint ? V : never; to: W } & BitsConfig<
            U[V],
            T[W],
        >

        Description of bits to capture.

      Returns this

    • Copy some of the bits from one existing field to another. Does not work for fields larger than 53 bits. For fields larger than 32 bits, use bigints, as returned from u64(). Should only be applied to unsigned from fields. Bits are numbered with 0 on the right, MSB on the left. Start and finish can be in either order.

      Type Parameters

      • V extends string | number | symbol
      • W extends string | number | symbol

      Parameters

      • desc: { from: T[V] extends number | bigint ? V : never; toTemp: W } & BitsConfig<
            T[V],
            U[W],
        >

        Description of bits to capture.

      Returns this

    • Copy some of the bits from one existing field to another. Does not work for fields larger than 53 bits. For fields larger than 32 bits, use bigints, as returned from u64(). Should only be applied to unsigned from fields. Bits are numbered with 0 on the right, MSB on the left. Start and finish can be in either order.

      Type Parameters

      • V extends string | number | symbol
      • W extends string | number | symbol

      Parameters

      • desc: { fromTemp: U[V] extends number | bigint ? V : never; toTemp: W } & BitsConfig<
            U[V],
            U[W],
        >

        Description of bits to capture.

      Returns this

    • Store some number of bytes.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: NotTemp<Uint8Array<ArrayBufferLike>, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store some number of bytes.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: MatchingType<T, V, Uint8Array<ArrayBufferLike>>

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      Returns this

      This, for chaining.

    • Store some number of bytes.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: HasTemp<Uint8Array<ArrayBufferLike>, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Assert that all of the data been read. Throws an exception if extra data.

      Returns this

      This, for chaining.

    • Store a constant to the packet.

      Type Parameters

      • V extends string | number | symbol
      • F extends FieldType

      Parameters

      • name: V

        Field to write to in packet or temp.

      • val: F

        Any constant value.

      • opts: NotTemp<F, T[V]>

        Read options.

      Returns this

    • Store a constant to the packet.

      Type Parameters

      • V extends string | number | symbol
      • F extends FieldType

      Parameters

      • name: MatchingType<T, V, F>

        Field to write to in packet or temp.

      • val: F

        Any constant value.

      Returns this

    • Store a constant to the packet.

      Type Parameters

      • V extends string | number | symbol
      • F extends FieldType

      Parameters

      • name: V

        Field to write to in packet or temp.

      • val: F

        Any constant value.

      • opts: HasTemp<F, U[V]>

        Read options.

      Returns this

    • Turn on truncation for this stream.

      Returns this

      This, for chaining.

    • Store a 16 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a 16 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store a 16 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a 32 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a 32 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store a 32 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a 64 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a 64 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store a 64 bit float.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 16 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 16 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store a signed 16 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 32 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 32 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store a signed 32 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 64 bit integer as a bigint.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<bigint, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 64 bit integer as a bigint.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store a signed 64 bit integer as a bigint.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<bigint, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 8 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 8 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store a signed 8 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Convenience function to perhaps execute a read. Does not call the function if input was truncated.

      Parameters

      • doIt: boolean

        Should fn be executed?

      • fn: () => void

        Run if doIt is true.

      Returns this

      This, for chaining.

    • Reset all packet data, temp data, and return reader to the start. Mostly useful for testing.

      Returns this

      This, for chaining.

    • Skip over some bytes in the stream.

      Parameters

      • length: number

        Number of bytes to skip.

      Returns this

      This, for chaining.

    • Convenience function to repeat reading a given number of times.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Packet field name to read into, as an array.

      • num: number

        Number of times to call fn.

      • fn: (n: number) => FieldType

        Function that reads.

      • opts: NotTemp<FieldType[], T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Convenience function to repeat reading a given number of times.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: MatchingType<T, V, FieldType[]>

        Packet field name to read into, as an array.

      • num: number

        Number of times to call fn.

      • fn: (n: number) => FieldType

        Function that reads.

      Returns this

      This, for chaining.

    • Convenience function to repeat reading a given number of times.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Packet field name to read into, as an array.

      • num: number

        Number of times to call fn.

      • fn: (n: number) => FieldType

        Function that reads.

      • opts: HasTemp<FieldType[], U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 16 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 16 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store an unsigned 16 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 32 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 32 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store an unsigned 32 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 64 bit integer as a bigint.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<bigint, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 64 bit integer as a bigint.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store an unsigned 64 bit integer as a bigint.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<bigint, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 8 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<number, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 8 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      Returns this

      This, for chaining.

    • Store an unsigned 8 bit integer.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<number, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store all of the data that has yet to be read.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: NotTemp<Uint8Array<ArrayBufferLike>, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store all of the data that has yet to be read.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: MatchingType<T, V, Uint8Array<ArrayBufferLike>>

        Field to write to in packet or temp.

      Returns this

      This, for chaining.

    • Store all of the data that has yet to be read.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • opts: HasTemp<Uint8Array<ArrayBufferLike>, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store some number of bytes, interpreted as a UTF8 string.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: NotTemp<string, T[V]>

        Read options.

      Returns this

      This, for chaining.

    • Store some number of bytes, interpreted as a UTF8 string.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: MatchingType<T, V, string>

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      Returns this

      This, for chaining.

    • Store some number of bytes, interpreted as a UTF8 string.

      Type Parameters

      • V extends string | number | symbol

      Parameters

      • name: V

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: HasTemp<string, U[V]>

        Read options.

      Returns this

      This, for chaining.

    • Repeat the given read until a condition fails.

      Type Parameters

      • V extends string | number | symbol
      • W extends FieldType

      Parameters

      • name: V

        Packet field name to read into, as an array.

      • keepGoing: (iteration: number, r: DataViewReader) => boolean

        While this function returns true, keep calling read.

      • read: (iteration: number, r: DataViewReader) => W

        The value returned from this function is added to the array.

      • Optionalopts: NotTemp<W[], T[V]>

        Read options.

      Returns this

    • Repeat the given read until a condition fails.

      Type Parameters

      • V extends string | number | symbol
      • W extends FieldType

      Parameters

      • name: MatchingType<T, V, W[]>

        Packet field name to read into, as an array.

      • keepGoing: (iteration: number, r: DataViewReader) => boolean

        While this function returns true, keep calling read.

      • read: (iteration: number, r: DataViewReader) => W

        The value returned from this function is added to the array.

      • opts: NotTemp<W[], T[V]>

        Read options.

      Returns this

    • Repeat the given read until a condition fails.

      Type Parameters

      • V extends string | number | symbol
      • W extends FieldType

      Parameters

      • name: V

        Packet field name to read into, as an array.

      • keepGoing: (iteration: number, r: DataViewReader) => boolean

        While this function returns true, keep calling read.

      • read: (iteration: number, r: DataViewReader) => W

        The value returned from this function is added to the array.

      • opts: HasTemp<W[], U[V]>

        Read options.

      Returns this