Encoder

Encoder

Transform JavaScript values into CBOR bytes. The `Writable` side of the stream is in object mode.

Constructor

new Encoder(optionsopt)

Creates an instance of Encoder.
Parameters:
Name Type Attributes Default Description
options Object <optional>
{} options for the encoder
Properties
Name Type Attributes Default Description
genTypes Array.<any> <optional>
[] array of pairs of `type`, `function(Encoder)` for semantic types to be encoded. Not needed for Array, Date, Buffer, Map, RegExp, Set, Url, or bignumber.
Source:

Extends

  • stream.Transform

Methods

(static) encode(…objs) → {Buffer}

Encode one or more JavaScript objects, and return a Buffer containing the CBOR bytes.
Parameters:
Name Type Attributes Description
objs any <repeatable>
the objects to encode
Source:
Returns:
- the encoded objects
Type
Buffer

addSemanticType(type, fun) → {encodeFunction}

Add an encoding function to the list of supported semantic types. This is useful for objects for which you can't add an encodeCBOR method
Parameters:
Name Type Description
type any
fun any
Source:
Returns:
Type
encodeFunction

pushAny(obj) → {boolean}

Push any supported type onto the encoded stream
Parameters:
Name Type Description
obj any
Source:
Returns:
true on success
Type
boolean