Restruct class.
A JavaScript binary data library.
restruct.js performs conversion to and from binary data types. It utilizes an intuitive declarative API to define formats for binary structure parsers and emitters. It works in both the browser and on Node.
restruct.js is freely distributable under the terms of the MIT license.
This class has chainable methods and is used to define a structure.
Can be used to convert between JSON and buffer of bytes.
It should be noted that this library has had some modifications done to it by InfiniteSky contributors.
But the initial library is by another person.
- Deprecated:
-
- We really should rewrite this some time into code that compiles at runtime into native functions. Or just use google protobuf or something?
- License:
-
- MIT
- Source:
- See:
-
- https://rfw.name/restruct.js/
- ../restruct/README.md
Methods
-
boolean(n) → {Restruct}
-
Boolean (1 byte)
Parameters:
Name Type Description nInteger The amount of bytes to pad null.
- Source:
Returns:
this, chainable
- Type
- Restruct
-
float32l(k, n, buf) → {Restruct}
-
32-bit signed little-endian float.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
generateDocumentation() → {String}
-
An attempt to output documentation about a Restruct structure definition.
- Deprecated:
-
- We may not ever use this it was just Liam toying around with the concept. Ideally a plugin could be made for jsdoc which would add more information about all structures we make (in namespace or markdown format maybe...).
- Source:
Returns:
Output.
- Type
- String
-
int8bs(k, n, buf) → {Restruct}
-
8-bit signed big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int8bu(k, n, buf) → {Restruct}
-
8-bit unsigned big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int8ls(k, n, buf) → {Restruct}
-
8-bit signed little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int8lu(k, n, buf) → {Restruct}
-
8-bit unsigned little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int16bs(k, n, buf) → {Restruct}
-
16-bit signed big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int16bu(k, n, buf) → {Restruct}
-
16-bit unsigned big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int16ls(k, n, buf) → {Restruct}
-
16-bit signed little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int16lu(k, n, buf) → {Restruct}
-
16-bit unsigned little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int24bs(k, n, buf) → {Restruct}
-
24-bit signed big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int24bu(k, n, buf) → {Restruct}
-
24-bit unsigned big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int24ls(k, n, buf) → {Restruct}
-
24-bit signed little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int24lu(k, n, buf) → {Restruct}
-
24-bit unsigned little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int32bs(k, n, buf) → {Restruct}
-
32-bit signed big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int32bu(k, n, buf) → {Restruct}
-
32-bit unsigned big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int32ls(k, n, buf) → {Restruct}
-
32-bit signed little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int32lu(k, n, buf) → {Restruct}
-
32-bit unsigned little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int40bs(k, n, buf) → {Restruct}
-
40-bit signed big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int40bu(k, n, buf) → {Restruct}
-
40-bit unsigned big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int40ls(k, n, buf) → {Restruct}
-
40-bit signed little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int40lu(k, n, buf) → {Restruct}
-
40-bit unsigned little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int48bs(k, n, buf) → {Restruct}
-
48-bit signed big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int48bu(k, n, buf) → {Restruct}
-
48-bit unsigned big-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int48ls(k, n, buf) → {Restruct}
-
48-bit signed little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
int48lu(k, n, buf) → {Restruct}
-
48-bit unsigned little-endian integer.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
nibble(k, n) → {Restruct}
-
Nibble
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of nibbles.
- Source:
Returns:
this, chainable
- Type
- Restruct
-
objectify() → {object}
-
Create js Object with undef keys.
- Source:
Returns:
- Type
- object
-
pack(struct) → {binary}
-
Packs a structure type.
This will return buffer/binary.Parameters:
Name Type Description structobject The object to pack.
- Source:
Returns:
- Type
- binary
-
pad(n) → {Restruct}
-
Pad NUL bytes.
Parameters:
Name Type Description nInteger The amount of bytes to pad null.
- Source:
Returns:
this, chainable
- Type
- Restruct
-
string(k, n, buf) → {Restruct}
-
UTF-8 string.
Parameters:
Name Type Description kString The name of this element of the structure.
nInteger Number of elements if this is an array.
bufbuffer - Source:
Returns:
this, chainable
- Type
- Restruct
-
struct(k, s, n) → {Restruct}
-
Nested structure.
Parameters:
Name Type Description kString The name of this element of the structure.
sRestruct Another structure.
nInteger Number of elements if this is an array.
- Source:
Returns:
this, chainable
- Type
- Restruct
-
unpack(array) → {object}
-
Unpacks a structure type.
This will return a JS object.Parameters:
Name Type Description arraybinary The data to unpack.
- Source:
Returns:
- Type
- object