Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FlexUnsignedIntType

A type storing any unsigned integer that can be represented precisely in a double (from 0 to 9007199254740991 (2 ** 53 - 1)). Rather than having a fixed-length value representation, more bytes are needed to represent larger values. This is inspired by the UTF-8 format: large values can be stored, but since most values are small, fewer bytes are used in the typical case. If values are uniformly distributed rather than concentrated among smaller values, you will likely get more efficient serializations from a fixed-width integer. For example, when writing outputs of a 32-bit hash function, you should use UnsignedIntType instead.

The number of bytes required for numbers are as follows:

Min Max Bytes
01271
128165112
1651221136633
21136642705491194
270549120346302874875
3463028748844326767985916
44326767985925673826302199037
56738263021990490071992547409918

Example:

let type = new sb.FlexUnsignedIntType

Hierarchy

  • UnsignedType<number | string, number>
    • FlexUnsignedIntType

Index

Constructors

constructor

Accessors

Static _value

  • get _value(): number

Methods

addToBuffer

consumeValue

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

    • buffer: ArrayBuffer
    • offset: number

    Returns ReadResult<number>

equals

  • equals(otherType: unknown): boolean
  • Parameters

    • otherType: unknown

    Returns boolean

getHash

  • getHash(): string

getSignature

  • getSignature(): string

Private isBuffer

Private isSameType

  • Determines whether the input is a Type with the same class

    Parameters

    • otherType: unknown

      A value, usually a Type instance

    Returns otherType is FlexUnsignedIntType

    whether this and otherType are instances of the same Type class

readValue

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

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

    Returns number

toBuffer

  • toBuffer(): ArrayBuffer

valueBuffer

  • valueBuffer(value: string | number): ArrayBuffer
  • Parameters

    • value: string | number

    Returns ArrayBuffer

writeValue

  • Appends value bytes to an AppendableBuffer according to the type

    Example:

    //Takes 4 bytes
    type.writeValue(buffer, 2113664) //or '2113664'
    
    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: string | number

      The value to write

    Returns void

Generated using TypeDoc