Datafield is the abstract base class of all concrete Datafield classes thus cannot be instantiated directly but can be useful for testing that a variable is a valid Datafield.

var df      = new decoder.DatafieldInt("df.name")
var isTrue  = df instanceof decoder.Datafield

Datafield.toString() : String

Returns the contents of a datafield as a string.

Datafield.getName() : String

Returns the name of a datafield.

Datafield.isSet() : Boolean

Returns true if a datafield has been set.

var df      = new decoder.DatafieldInt("df.name")
var isFalse = df.isSet()

Datafield.unset() : Boolean

Some protocols require multiple messages to be decoded from a single buffer and in some cases decode data into different fields based on message type.  On each iteration of decoding a message any set datafields should be "unset" so that they are not collected again the next time.

var df      = new decoder.DatafieldInt("df.name")
 
function on_data(dec) {
  if (df.isSet()) {
    df.unset()
  }
}

Datafield.isRequired() : Boolean

In many cases certain datafields are not required by the collector, this method can be used to test if the Datafield is required. In cases where certain datafields are not required then time can be saved by avoiding the parsing of them.

var df      = new decoder.DatafieldInt("df.name")
 
function on_data(dec) {
  if (df.isRequired()) {
    // parse data for this field from dec.buffer
  }
}

Datafield.setRequired(isRequired : Boolean) : Void

This method can be useful for debugging by ensuring that a datafield is set as required. It generally should not be used, otherwise.

var df = new decoder.DatafieldInt("df.name")
df.setRequired(true)
 
function on_data(dec) {
  if (df.isRequired()) {  // Always returns true, due to df.setRequired(true)
    // parse data for this field from dec.buffer
  }
}

DatafieldBool

DatafieldBool is the simplest of all Datafields. It represents only two states "true" and "false" (or "on" and "off").

DatafieldBool(datafieldName : String)

The DatafieldBool constructor creates a Datafield with the given name.

var df = new decoder.DatafieldBool("df.name")

DatafieldBool.set(value : Object) : Void

Object is the base of all JavaScript variables. This method sets the value of the Datafield based on whether the JavaScript argument value represents "false" or "true".

var df = new decoder.DatafieldBool("df.name")
df.set(false) // false
df.set(null// false
df.set(0)     // false
 
df.set(true// true

DatafieldBool.get() : Boolean

Retrieve the value of this Datafield as a JavaScript boolean value.

var df = new decoder.DatafieldBool("df.name")
df.set(true)
var isTrue  = df.get()
df.set(false)
var isFalse  = df.get()

DatafieldBool.on() : Void

Sets the Datafield value to true.

var df = new decoder.DatafieldBool("df.name")
df.on()
var isTrue = df.get()

DatafieldBool.off() : Void

Sets the Datafield value to true.

var df = new decoder.DatafieldBool("df.name")
df.on()
df.off()
var isFalse = df.get()

DatafieldFloat

DatafieldFloat is a simple Datafield to work with as the number representation it uses (IEEE double) is identical to that of the number representation used by JavaScript.

DatafieldFloat(datafieldName : String)

The DatafieldFloat constructor creates a DatafieldFloat with the given name.

var df = new decoder.DatafieldFloat("df.name")

DatafieldFloat.set(value : Number) : Void

Assign the Datafield contents from the JavaScript number value.

var df = new decoder.DatafieldFloat("df.name")
df.set(123.456)

DatafieldFloat.get() : Number

Retrieve the value of this Datafield as a JavaScript Number.

var df = new decoder.DatafieldFloat("df.name")
df.set(123.456)
var isTrue = df.get() === 123.456

DatafieldFloat.incrementBy(value : Number) : Void

Increment the value of the DatafieldFloat by value. To decrement the DatafieldFloat a negative number can be passed to this method.

var df = new decoder.DatafieldFloat("df.name")
df.incrementBy(100.12)
df.incrementBy(-50.12) // df now represents a value of 50

DatafieldString

A Datafield that can store any string of data.

DatafieldString(datafieldName : String)

The DatafieldString constructor creates a Datafield with name datafieldName.

var df = new decoder.DatafieldString("df.name")

DatafieldString.set(value : String) : Void

Assign the Datafield value from the JavaScript string value.

var df = new decoder.DatafieldString("df.name")
df.set("value")

DatafieldString.get() : String

Retrieve the value of this Datafield as a JavaScript string.

var df = new decoder.DatafieldString("df.name")
df.set("value")
var jsString = df.get()
var isTrue   = jsString === "value"

DatafieldString.append(value : String) : String

Append the JavaScript string value to the end of the Datafield contents.

var df = new decoder.DatafieldString("df.name")
df.set("val")
df.append("ue")
var isTrue = df.get() == "value"

DatafieldIPAddr

A Datafield used for representing an IP address.

DatafieldIPAddr.set(ipaddress : String) : Void

Set IP address from string representation.

var df = new decoder.DatafieldIPAddr("df.name")
df.set("192.168.1.68") // sets ip address
df.set("catfriend")    // throws exception

DatafieldIPAddr.get() : String

Get IP address in string format.

var df = new decoder.DatafieldIPAddr("df.name")
df.set("192.168.1.68") // sets ip address
if (df.get() !== "192.168.1.68")
  throw new Error("This is impossible")

DatafieldIPPort

A Datafield used for representing an IP port.

DatafieldIPPort.set(value : Number) : Void

Set Datafield port value from a JavaScript number.

var df = new decoder.DatafieldIPPort("df.name")
df.set(80)

DatafieldIPPort.get() : Number

Get Datafield port value as JavaScript number.

var df = new decoder.DatafieldIPPort("df.name")
df.set(80)
if (df.get() !== 80)
  throw new Error("This is impossible")

DatafieldInt

The integral Datafields, DatafieldInt and DatafieldUInt, can represent 64-bit numbers, signed and unsigned respectively. Both Datafields have the same methods so only one will be listed, but the distinction between key methods of both is discussed. Usually a DatafieldInt will not be used directly beyond assigning from the richer Int64 class but some convenience methods are supplied that are specifically useful for dealing with numbers in the 32-bit address space.

DatafieldInt(datafieldName : String)

The DatafieldInt constructor creates a Datafield with the given name.

var df = new decoder.DatafieldInt("df.name")

DatafieldInt.fromInt32(value : Number) : Void

Equivalent to Int64.fromtInt32 but operates on Datafield value.

DatafieldInt.fromUInt32(i : Number) : Void

Equivalent to Int64.fromUInt32 but operates on Datafield value.

DatafieldInt.fromInt64(value : Number) : Void

Equivalent to Int64.fromtInt64 but operates on Datafield value.

DatafieldInt.fromUInt32(i : Number) : Void

Equivalent to Int64.fromUInt64 but operates on Datafield value.

DatafieldInt.set(i : Number or Int64 or UInt64) : Void

Equivalent to Int64.set but operates on Datafield value.

DatafieldInt.increment(i : Number or Int64 or UInt64) : Void

Equivalent to Int64.increment but operates on Datafield value.

DatafieldInt.multiply(i : Number or Int64 or UInt64) : Void

Equivalent to Int64.multiply but operates on Datafield value.

DatafieldInt.divide(i : Number or Int64 or UInt64) : Void

Equivalent to Int64.divide but operates on Datafield value.

DatafieldInt.get() : Number

Retrieve the value of this Datafield as an Int64 (or UInt64 for DatafieldUInt).

var df = new decoder.DatafieldInt("df.name")
df.setRequired(true)   // Required, otherwise the datafield is not actually set
df.set(400)
var int64val = df.get()
if (! (int64val instanceof decoder.Int64) || int64val.toInt32() !== 400)
  throw new Error("This is not possible")

DatafieldInt.toUInt32() : Number

Equivalent to get().toUInt32().

DatafieldInt.toInt32() : Number

Equivalent to get().toInt32().

DatafieldTimestamp

A datafield used to hold a timestamp in nanoseconds since the unix epoch.

DatafieldTimestamp(datafieldName : String)

The DatafieldTimestamp constructor creates a Datafield with the given name.

var df = new decoder.DatafieldTimestamp("df.name")

DatafieldTimestamp.get() : UInt64

Returns the timestamp in nanoseconds since the unix epoch.

DatafieldTimestamp.fromUInt64(value : UInt64) : Void

Sets the timestamp in nanoseconds since the unix epoch.

DatafieldTimestamp.fromInt64(value : Int64) : Void

Sets the timestamp in nanoseconds since the unix epoch.

DatafieldBinary

A datafield used to hold binary data.

DatafieldBinary(datafieldName : String)

The DatafieldBinary constructor creates a Datafield with the given name.

var df = new decoder.DatafieldBinary("df.name")

DatafieldBinary.size() : Number

Returns the number of bytes of data in the datafield.

DatafieldBinary.consume(buffer : BufferChain, size : Number) : Void

Consumes up to <size> bytes from the buffer and stores them in the datafield. The BufferChain pointer is advanced up to <size> bytes.