Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EnumType<E>

A type storing a value in a fixed set of possible values. There can be at most 255 possible values.

Example:

//Storing different species' characteristics
const HUMAN = {heightFt: 6, speedMph: 28}
const CHEETAH = {heightFt: 3, speedMph: 70}
let type = new sb.EnumType({
  type: new sb.StructType({
    heightFt: new sb.FloatType,
    speedMph: new sb.UnsignedByteType
  }),
  values: [HUMAN, CHEETAH]
})

Type parameters

  • E

    The type of each value in the enum

Hierarchy

  • AbstractType<E>
    • EnumType

Index

Constructors

constructor

  • throws

    If any value cannot be serialized by type

    Type parameters

    • E

    Parameters

    Returns EnumType<E>

Properties

Private cachedValueIndices

cachedValueIndices: undefined | Map<string, number>

Readonly type

type: Type<E, E>

The type used to serialize the values

Readonly values

values: E[]

The list of possible values

Accessors

Private valueIndices

  • get valueIndices(): Map<string, number>

Static _value

  • get _value(): number

Methods

addToBuffer

consumeValue

  • consumeValue(buffer: ArrayBuffer, offset: number): ReadResult<E>
  • Parameters

    • buffer: ArrayBuffer
    • offset: number

    Returns ReadResult<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 EnumType<E>
  • Determines whether the input is a Type with the same class

    Parameters

    • otherType: unknown

      A value, usually a Type instance

    Returns otherType is EnumType<E>

    whether this and otherType are instances of the same Type class

readValue

  • readValue(valueBuffer: ArrayBuffer | Uint8Array, offset?: number): E
  • Parameters

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

    Returns 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:

    type.writeValue(buffer, CHEETAH)
    
    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