Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ArrayType<E, READ_E>

A type storing a variable-length array of values of the same type

Example:

class Car {
  constructor(brand, model, year) {
    this.brand = brand
    this.model = model
    this.year = year
  }
}
let carType = new sb.StructType({ //Type<Car>
  brand: new sb.StringType,
  model: new sb.StringType,
  year: new sb.ShortType
})
let type = new sb.ArrayType(carType) //Type<Car[]>

Type parameters

  • E

    The type of each element in the array

  • READ_E: E = E

    The type of each element in the read array

Hierarchy

  • AbsoluteType<E[], READ_E[]>
    • ArrayType

Index

Constructors

constructor

  • new ArrayType<E, READ_E>(type: Type<E, READ_E>): ArrayType<E, READ_E>
  • Type parameters

    • E

    • READ_E = E

    Parameters

    • type: Type<E, READ_E>

      A Type that can serialize each element in the array

    Returns ArrayType<E, READ_E>

Properties

Readonly type

type: Type<E, READ_E>

Accessors

Static _value

  • get _value(): number

Methods

addToBuffer

consumeValue

  • consumeValue(buffer: ArrayBuffer, offset: number, baseValue?: READ_E[]): ReadResult<READ_E[]>
  • Parameters

    • buffer: ArrayBuffer
    • offset: number
    • Optional baseValue: READ_E[]

    Returns ReadResult<READ_E[]>

equals

  • equals(otherType: unknown): boolean
  • Parameters

    • otherType: unknown

    Returns boolean

getHash

  • getHash(): string

getSignature

  • getSignature(): string

Private isBuffer

Private isSameType

  • isSameType(otherType: unknown): otherType is ArrayType<E, READ_E>
  • Determines whether the input is a Type with the same class

    Parameters

    • otherType: unknown

      A value, usually a Type instance

    Returns otherType is ArrayType<E, READ_E>

    whether this and otherType are instances of the same Type class

readValue

  • readValue(valueBuffer: ArrayBuffer | Uint8Array, offset?: number): READ_E[]
  • Parameters

    • valueBuffer: ArrayBuffer | Uint8Array
    • offset: number = 0

    Returns READ_E[]

toBuffer

  • toBuffer(): ArrayBuffer

valueBuffer

  • valueBuffer(value: E[]): ArrayBuffer
  • Parameters

    • value: E[]

    Returns ArrayBuffer

writeValue

  • Appends value bytes to an AppendableBuffer according to the type

    Example:

    let car1 = new Car('VW', 'Bug', 1960)
    let car2 = new Car('Honda', 'Fit', 2015)
    let car3 = new Car('Tesla', 'Model 3', 2017)
    type.writeValue(buffer, [car1, car2, car3])
    
    throws

    If the value doesn't match the type, e.g. new sb.StringType().writeValue(buffer, 23)

    Parameters

    • buffer: AppendableBuffer

      The buffer to which to append

    • value: E[]

      The value to write

    Returns void

Generated using TypeDoc