Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PointerType<E, READ_E>

A type storing a value of another type through a pointer. If you expect to have the same large value repeated many times, using a pointer will decrease the size of the value ArrayBuffer. If the value has already been written, 1 to 2 bytes are likely needed to write the pointer (more if values are far apart in output buffer). In comparison to without a pointer type, only 1 extra byte will be used if the value has not yet been written to the output buffer.

Example:

//If the same people will be used many times
let personType = new sb.PointerType(
  new sb.StructType({
    dob: new sb.DayType,
    id: new sb.UnsignedShortType,
    name: new sb.StringType
  })
)
let tribeType = new sb.StructType({
  leader: personType,
  members: new sb.SetType(personType),
  money: new sb.MapType(personType, new sb.FloatType)
})

Type parameters

  • E

    The type of values that can be written

  • READ_E: E = E

    The type of values that will be read

Hierarchy

  • AbstractType<E, READ_E>
    • PointerType

Index

Constructors

constructor

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

    • E

    • READ_E = E

    Parameters

    • type: Type<E, READ_E>

      The Type used to write the values being pointed to

    Returns PointerType<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): ReadResult<READ_E>
  • Parameters

    • buffer: ArrayBuffer
    • offset: number

    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 PointerType<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 PointerType<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 louis = {
      dob: new Date(1437592284193),
      id: 9,
      name: 'Louis'
    },
    garfield = {
      dob: new Date(1437592284194),
      id: 17,
      name: 'Garfield'
    }
    let value = {
      leader: {
        dob: new Date(1437592284192),
        id: 10,
        name: 'Joe'
      },
      members: new Set([louis, garfield]),
      money: new Map().set(louis, 23.05).set(garfield, -10.07)
    }
    tribeType.writeValue(buffer, value)
    
    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