Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface BinaryDataType

Binary data type.

Accessed via: diffusion.datatypes.binary();

The implementation provides support for binary deltas.

Binary values can be used to store and transmit arbitrary information. The responsibility for formatting and interpreting the information belongs solely to the application. Before using Binary for a topic, consider other data types such as JSON or single value topic types; these may provide a simpler interface for your application.

since

5.7

Hierarchy

Index

Properties

Binary

Binary: object

The Binary data type value class

Type declaration

Methods

canReadAs

  • canReadAs(valueType: object): boolean
  • Test whether this data type is compatible with valueType. Compatibility with a valueType means than any valid binary representation of a value can be read as an instance of valueType.

    Every data type should be compatible with the following:

    • Value Type – the class corresponding to the data type's value type.

    For a data type with a value type of X, readAs(X, buffer) is equivalent to readValue(buffer).

    since

    6.0

    Parameters

    • valueType: object

      the type to check

    Returns boolean

    true if a binary representation created by this data type can read as an instance * of valueType

deltaType

  • Obtain a DeltaType by name or delta type.

    Example:

    // Get by name
    var deltas = datatype.deltaType("binary");

    Example:

    // Get by type
    var deltas = datatype.deltaType(delta);

    Parameters

    • Optional name: undefined | string

      the name, as returned by DeltaType.name

    Returns DeltaType<Binary, Buffer | Binary, Binary>

    the delta type

from

  • from(buffer: Buffer): Binary
  • Returns a new Binary instance from a buffer.

    function

    diffusion.datatypes.BinaryDataType#from

    Parameters

    • buffer: Buffer

      The binary data

    Returns Binary

    a Binary data-type instance

name

  • name(): string
  • The external type identifier.

    Returns string

    the name of this datatype

readAs

  • readAs(valueType: object, buffer: Buffer, offset?: undefined | number, length?: undefined | number): any | null
  • readAs(valueType: object, buffer: Binary): any | null
  • Create a value of a compatible class from binary.

    throws

    an error if valueType is incompatible with this data type, or buffer does not * represent a valid value.

    since

    6.0

    Parameters

    • valueType: object

      the type of the result

    • buffer: Buffer

      the binary data

    • Optional offset: undefined | number

      the offset to start reading from the provided buffer (default = 0)

    • Optional length: undefined | number

      the length of the data to read (default = input.length)

    Returns any | null

    the value in the form of the specified type

  • Parameters

    • valueType: object
    • buffer: Binary

    Returns any | null

readValue

  • readValue(input: Buffer, offset?: undefined | number, length?: undefined | number): Binary | null
  • readValue(input: Binary): Binary | null
  • Parse a value from binary.

    throws

    an error if the data is invalid for this type

    Parameters

    • input: Buffer

      the binary data

    • Optional offset: undefined | number

      the offset to start reading from the provided buffer (default = 0)

    • Optional length: undefined | number

      the length of the data to read (default = input.length)

    Returns Binary | null

    an instance of this data type value

  • Parameters

    Returns Binary | null

writeValue

  • writeValue(value: Buffer | Binary): Buffer
  • Serialise a value to binary

    throws

    an error if the value can not be serialised

    Parameters

    • value: Buffer | Binary

      the value to serialise

    Returns Buffer

    the serialised value as a buffer