Options
All
  • Public
  • Public/Protected
  • All
Menu

typed-struct

Index

Type aliases

BitMask: readonly [offset: number, length: number]

Continuous bit mask.

  • offset: offset of the first bit in the mask, starting with the most significant bit
  • length: bit-length of fields
// |------> bit order
// 01234567 offset
// 00011110 mask
const mask: BitMask = [3, 4]
BitMaskN<M>: readonly [offset: BitOffset<M>, length: BitLength<M>]

Type parameters

  • M: number

CRCCalc: (buf: Buffer, previous?: number) => number

Type declaration

    • (buf: Buffer, previous?: number): number
    • Checksum function type

      Parameters

      • buf: Buffer
      • Optional previous: number

      Returns number

CRCOpts: { calc: CRCCalc; initial?: number; start?: number }

CRC field options

Type declaration

  • calc: CRCCalc

    Checksum function

  • Optional initial?: number

    Initial value. Default 0

  • Optional start?: number

    Zero-based index at which to start calculation. Default 0

Enumerate<N>: ArrayItem<EnumerateInternal<[], N>>

Type parameters

  • N: number

ExtractType<C, clear>: C extends new () => infer T ? clear extends true ? Omit<T, "__struct" | "toJSON"> : T : never

Type parameters

  • C

  • clear: boolean = true

Getter<R>: (type: string, buffer: Buffer) => R | undefined

Type parameters

  • R

Type declaration

    • (type: string, buffer: Buffer): R | undefined
    • Getter for custom types. Should return the property value, or undefined if the type is unknown.

      Parameters

      • type: string
      • buffer: Buffer

      Returns R | undefined

Range<FROM, TO>: Exclude<Enumerate<TO>, Enumerate<FROM>>

Type parameters

  • FROM: number

  • TO: number

Setter<R>: (type: string, buffer: Buffer, value: R) => boolean

Type parameters

  • R

Type declaration

    • (type: string, buffer: Buffer, value: R): boolean
    • Setter for custom types. Should return false if the type is unknown.

      Parameters

      • type: string
      • buffer: Buffer
      • value: R

      Returns boolean

StringArrayOpts: Id<Omit<StringOpts<string>, "literal" | "length"> & { length: number; lines: number }>

String array options

  • lines - the number of lines in the string array
StringOpts<R>: { encoding?: string; length: number; literal?: undefined } | { encoding?: string; length?: undefined; literal: R }

String options.

Type parameters

  • R: string

WithCRC<T, HasCRC>: ConditionalExtend<T, CRC<T>, HasCRC>

Type parameters

  • T: Constructable

  • HasCRC: boolean

Functions

  • getMask(offset: number, length: number, size: BitMaskSize): number
  • Create continuous bit mask.

    Parameters

    • offset: number

      offset of the first bit in the mask, starting with the most significant bit

    • length: number

      bit-length of fields

    • size: BitMaskSize

      8 | 16 | 32

    Returns number

  • typed<T>(): T | undefined
  • Use this function to specify the type of the numeric field

    enum ErrorType {
    Success,
    Timeout,
    InvalidCommand,
    ServerError,
    }
    const OperationResult = new Struct().UInt8('error', typed<ErrorType>()).compile();
    const res = new OperationResult();
    res.error = ErrorType.Success;

    Type parameters

    • T: string | number | bigint

    Returns T | undefined

Generated using TypeDoc