Class: RecordContent

diffusion.metadata. RecordContent

new RecordContent()

Metadata that supports a user-defined tabular structure for values.

A record topic can have multiple Records, each of which may have multiple Fields. Records and Fields are named, allowing direct lookup when used with topic updates.

Each Field has a specified metadata type, which enforces the type of value that can be used for sending updates.

Classes

Field
Record

Methods

addRecord(name, occurs, fields)

Add a new Record. Records are added in order; this allows both name and index based lookup.
Parameters:
Name Type Argument Default Description
name String The name of this record
occurs diffusion.metadata.RecordContent.Occurs <optional>
{min:1, max:1} An optional specification of how many times this record can repeat
fields Object <optional>
{} Optional set of fields to add to this record
Returns:
The new Record.
Examples
// Add a single record
var metadata = new diffusion.metadata.RecordContent();
var record = metadata.addRecord('name');
// Add a record that can repeat up to 5 times
var metadata = new diffusion.metadata.RecordContent();
var record = metadata.addRecord('foo', metadata.occurs(0, 5));
// Add a record with specified fields
var metadata = new diffusion.metadata.RecordContent();
var record = metadata.addRecord('foo', metadata.occurs(1), {
    field1 : metadata.integer(),
    field2 : metadata.string()
});

builder() → {RecordContent.Builder}

Create a new RecordContent.Builder from this metadata.

The returned builder facilitates the construction of RecordContent for updates, with the content data constrained by the structure of this metadata.

Returns:
A new builder
Type
RecordContent.Builder
Example
var metadata = new diffusion.metadata.RecordContent();
var builder = metadata.builder();

decimal()

Alias for the diffusion.metadata.Decimal constructor.

getRecord(key) → {diffusion.metadata.RecordContent.Record}

Get a record that is attached to this metadata.

If a string is provided, this will lookup the record that was added with that same name, if it exists. If a number is given, this will be treated as the zero-indexed number of the record to return.

Parameters:
Name Type Description
key Number | String The key to lookup the record with
Returns:
The record, or null
Type
diffusion.metadata.RecordContent.Record
Examples
// Get the record named 'foo'
var record = metadata.getRecord('foo');
// Get the second record that was added
var record = metadata.getRecord(1);

getRecords() → {Array.<diffusion.metadata.RecordContent.Record>}

Get all records in order, as an array.
Returns:
The records
Type
Array.<diffusion.metadata.RecordContent.Record>

integer()

Alias for the diffusion.metadata.Integer constructor.

occurs(min, max) → {diffusion.metadata.RecordContent.Occurs}

Specify the minimum and maximum number of times a Record or Field may occur. This allows metadata to specify required, optional, or repeating records and fields.

If no maximum value is provided, it will be set as the same as the minimum value.

A value of -1 is interpreted as 'unlimited'.

Parameters:
Name Type Argument Description
min integer The minimum number of times that a field or record can occur.
max integer <optional>
The maximum number of times that a field or record can occur.
Returns:
The min and max occurences.
Type
diffusion.metadata.RecordContent.Occurs

parse(buffer) → {RecordContent}

Parse binary data into a RecordContent based on the structure of this metadata.
Parameters:
Name Type Description
buffer Buffer The data to parse
Throws:
An exception if the data cannot be parsed
Returns:
A record content instance
Type
RecordContent
Example
// Parse an update into content
var content = metadata.parse(update);

string()

Alias for the diffusion.metadata.String constructor.

Type Definitions

Occurs

Type:
  • Object
Properties:
Name Type Argument Default Description
min Number <optional>
1 The minimum number allowed
max Number <optional>
1 The maximum number allowed