dataview-stream - v1.4.0
    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

    Accessors

    • get left(): number

      How many bytes are left to be read?

      Returns number

    • 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.

    Methods

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

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • Optionalopts: NotTemp<string>

        Read options.

      Returns this

      This, for chaining.

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

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: HasTemp<string>

        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.

      Parameters

      • desc: {
            convert?(value: number | boolean, name: string): void;
            from: keyof T;
            to: keyof T;
        } & StartFinish

        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.

      Parameters

      • desc: {
            convert?(value: number | boolean, name: string): void;
            fromTemp: keyof U;
            to: keyof T;
        } & StartFinish

        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.

      Parameters

      • desc: {
            convert?(value: number | boolean, name: string): void;
            from: keyof T;
            toTemp: keyof U;
        } & StartFinish

        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.

      Parameters

      • desc: {
            convert?(value: number | boolean, name: string): void;
            fromTemp: keyof U;
            toTemp: keyof U;
        } & StartFinish

        Description of bits to capture.

      Returns this

    • Store some number of bytes.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • Optionalopts: NotTemp<Uint8Array<ArrayBufferLike>>

        Read options.

      Returns this

      This, for chaining.

    • Store some number of bytes.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: HasTemp<Uint8Array<ArrayBufferLike>>

        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 16 bit float.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a 16 bit float.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a 32 bit float.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a 32 bit float.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a 64 bit float.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a 64 bit float.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 16 bit integer.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 16 bit integer.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 32 bit integer.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 32 bit integer.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 64 bit integer as a bigint.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<bigint>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 64 bit integer as a bigint.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<bigint>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 8 bit integer.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store a signed 8 bit integer.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Convenience function to perhaps execute a read.

      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.

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

      Parameters

      • name: keyof T

        Packet field name to read into, as an array.

      • num: number

        Number of times to call fn.

      • fn: (n: number) => FieldType

        Function that reads.

      • Optionalopts: NotTemp<FieldType[]>

        Read options.

      Returns this

      This, for chaining.

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

      Parameters

      • name: keyof U

        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[]>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 16 bit integer.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 16 bit integer.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 32 bit integer.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 32 bit integer.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 64 bit integer as a bigint.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<bigint>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 64 bit integer as a bigint.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<bigint>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 8 bit integer.

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<number>

        Read options.

      Returns this

      This, for chaining.

    • Store an unsigned 8 bit integer.

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<number>

        Read options.

      Returns this

      This, for chaining.

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

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • Optionalopts: NotTemp<Uint8Array<ArrayBufferLike>>

        Read options.

      Returns this

      This, for chaining.

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

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • opts: HasTemp<Uint8Array<ArrayBufferLike>>

        Read options.

      Returns this

      This, for chaining.

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

      Parameters

      • name: keyof T

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • Optionalopts: NotTemp<string>

        Read options.

      Returns this

      This, for chaining.

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

      Parameters

      • name: keyof U

        Field to write to in packet or temp.

      • len: number

        Number of bytes to read.

      • opts: HasTemp<string>

        Read options.

      Returns this

      This, for chaining.

    • Repeat the given read until a condition fails.

      Type Parameters

      • V

      Parameters

      • name: keyof T

        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) => V

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

      • Optionalopts: NotTemp<V[]>

        Read options.

      Returns this

    • Repeat the given read until a condition fails.

      Type Parameters

      • V

      Parameters

      • name: keyof U

        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) => V

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

      • opts: HasTemp<V[]>

        Read options.

      Returns this