Constructor
new Decoder(optionsopt)
Create a parsing stream.
- Source:
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object
|
<optional> |
{} |
|
Extends
- BinaryParseStream
Methods
(static) decodeAll(input, options, cb) → {Promise}
Decode all of the CBOR items in the input. This will error if there are
more bytes left over at the end.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
input |
string
|
Buffer
|
the input to parse |
options |
string
|
Object
|
Decoding options. If string, the input encoding. |
cb |
decodeAllCallback
|
Returns:
- Type:
-
Promise
if no callback
(static) decodeAllSync(input, optionsopt) → {Array}
Decode all of the CBOR items in the input into an array. This will throw
an exception if the input is not valid CBOR; a zero-length input will
return an empty array.
- Source:
Parameters:
Name | Type | Attributes | Default | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
input |
string
|
Buffer
|
|||||||||||
options |
string
|
Object
|
<optional> |
{encoding: 'hex'} |
|
Returns:
- Type:
-
Array
- Array of all found items
(static) decodeFirst(input, options, cb) → {Promise}
Decode the first CBOR item in the input. This will error if there are more
bytes left over at the end, and optionally if there were no valid CBOR
bytes in the input. Emits the {Decoder.NOT_FOUND} Symbol in the callback
if no data was found and the `required` option is false.
- Source:
Parameters:
Name | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
input |
string
|
Buffer
|
the input to parse | ||||||||
options |
function
|
string
|
Object
|
|
||||||||
cb |
decodeCallback
|
Returns:
- Type:
-
Promise
if no cb specified
(static) decodeFirstSync(input, optionsopt) → {any}
Decode the first CBOR item in the input, synchronously. This will throw an
exception if the input is not valid CBOR.
- Source:
Parameters:
Name | Type | Attributes | Default | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
input |
string
|
Buffer
|
|||||||||||
options |
object
|
<optional> |
{encoding: 'hex'} |
|
Returns:
- Type:
-
any
- the decoded value
(static) nullcheck(val) → {any}
Check the given value for a symbol encoding a NULL or UNDEFINED value in
the CBOR stream.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
val |
any
|
the value to check |
Returns:
- Type:
-
any
the corrected value
Example
myDecoder.on('data', function(val) {
val = Decoder.nullcheck(val);
...
});