byte-data

Methods

(static) pack(value, theTypenon-null, clampopt) → (non-null) {Array.<number>}

Source:
Pack a number as a array of bytes.
Parameters:
Name Type Attributes Default Description
value number The number to pack.
theType Object The type definition.
clamp boolean <optional>
false True to clamp ints on overflow.
Throws:
  • If the type definition is not valid.
    Type
    Error
  • On overflow if clamp is set to false.
    Type
    RangeError
  • If 'value' is not a number.
    Type
    TypeError
  • If 'value' is not a int and type is int.
    Type
    TypeError
Returns:
The packed value.
Type
Array.<number>

(static) packArray(valuesnon-null, theTypenon-null, clampopt) → (non-null) {Array.<number>}

Source:
Pack a array of numbers as a array of bytes.
Parameters:
Name Type Attributes Default Description
values Array.<number> | TypedArray The values to pack.
theType Object The type definition.
clamp boolean <optional>
false True to clamp ints on overflow.
Throws:
  • If the type definition is not valid.
    Type
    Error
  • On overflow if clamp is set to false.
    Type
    RangeError
  • If 'values' is not a array of numbers.
    Type
    TypeError
  • If 'values' is not a array of ints and type is int.
    Type
    TypeError
Returns:
The packed values.
Type
Array.<number>

(static) packArrayTo(valuesnon-null, theTypenon-null, buffernon-null, indexopt, clampopt) → {number}

Source:
Pack a array of numbers to a byte buffer. All other packing functions are interfaces to this function.
Parameters:
Name Type Attributes Default Description
values Array.<number> | TypedArray The values to pack.
theType Object The type definition.
buffer Uint8Array | Array.<number> The buffer to write on.
index number <optional>
0 The buffer index to start writing.
clamp boolean <optional>
false True to clamp ints on overflow.
Throws:
  • If the type definition is not valid.
    Type
    Error
  • On overflow if clamp is set to false.
    Type
    RangeError
  • If 'values' is not a array of numbers.
    Type
    TypeError
  • If 'values' is not a array of ints and type is int.
    Type
    TypeError
Returns:
The next index to write.
Type
number

(static) packString(str) → (non-null) {Array.<number>}

Source:
Write a string of UTF-8 characters as a byte buffer.
Parameters:
Name Type Description
str string The string to pack.
Throws:
If 'str' is not a string.
Type
TypeError
Returns:
The UTF-8 string bytes.
Type
Array.<number>

(static) packStringTo(str, buffernon-null, indexopt) → {number}

Source:
Write a string of UTF-8 characters to a byte buffer.
Parameters:
Name Type Attributes Default Description
str string The string to pack.
buffer Uint8Array | Array.<number> The output buffer.
index number <optional>
0 The buffer index to start writing.
Throws:
If 'str' is not a string.
Type
TypeError
Returns:
The next index to write in the buffer.
Type
number

(static) packTo(value, theTypenon-null, buffernon-null, indexopt, clampopt) → {number}

Source:
Pack a number to a byte buffer.
Parameters:
Name Type Attributes Default Description
value number The value.
theType Object The type definition.
buffer Uint8Array | Array.<number> The byte buffer to write on.
index number <optional>
0 The buffer index to write.
clamp boolean <optional>
false True to clamp ints on overflow.
Throws:
  • If the type definition is not valid.
    Type
    Error
  • On overflow if clamp is set to false.
    Type
    RangeError
  • If 'value' is not a number.
    Type
    TypeError
  • If 'value' is not a int and type is int.
    Type
    TypeError
Returns:
The next index to write.
Type
number

(static) unpack(buffernon-null, theTypenon-null, indexopt, safeopt) → {number}

Source:
Unpack a number from a byte buffer.
Parameters:
Name Type Attributes Default Description
buffer Uint8Array | Array.<number> The byte buffer.
theType Object The type definition.
index number <optional>
0 The buffer index to read.
safe boolean <optional>
false If set to false, extra bytes in the end of the input array are ignored and input buffers with insufficient bytes will write nothing to the output array. If safe is set to true the function will throw a 'Bad buffer length' error on the aforementioned cases.
Throws:
  • If the type definition is not valid.
    Type
    Error
  • On bad input buffer length if on safe mode.
    Type
    Error
Returns:
Type
number

(static) unpackArray(buffernon-null, theTypenon-null, startopt, endopt, safeopt) → (non-null) {Array.<number>}

Source:
Unpack a array of numbers from a byte buffer.
Parameters:
Name Type Attributes Default Description
buffer Uint8Array | Array.<number> The byte buffer.
theType Object The type definition.
start number <optional>
0 The buffer index to start reading.
end number <optional>
buffer.length The buffer index to stop reading.
safe boolean <optional>
false If set to false, extra bytes in the end of the input array are ignored and input buffers with insufficient bytes will write nothing to the output array. If safe is set to true the function will throw a 'Bad buffer length' error on the aforementioned cases.
Throws:
  • If the type definition is not valid.
    Type
    Error
  • On bad input buffer length if on safe mode.
    Type
    Error
Returns:
Type
Array.<number>

(static) unpackArrayTo(buffernon-null, theTypenon-null, outputnon-null, startopt, endopt, safeopt)

Source:
Unpack a array of numbers from a byte buffer to a array or a typed array. All other unpacking functions are interfaces to this function.
Parameters:
Name Type Attributes Default Description
buffer Uint8Array | Array.<number> The byte buffer.
theType Object The type definition.
output TypedArray | Array.<number> The output array or typed array.
start number <optional>
0 The buffer index to start reading.
end number <optional>
buffer.length The buffer index to stop reading.
safe boolean <optional>
false If set to false, extra bytes in the end of the input array are ignored and input buffers with insufficient bytes will write nothing to the output array. If safe is set to true the function will throw a 'Bad buffer length' error on the aforementioned cases.
Throws:
  • If the type definition is not valid.
    Type
    Error
  • On bad input buffer length if on safe mode.
    Type
    Error

(static) unpackString(buffernon-null, indexopt, endopt) → {string}

Source:
Read a string of UTF-8 characters from a byte buffer.
Parameters:
Name Type Attributes Default Description
buffer Uint8Array | Array.<number> A byte buffer.
index number <optional>
0 The buffer index to start reading.
end number <optional>
buffer.length The index to stop reading, non inclusive.
Returns:
Type
string