Module: MessageUtils

DXL messaging related utility methods

Source:

Methods

(static) decode(value, returnType, encodingopt) → {Buffer|Object|String}

Convert the supplied value to the supplied returnType. If the returnType is 'bin', the value is returned as a binary buffer. If the returnType is 'obj', the value is returned as an object, deserialized from a JSON string. If the returnType is 'txt' (or anything else), the value is returned as a string.

Parameters:
Name Type Attributes Default Description
value Buffer | String

The value.

returnType String

One of 'bin', 'obj', or 'txt'.

encoding String <optional>
utf8

The encoding of the value. (Unused when returnType is 'bin'.)

Source:
Throws:

If 'bin' is requested but the value is not a binary buffer.

Type
TypeError
Returns:

The value converted from the buffer.

Type
Buffer | Object | String

(static) decodePayload(message, payloadType, encodingopt) → {Buffer|Object|String}

Convert the payload in the supplied DXL message to the supplied payloadType. If the payloadType is 'bin', the payload is returned as a binary buffer. If the payloadType is 'obj', the payload is returned as an object, deserialized from a JSON string. If the payloadType is 'txt' (or anything else), the payload is returned as a string.

Parameters:
Name Type Attributes Default Description
message external:Message

The DXL message.

payloadType String

One of 'bin', 'obj', or 'txt'.

encoding String <optional>
utf8

The encoding of the payload. (Unused when payloadType is 'bin'.)

Source:
Throws:

If 'bin' is requested but the payload in the message is not a binary buffer.

Type
TypeError
Returns:

The value converted from the buffer.

Type
Buffer | Object | String

(static) objectToReturnType(obj, returnType, encodingopt) → {Buffer|Object|String}

Convert an object to a returnType. If the returnType is 'obj', the supplied obj is returned. If the returnType is 'bin', the value is returned as a binary buffer, serialized as a JSON string. If the returnType is 'txt' (or anything else), the value is returned as a JSON-serialized string.

Parameters:
Name Type Attributes Default Description
obj Object

The object.

returnType String

One of 'bin', 'obj', or 'txt'.

encoding String <optional>
utf8

The encoding of the payload. (Unused unless the payloadType is 'bin'.)

Source:
Returns:

The value converted from the object.

Type
Buffer | Object | String