An open API service indexing awesome lists of open source software.

https://github.com/patrickroberts/c-struct-js

UMD module for DataView extension inspired by C structs
https://github.com/patrickroberts/c-struct-js

javascript library node-module object-oriented struct umd

Last synced: 3 months ago
JSON representation

UMD module for DataView extension inspired by C structs

Awesome Lists containing this project

README

        

# c-struct-js

UMD module for DataView extension inspired by C structs

[![NPM Version][npm-image]][npm-url] [![Node Version][node-image]][npm-url] [![devDependencies][devdep-image]][npm-url] [![License][license-image]][license-url] [![Standard][style-image]][style-url] [![Github File Size][filesize-image]][filesize-url]

## Usage

#### Install via [`npm`][npm-url]

```bash
$ npm i c-struct-js
```

#### CommonJS

```js
const Struct = require('c-struct-js')
```

#### ES6 import (using babel)

```js
import Struct from 'c-struct-js'
```

#### AMD requireJS

```js
define(['c-struct-js'], (Struct) => { ... })
```

#### Or include via [`unpkg`][unpkg-url]

```html

```

#### UMD global

```html

const { Struct } = window

```

## Classes



StructDataView


## Objects



types : object


Namespace of predefined Struct classes.



## Struct ⇐ [DataView](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
**Kind**: global class
**Extends**: [DataView](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)

* [Struct](#Struct) ⇐ [DataView](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
* [new Struct(buffer, [byteOffset])](#new_Struct_new)
* _static_
* [.extend(...descriptors)](#Struct.extend) ⇒ constructor
* [.types](#Struct.types) : [types](#types)
* [.byteLength](#Struct.byteLength) : number
* [.from(value, [byteOffset])](#Struct.from) ⇒ [Struct](#Struct)
* [.isStruct(value)](#Struct.isStruct) ⇒ boolean
* [.union(...Classes)](#Struct.union) ⇒ constructor
* _instance_
* [.getString(byteOffset, byteLength, [encoding])](#Struct+getString) ⇒ string
* [.setString(byteOffset, byteLength, value, [encoding])](#Struct+setString)
* [.get()](#Struct+get)
* [.set(typedArray, [byteOffset])](#Struct+set)
* [.next([constructor], [bytePadding])](#Struct+next)
* [.prev([constructor], [bytePadding])](#Struct+prev)

### new Struct(buffer, [byteOffset])

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) | | An instance of ArrayBuffer to view. |
| [byteOffset] | number | 0 | Byte offset at which to view ArrayBuffer. |

### Struct.extend(...descriptors) ⇒ constructor
Creates a class that extends Struct with members defined by arguments.

**Kind**: static method of [Struct](#Struct)
**Throws**:

- [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) Unexpected type.
- [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) byteLength is required for String type.

| Param | Type | Description |
| --- | --- | --- |
| ...descriptors | Object | Instance member definitions for extended class. |
| descriptors[].name | string | The member name. |
| descriptors[].type | string \| [Struct](#Struct) | The member type. Accepts strings 'Int8', 'Uint8', 'Int16', 'Uint16', 'Float32', 'Int32', 'Uint32', 'Float64', 'String', or any constructor that extends Struct. |
| [descriptors[].option] | \* | An optional argument to append to the accessor methods of the member. |
| [descriptors[].byteLength] | number | Determined using type by default. Required when type is 'String'. |
| [descriptors[].byteOffset] | number | Determined using order of descriptors by default. |

**Example**
```js
const Struct = require('c-struct-js')

// Implementing RIFF-style chunk headers
const Word = Struct.extend(
{ name: 'word', type: 'String', byteLength: 4 }
)

const Chunk = Struct.extend(
{ name: 'id', type: Word },
{ name: 'size', type: Struct.types.Uint32LE }
)

class RIFF extends Struct.extend(
{ name: 'chunk', type: Chunk },
// ...
) {
constructor () {
super(new ArrayBuffer(RIFF.byteLength))

this.chunk.id.word = 'RIFF'
this.chunk.size = this.byteLength - this.chunk.byteLength
// ...
}
}

let riff = new RIFF()
let ab = riff.chunk.id
let buf = Buffer.from(ab.buffer, ab.byteOffset, ab.byteLength)

console.log(buf.toString())
```

### Struct.types : [types](#types)
Namespace of predefined types.

**Kind**: static property of [Struct](#Struct)

### Struct.byteLength : number
Byte length of instances.

**Kind**: static property of [Struct](#Struct)
**Default**: 0
**Read only**: true

### Struct.from(value, [byteOffset]) ⇒ [Struct](#Struct)
Creates an instance of Struct to view given value at byteOffset.

**Kind**: static method of [Struct](#Struct)
**Throws**:

- [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) value must be a valid ArrayBuffer or view.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| value | [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) \| [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | | A valid ArrayBuffer or TypedArray. |
| [byteOffset] | number | 0 | Byte offset at which to view value. |

**Example**
```js
// checking encoded size of WAV file
const { promisify } = require('util')
const fs = require('fs')
const read = promisify(fs.read)
const open = promisify(fs.open)
const close = promisify(fs.close)

// using Chunk from previous example
// ...

// bytes 36-44 contain SubChunk2 of WAV header
open('test.wav', 'r')
.then(fd => {
return read(fd, Buffer.allocUnsafe(Chunk.byteLength), 0, Chunk.byteLength, 36)
.then((bytesRead, buffer) => close(fd).then(() => Chunk.from(buffer)))
})
.then(chunk => console.log('file size:', 44 + chunk.size))
```

### Struct.isStruct(value) ⇒ boolean
Validates constructors that implement Struct.

**Kind**: static method of [Struct](#Struct)

| Param | Type | Description |
| --- | --- | --- |
| value | \* | A value to test. |

**Example**
```js
console.log(Struct.isStruct(Struct)) // true
console.log(Struct.isStruct(RIFF)) // true
console.log(Struct.isStruct(DataView)) // false - doesn't implement Struct
console.log(Struct.isStruct(riff)) // false - is instance, not class
```

### Struct.union(...Classes) ⇒ constructor
Creates a union class that extends Struct with members of all Classes.

**Kind**: static method of [Struct](#Struct)
**Throws**:

- [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) Union contains conflicting key.

| Param | Type | Description |
| --- | --- | --- |
| ...Classes | constructor | Classes that extend Struct. |

**Example**
```js
// Getting surrogate pairs of utf16le encoding
const UTF16LE = Struct.extend(
{ name: 'code', type: 'String', byteLength: 2, option: 'utf16le' }
)

const UTF16Pair = Struct.extend(
{ name: 'lo', type: 'Uint8' },
{ name: 'hi', type: 'Uint8' }
)

const UTF16 = Struct.union(Utf16le, Utf16Pair)

let utf16 = new Utf16(new ArrayBuffer(UTF16.byteLength))

utf16.code = '€'

// € ac 20
console.log(utf16.code, utf16.lo.toString(16), utf16.hi.toString(16))
```

### struct.getString(byteOffset, byteLength, [encoding]) ⇒ string
Gets string with byteLength and encoding from viewed ArrayBuffer at byteOffset.
Depending on data and encoding, returned string may have different length than byteLength.

**Kind**: instance method of [Struct](#Struct)
**Throws**:

- [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) encoding must be a valid string encoding.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| byteOffset | number | | Byte offset within ArrayBuffer of string to read. |
| byteLength | number | | Byte length within ArrayBuffer of string to read. |
| [encoding] | string | "utf8" | Encoding within ArrayBuffer of string to read. |

**Example**
```js
// using utf16 from previous example
// ...

console.log(utf16.code === utf16.getString(0, 2, 'utf16le')) // true
```

### struct.setString(byteOffset, byteLength, value, [encoding])
Sets string with byteLength and encoding to viewed ArrayBuffer at byteOffset.
Depending on byteLength and encoding, set string may be truncated or padded.

**Kind**: instance method of [Struct](#Struct)
**Throws**:

- [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) encoding must be a valid string encoding.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| byteOffset | number | | Byte offset within ArrayBuffer of string to write. |
| byteLength | number | | Byte length within ArrayBuffer of string to write. |
| value | string | | String value to write to ArrayBuffer. |
| [encoding] | string | "utf8" | Encoding within ArrayBuffer of string to write. |

**Example**
```js
// using utf16 from previous example
// ...

utf16.setString(0, 2, '$', 'utf16le')

// $ 24 0
console.log(utf16.code, utf16.lo.toString(16), utf16.hi.toString(16))
```

### struct.get()
Default member getter when accessed as a member of a parent Struct.

**Kind**: instance method of [Struct](#Struct)
**Example**
```js
// Better implementation for RIFF-style chunk headers
class Word extends Struct.extend(
{ name: 'word', type: 'String', byteLength: 4 }
) {
get () { return this.word }
set (string) { this.word = string }
}

const Chunk = Struct.extend(
{ name: 'id', type: Word },
{ name: 'size', type: Struct.types.Uint32LE }
)

// Other structs...

class RIFF extends Struct.extend(
{ name: 'chunk', type: Chunk },
// Other fields...
) {
constructor (arrayBuffer = new ArrayBuffer(RIFF.byteLength), byteOffset = 0) {
super(arrayBuffer, byteOffset)

this.chunk.id = 'RIFF'
this.chunk.size = this.byteLength - this.chunk.byteLength
// ...
}
}

let riff = new RIFF()
let id = riff.chunk.id

// 'RIFF' instead of instance of Word
console.log(id)
```

### struct.set(typedArray, [byteOffset])
Sets memory in ArrayBuffer starting at byteOffset with data from typedArray.

**Kind**: instance method of [Struct](#Struct)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| typedArray | [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | | View of data to copy. |
| [byteOffset] | number | 0 | Byte offset within ArrayBuffer at which to write. |

**Example**
```js
// reading header of WAV file into instance of RIFF

// using RIFF from previous example
// ...
let riff = new RIFF()

open('test.wav', 'r')
.then(fd => {
return read(fd, Buffer.allocUnsafe(RIFF.byteLength), 0, RIFF.byteLength, 0)
.then((bytesRead, buffer) => close(fd).then(() => buffer))
})
.then(buffer => {
riff.set(buffer)
// populated with header bytes from test.wav
// ...
})
```

### struct.next([constructor], [bytePadding])
Initializes the next chunk of the buffer as another instance of Struct.

**Kind**: instance method of [Struct](#Struct)
**Throws**:

- [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) constructor must implement Struct.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [constructor] | constructor | this.constructor | The Struct class with which to initialize. |
| [bytePadding] | number | 0 | Amount of bytes after the end of this to begin ArrayBuffer view. |

**Example**
```js
// iterating through a large dataset
const readFile = promisify(fs.readFile)

readFile('test.wav')
.then(buffer => {
for (let struct = new Struct.types.Uint8(buffer.buffer, 44); struct !== null; struct = struct.next()) {
// iterates through each byte of sound data
console.log(struct.uint8) // 0-255
}
})
```

### struct.prev([constructor], [bytePadding])
Initializes the previous chunk of the buffer as another instance of Struct.

**Kind**: instance method of [Struct](#Struct)
**Throws**:

- [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) constructor must implement Struct.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [constructor] | constructor | this.constructor | The Struct class with which to initialize. |
| [bytePadding] | number | 0 | Amount of bytes before the end of this to end ArrayBuffer view. |

**Example**
```js
// accessing header of first data

readFile('test.wav')
.then(buffer => {
let data = new Struct.types.Uint8(buffer.buffer, 44)
// to properly initialize RIFF header at byteOffset of 0
let riff = data.prev(RIFF, data.byteOffset - Chunk.byteLength)

// 'RIFF'
console.log(riff.chunk.id)
})
```

## types : object
Namespace of predefined Struct classes.

**Kind**: global namespace

* [types](#types) : object
* [.Byte](#types.Byte) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Byte.byteLength) : number
* _instance_
* [.char](#types.Byte+char) : String
* [.int8](#types.Byte+int8) : number
* [.uint8](#types.Byte+uint8) : number
* [.Char](#types.Char) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Char.byteLength) : number
* _instance_
* [.char](#types.Char+char) : String
* [.get()](#types.Char+get) ⇒ String
* [.set(value)](#types.Char+set)
* [.Float32BE](#types.Float32BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Float32BE.byteLength) : number
* _instance_
* [.float32be](#types.Float32BE+float32be) : number
* [.get()](#types.Float32BE+get) ⇒ number
* [.set(value)](#types.Float32BE+set)
* [.Float32LE](#types.Float32LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Float32LE.byteLength) : number
* _instance_
* [.float32le](#types.Float32LE+float32le) : number
* [.get()](#types.Float32LE+get) ⇒ number
* [.set(value)](#types.Float32LE+set)
* [.Float64BE](#types.Float64BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Float64BE.byteLength) : number
* _instance_
* [.float64be](#types.Float64BE+float64be) : number
* [.get()](#types.Float64BE+get) ⇒ number
* [.set(value)](#types.Float64BE+set)
* [.Float64LE](#types.Float64LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Float64LE.byteLength) : number
* _instance_
* [.float64le](#types.Float64LE+float64le) : number
* [.get()](#types.Float64LE+get) ⇒ number
* [.set(value)](#types.Float64LE+set)
* [.Int16BE](#types.Int16BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int16BE.byteLength) : number
* _instance_
* [.int16be](#types.Int16BE+int16be) : number
* [.get()](#types.Int16BE+get) ⇒ number
* [.set(value)](#types.Int16BE+set)
* [.Int16LE](#types.Int16LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int16LE.byteLength) : number
* _instance_
* [.int16le](#types.Int16LE+int16le) : number
* [.get()](#types.Int16LE+get) ⇒ number
* [.set(value)](#types.Int16LE+set)
* [.Int32BE](#types.Int32BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int32BE.byteLength) : number
* _instance_
* [.int32be](#types.Int32BE+int32be) : number
* [.get()](#types.Int32BE+get) ⇒ number
* [.set(value)](#types.Int32BE+set)
* [.Int32LE](#types.Int32LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int32LE.byteLength) : number
* _instance_
* [.int32le](#types.Int32LE+int32le) : number
* [.get()](#types.Int32LE+get) ⇒ number
* [.set(value)](#types.Int32LE+set)
* [.Int8](#types.Int8) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int8.byteLength) : number
* _instance_
* [.int8](#types.Int8+int8) : number
* [.get()](#types.Int8+get) ⇒ number
* [.set(value)](#types.Int8+set)
* [.Long](#types.Long) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Long.byteLength) : number
* _instance_
* [.float64be](#types.Long+float64be) : number
* [.float64le](#types.Long+float64le) : number
* [.Short](#types.Short) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Short.byteLength) : number
* _instance_
* [.int16be](#types.Short+int16be) : number
* [.int16le](#types.Short+int16le) : number
* [.uint16be](#types.Short+uint16be) : number
* [.uint16le](#types.Short+uint16le) : number
* [.Uint16BE](#types.Uint16BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint16BE.byteLength) : number
* _instance_
* [.uint16be](#types.Uint16BE+uint16be) : number
* [.get()](#types.Uint16BE+get) ⇒ number
* [.set(value)](#types.Uint16BE+set)
* [.Uint16LE](#types.Uint16LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint16LE.byteLength) : number
* _instance_
* [.uint16le](#types.Uint16LE+uint16le) : number
* [.get()](#types.Uint16LE+get) ⇒ number
* [.set(value)](#types.Uint16LE+set)
* [.Uint32BE](#types.Uint32BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint32BE.byteLength) : number
* _instance_
* [.uint32be](#types.Uint32BE+uint32be) : number
* [.get()](#types.Uint32BE+get) ⇒ number
* [.set(value)](#types.Uint32BE+set)
* [.Uint32LE](#types.Uint32LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint32LE.byteLength) : number
* _instance_
* [.uint32le](#types.Uint32LE+uint32le) : number
* [.get()](#types.Uint32LE+get) ⇒ number
* [.set(value)](#types.Uint32LE+set)
* [.Uint8](#types.Uint8) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint8.byteLength) : number
* _instance_
* [.uint8](#types.Uint8+uint8) : number
* [.get()](#types.Uint8+get) ⇒ number
* [.set(value)](#types.Uint8+set)
* [.Word](#types.Word) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Word.byteLength) : number
* _instance_
* [.float32be](#types.Word+float32be) : number
* [.float32le](#types.Word+float32le) : number
* [.int32be](#types.Word+int32be) : number
* [.int32le](#types.Word+int32le) : number
* [.uint32be](#types.Word+uint32be) : number
* [.uint32le](#types.Word+uint32le) : number

### types.Byte ⇐ [Struct](#Struct)
A union of all 1-byte predefined types.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Byte](#types.Byte) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Byte.byteLength) : number
* _instance_
* [.char](#types.Byte+char) : String
* [.int8](#types.Byte+int8) : number
* [.uint8](#types.Byte+uint8) : number

#### Byte.byteLength : number
Byte length of instances.

**Kind**: static property of [Byte](#types.Byte)
**Default**: 1
**Read only**: true

#### byte.char : String
A single byte binary string character. Accepts any characters from the [latin-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) block.

**Kind**: instance property of [Byte](#types.Byte)

#### byte.int8 : number
An 8-bit signed integer.

**Kind**: instance property of [Byte](#types.Byte)

#### byte.uint8 : number
An 8-bit unsigned integer.

**Kind**: instance property of [Byte](#types.Byte)

### types.Char ⇐ [Struct](#Struct)
A predefined type for storing a binary-encoded string character.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Char](#types.Char) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Char.byteLength) : number
* _instance_
* [.char](#types.Char+char) : String
* [.get()](#types.Char+get) ⇒ String
* [.set(value)](#types.Char+set)

#### Char.byteLength : number
Byte length of instances.

**Kind**: static property of [Char](#types.Char)
**Default**: 1
**Read only**: true

#### char.char : String
A single byte binary string character. Accepts any characters from the [latin-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) block.

**Kind**: instance property of [Char](#types.Char)

#### char.get() ⇒ String
**Kind**: instance method of [Char](#types.Char)
**Returns**: String - char

#### char.set(value)
**Kind**: instance method of [Char](#types.Char)

| Param | Type |
| --- | --- |
| value | String |

### types.Float32BE ⇐ [Struct](#Struct)
A predefined type for storing a 32-bit floating point number in big-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Float32BE](#types.Float32BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Float32BE.byteLength) : number
* _instance_
* [.float32be](#types.Float32BE+float32be) : number
* [.get()](#types.Float32BE+get) ⇒ number
* [.set(value)](#types.Float32BE+set)

#### Float32BE.byteLength : number
Byte length of instances.

**Kind**: static property of [Float32BE](#types.Float32BE)
**Default**: 4
**Read only**: true

#### float32BE.float32be : number
A 32-bit floating point number accessed in big-endian byte order.

**Kind**: instance property of [Float32BE](#types.Float32BE)
**See**: [IEEE 754 Single-precision floating-point format](https://en.wikipedia.org/wiki/Single-precision_floating-point_format#IEEE_754_single-precision_binary_floating-point_format:_binary32)

#### float32BE.get() ⇒ number
**Kind**: instance method of [Float32BE](#types.Float32BE)
**Returns**: number - float32be

#### float32BE.set(value)
**Kind**: instance method of [Float32BE](#types.Float32BE)

| Param | Type |
| --- | --- |
| value | number |

### types.Float32LE ⇐ [Struct](#Struct)
A predefined type for storing a 32-bit floating point number in little-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Float32LE](#types.Float32LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Float32LE.byteLength) : number
* _instance_
* [.float32le](#types.Float32LE+float32le) : number
* [.get()](#types.Float32LE+get) ⇒ number
* [.set(value)](#types.Float32LE+set)

#### Float32LE.byteLength : number
Byte length of instances.

**Kind**: static property of [Float32LE](#types.Float32LE)
**Default**: 4
**Read only**: true

#### float32LE.float32le : number
A 32-bit floating point number accessed in big-endian byte order.

**Kind**: instance property of [Float32LE](#types.Float32LE)
**See**: [IEEE 754 Single-precision floating-point format](https://en.wikipedia.org/wiki/Single-precision_floating-point_format#IEEE_754_single-precision_binary_floating-point_format:_binary32)

#### float32LE.get() ⇒ number
**Kind**: instance method of [Float32LE](#types.Float32LE)
**Returns**: number - float32le

#### float32LE.set(value)
**Kind**: instance method of [Float32LE](#types.Float32LE)

| Param | Type |
| --- | --- |
| value | number |

### types.Float64BE ⇐ [Struct](#Struct)
A predefined type for storing a 64-bit floating point number in big-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Float64BE](#types.Float64BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Float64BE.byteLength) : number
* _instance_
* [.float64be](#types.Float64BE+float64be) : number
* [.get()](#types.Float64BE+get) ⇒ number
* [.set(value)](#types.Float64BE+set)

#### Float64BE.byteLength : number
Byte length of instances.

**Kind**: static property of [Float64BE](#types.Float64BE)
**Default**: 8
**Read only**: true

#### float64BE.float64be : number
A 64-bit floating point number accessed in big-endian byte order.

**Kind**: instance property of [Float64BE](#types.Float64BE)
**See**: [IEEE 754 Double-precision floating-point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format:_binary64)

#### float64BE.get() ⇒ number
**Kind**: instance method of [Float64BE](#types.Float64BE)
**Returns**: number - float64be

#### float64BE.set(value)
**Kind**: instance method of [Float64BE](#types.Float64BE)

| Param | Type |
| --- | --- |
| value | number |

### types.Float64LE ⇐ [Struct](#Struct)
A predefined type for storing a 64-bit floating point number in little-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Float64LE](#types.Float64LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Float64LE.byteLength) : number
* _instance_
* [.float64le](#types.Float64LE+float64le) : number
* [.get()](#types.Float64LE+get) ⇒ number
* [.set(value)](#types.Float64LE+set)

#### Float64LE.byteLength : number
Byte length of instances.

**Kind**: static property of [Float64LE](#types.Float64LE)
**Default**: 8
**Read only**: true

#### float64LE.float64le : number
A 64-bit floating point number accessed in little-endian byte order.

**Kind**: instance property of [Float64LE](#types.Float64LE)
**See**: [IEEE 754 Double-precision floating-point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format:_binary64)

#### float64LE.get() ⇒ number
**Kind**: instance method of [Float64LE](#types.Float64LE)
**Returns**: number - float64le

#### float64LE.set(value)
**Kind**: instance method of [Float64LE](#types.Float64LE)

| Param | Type |
| --- | --- |
| value | number |

### types.Int16BE ⇐ [Struct](#Struct)
A predefined type for storing a 16-bit signed integer in big-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Int16BE](#types.Int16BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int16BE.byteLength) : number
* _instance_
* [.int16be](#types.Int16BE+int16be) : number
* [.get()](#types.Int16BE+get) ⇒ number
* [.set(value)](#types.Int16BE+set)

#### Int16BE.byteLength : number
Byte length of instances.

**Kind**: static property of [Int16BE](#types.Int16BE)
**Default**: 2
**Read only**: true

#### int16BE.int16be : number
A 16-bit signed integer accessed in big-endian byte order.

**Kind**: instance property of [Int16BE](#types.Int16BE)

#### int16BE.get() ⇒ number
**Kind**: instance method of [Int16BE](#types.Int16BE)
**Returns**: number - int16be

#### int16BE.set(value)
**Kind**: instance method of [Int16BE](#types.Int16BE)

| Param | Type |
| --- | --- |
| value | number |

### types.Int16LE ⇐ [Struct](#Struct)
A predefined type for storing a 16-bit signed integer in little-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Int16LE](#types.Int16LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int16LE.byteLength) : number
* _instance_
* [.int16le](#types.Int16LE+int16le) : number
* [.get()](#types.Int16LE+get) ⇒ number
* [.set(value)](#types.Int16LE+set)

#### Int16LE.byteLength : number
Byte length of instances.

**Kind**: static property of [Int16LE](#types.Int16LE)
**Default**: 2
**Read only**: true

#### int16LE.int16le : number
A 16-bit signed integer accessed in little-endian byte order.

**Kind**: instance property of [Int16LE](#types.Int16LE)

#### int16LE.get() ⇒ number
**Kind**: instance method of [Int16LE](#types.Int16LE)
**Returns**: number - int16le

#### int16LE.set(value)
**Kind**: instance method of [Int16LE](#types.Int16LE)

| Param | Type |
| --- | --- |
| value | number |

### types.Int32BE ⇐ [Struct](#Struct)
A predefined type for storing a 32-bit signed integer in big-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Int32BE](#types.Int32BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int32BE.byteLength) : number
* _instance_
* [.int32be](#types.Int32BE+int32be) : number
* [.get()](#types.Int32BE+get) ⇒ number
* [.set(value)](#types.Int32BE+set)

#### Int32BE.byteLength : number
Byte length of instances.

**Kind**: static property of [Int32BE](#types.Int32BE)
**Default**: 4
**Read only**: true

#### int32BE.int32be : number
A 32-bit signed integer accessed in big-endian byte order.

**Kind**: instance property of [Int32BE](#types.Int32BE)

#### int32BE.get() ⇒ number
**Kind**: instance method of [Int32BE](#types.Int32BE)
**Returns**: number - int32be

#### int32BE.set(value)
**Kind**: instance method of [Int32BE](#types.Int32BE)

| Param | Type |
| --- | --- |
| value | number |

### types.Int32LE ⇐ [Struct](#Struct)
A predefined type for storing a 32-bit signed integer in little-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Int32LE](#types.Int32LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int32LE.byteLength) : number
* _instance_
* [.int32le](#types.Int32LE+int32le) : number
* [.get()](#types.Int32LE+get) ⇒ number
* [.set(value)](#types.Int32LE+set)

#### Int32LE.byteLength : number
Byte length of instances.

**Kind**: static property of [Int32LE](#types.Int32LE)
**Default**: 4
**Read only**: true

#### int32LE.int32le : number
A 32-bit signed integer accessed in big-endian byte order.

**Kind**: instance property of [Int32LE](#types.Int32LE)

#### int32LE.get() ⇒ number
**Kind**: instance method of [Int32LE](#types.Int32LE)
**Returns**: number - int32le

#### int32LE.set(value)
**Kind**: instance method of [Int32LE](#types.Int32LE)

| Param | Type |
| --- | --- |
| value | number |

### types.Int8 ⇐ [Struct](#Struct)
A predefined type for storing an 8-bit signed integer.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Int8](#types.Int8) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Int8.byteLength) : number
* _instance_
* [.int8](#types.Int8+int8) : number
* [.get()](#types.Int8+get) ⇒ number
* [.set(value)](#types.Int8+set)

#### Int8.byteLength : number
Byte length of instances.

**Kind**: static property of [Int8](#types.Int8)
**Default**: 1
**Read only**: true

#### int8.int8 : number
An 8-bit signed integer.

**Kind**: instance property of [Int8](#types.Int8)

#### int8.get() ⇒ number
**Kind**: instance method of [Int8](#types.Int8)
**Returns**: number - int8

#### int8.set(value)
**Kind**: instance method of [Int8](#types.Int8)

| Param | Type |
| --- | --- |
| value | number |

### types.Long ⇐ [Struct](#Struct)
A union of all 8-byte predefined types.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Long](#types.Long) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Long.byteLength) : number
* _instance_
* [.float64be](#types.Long+float64be) : number
* [.float64le](#types.Long+float64le) : number

#### Long.byteLength : number
Byte length of instances.

**Kind**: static property of [Long](#types.Long)
**Default**: 8
**Read only**: true

#### long.float64be : number
A 64-bit floating point number accessed in big-endian byte order.

**Kind**: instance property of [Long](#types.Long)
**See**: [IEEE 754 Double-precision floating-point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format:_binary64)

#### long.float64le : number
A 64-bit floating point number accessed in little-endian byte order.

**Kind**: instance property of [Long](#types.Long)
**See**: [IEEE 754 Double-precision floating-point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format:_binary64)

### types.Short ⇐ [Struct](#Struct)
A union of all 2-byte predefined types.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Short](#types.Short) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Short.byteLength) : number
* _instance_
* [.int16be](#types.Short+int16be) : number
* [.int16le](#types.Short+int16le) : number
* [.uint16be](#types.Short+uint16be) : number
* [.uint16le](#types.Short+uint16le) : number

#### Short.byteLength : number
Byte length of instances.

**Kind**: static property of [Short](#types.Short)
**Default**: 2
**Read only**: true

#### short.int16be : number
A 16-bit signed integer accessed in big-endian byte order.

**Kind**: instance property of [Short](#types.Short)

#### short.int16le : number
A 16-bit signed integer accessed in little-endian byte order.

**Kind**: instance property of [Short](#types.Short)

#### short.uint16be : number
A 16-bit unsigned integer accessed in big-endian byte order.

**Kind**: instance property of [Short](#types.Short)

#### short.uint16le : number
A 16-bit unsigned integer accessed in little-endian byte order.

**Kind**: instance property of [Short](#types.Short)

### types.Uint16BE ⇐ [Struct](#Struct)
A predefined type for storing a 16-bit unsigned integer in big-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Uint16BE](#types.Uint16BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint16BE.byteLength) : number
* _instance_
* [.uint16be](#types.Uint16BE+uint16be) : number
* [.get()](#types.Uint16BE+get) ⇒ number
* [.set(value)](#types.Uint16BE+set)

#### Uint16BE.byteLength : number
Byte length of instances.

**Kind**: static property of [Uint16BE](#types.Uint16BE)
**Default**: 2
**Read only**: true

#### uint16BE.uint16be : number
A 16-bit unsigned integer accessed in big-endian byte order.

**Kind**: instance property of [Uint16BE](#types.Uint16BE)

#### uint16BE.get() ⇒ number
**Kind**: instance method of [Uint16BE](#types.Uint16BE)
**Returns**: number - uint16be

#### uint16BE.set(value)
**Kind**: instance method of [Uint16BE](#types.Uint16BE)

| Param | Type |
| --- | --- |
| value | number |

### types.Uint16LE ⇐ [Struct](#Struct)
A predefined type for storing a 16-bit unsigned integer in little-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Uint16LE](#types.Uint16LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint16LE.byteLength) : number
* _instance_
* [.uint16le](#types.Uint16LE+uint16le) : number
* [.get()](#types.Uint16LE+get) ⇒ number
* [.set(value)](#types.Uint16LE+set)

#### Uint16LE.byteLength : number
Byte length of instances.

**Kind**: static property of [Uint16LE](#types.Uint16LE)
**Default**: 2
**Read only**: true

#### uint16LE.uint16le : number
A 16-bit unsigned integer accessed in little-endian byte order.

**Kind**: instance property of [Uint16LE](#types.Uint16LE)

#### uint16LE.get() ⇒ number
**Kind**: instance method of [Uint16LE](#types.Uint16LE)
**Returns**: number - uint16le

#### uint16LE.set(value)
**Kind**: instance method of [Uint16LE](#types.Uint16LE)

| Param | Type |
| --- | --- |
| value | number |

### types.Uint32BE ⇐ [Struct](#Struct)
A predefined type for storing a 32-bit unsigned integer in big-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Uint32BE](#types.Uint32BE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint32BE.byteLength) : number
* _instance_
* [.uint32be](#types.Uint32BE+uint32be) : number
* [.get()](#types.Uint32BE+get) ⇒ number
* [.set(value)](#types.Uint32BE+set)

#### Uint32BE.byteLength : number
Byte length of instances.

**Kind**: static property of [Uint32BE](#types.Uint32BE)
**Default**: 4
**Read only**: true

#### uint32BE.uint32be : number
A 32-bit unsigned integer accessed in big-endian byte order.

**Kind**: instance property of [Uint32BE](#types.Uint32BE)

#### uint32BE.get() ⇒ number
**Kind**: instance method of [Uint32BE](#types.Uint32BE)
**Returns**: number - uint32be

#### uint32BE.set(value)
**Kind**: instance method of [Uint32BE](#types.Uint32BE)

| Param | Type |
| --- | --- |
| value | number |

### types.Uint32LE ⇐ [Struct](#Struct)
A predefined type for storing a 32-bit unsigned integer in little-endian byte order.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Uint32LE](#types.Uint32LE) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint32LE.byteLength) : number
* _instance_
* [.uint32le](#types.Uint32LE+uint32le) : number
* [.get()](#types.Uint32LE+get) ⇒ number
* [.set(value)](#types.Uint32LE+set)

#### Uint32LE.byteLength : number
Byte length of instances.

**Kind**: static property of [Uint32LE](#types.Uint32LE)
**Default**: 4
**Read only**: true

#### uint32LE.uint32le : number
A 32-bit unsigned integer accessed in little-endian byte order.

**Kind**: instance property of [Uint32LE](#types.Uint32LE)

#### uint32LE.get() ⇒ number
**Kind**: instance method of [Uint32LE](#types.Uint32LE)
**Returns**: number - uint32le

#### uint32LE.set(value)
**Kind**: instance method of [Uint32LE](#types.Uint32LE)

| Param | Type |
| --- | --- |
| value | number |

### types.Uint8 ⇐ [Struct](#Struct)
A predefined type for storing an 8-bit unsigned integer.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Uint8](#types.Uint8) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Uint8.byteLength) : number
* _instance_
* [.uint8](#types.Uint8+uint8) : number
* [.get()](#types.Uint8+get) ⇒ number
* [.set(value)](#types.Uint8+set)

#### Uint8.byteLength : number
Byte length of instances.

**Kind**: static property of [Uint8](#types.Uint8)
**Default**: 1
**Read only**: true

#### uint8.uint8 : number
An 8-bit unsigned integer.

**Kind**: instance property of [Uint8](#types.Uint8)

#### uint8.get() ⇒ number
**Kind**: instance method of [Uint8](#types.Uint8)
**Returns**: number - uint8

#### uint8.set(value)
**Kind**: instance method of [Uint8](#types.Uint8)

| Param | Type |
| --- | --- |
| value | number |

### types.Word ⇐ [Struct](#Struct)
A union of all 4-byte predefined types.

**Kind**: static mixin of [types](#types)
**Extends**: [Struct](#Struct)

* [.Word](#types.Word) ⇐ [Struct](#Struct)
* _static_
* [.byteLength](#types.Word.byteLength) : number
* _instance_
* [.float32be](#types.Word+float32be) : number
* [.float32le](#types.Word+float32le) : number
* [.int32be](#types.Word+int32be) : number
* [.int32le](#types.Word+int32le) : number
* [.uint32be](#types.Word+uint32be) : number
* [.uint32le](#types.Word+uint32le) : number

#### Word.byteLength : number
Byte length of instances.

**Kind**: static property of [Word](#types.Word)
**Default**: 4
**Read only**: true

#### word.float32be : number
A 32-bit floating point number accessed in big-endian byte order.

**Kind**: instance property of [Word](#types.Word)
**See**: [IEEE 754 Single-precision floating-point format](https://en.wikipedia.org/wiki/Single-precision_floating-point_format#IEEE_754_single-precision_binary_floating-point_format:_binary32)

#### word.float32le : number
A 32-bit floating point number accessed in big-endian byte order.

**Kind**: instance property of [Word](#types.Word)
**See**: [IEEE 754 Single-precision floating-point format](https://en.wikipedia.org/wiki/Single-precision_floating-point_format#IEEE_754_single-precision_binary_floating-point_format:_binary32)

#### word.int32be : number
A 32-bit signed integer accessed in big-endian byte order.

**Kind**: instance property of [Word](#types.Word)

#### word.int32le : number
A 32-bit signed integer accessed in big-endian byte order.

**Kind**: instance property of [Word](#types.Word)

#### word.uint32be : number
A 32-bit unsigned integer accessed in big-endian byte order.

**Kind**: instance property of [Word](#types.Word)

#### word.uint32le : number
A 32-bit unsigned integer accessed in little-endian byte order.

**Kind**: instance property of [Word](#types.Word)

## License

Available under the MIT License
(c) 2017 Patrick Roberts

[npm-url]: https://www.npmjs.com/package/c-struct-js
[npm-image]: https://img.shields.io/npm/v/c-struct-js.svg

[node-image]: https://img.shields.io/node/v/c-struct-js.svg

[devdep-image]: https://img.shields.io/david/dev/patrickroberts/c-struct-js.svg

[license-url]: https://github.com/patrickroberts/c-struct-js/blob/master/LICENSE
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg

[style-url]: https://standardjs.com/
[style-image]: https://img.shields.io/badge/style-standard-brightgreen.svg

[filesize-url]: https://github.com/patrickroberts/c-struct-js/blob/master/umd/struct.min.js
[filesize-image]: https://img.shields.io/github/size/patrickroberts/c-struct-js/umd/struct.min.js.svg

[unpkg-url]: https://unpkg.com/