Class: Decoder
| Defined in: | src/decoder.coffee |
| Inherits: | BinaryParseStream |
Overview
Decode a stream of CBOR bytes by transforming them into equivalent JavaScript data. Because of the limitations of Node object streams, special symbols are emitted instead of NULL or UNDEFINED. Fix those up by calling Decoder.nullcheck.
Several other internal events are emitted, but I hope you never need to care about them.
Variables Summary
- NOT_FOUND =
-
NOT_FOUNDA symbol returned from Decoder.decodeFirst when no object was found.
Class Method Summary
- . (void) nullcheck(val) Check the given value for a symbol encoding a NULL or UNDEFINED value in the CBOR stream.
- . (anything) decodeFirstSync(input, options = { encoding: 'hex' }) Decode the first CBOR item in the input, synchronously.
- . (anything) decodeAllSync(input, options = { encoding: 'hex' }) Decode all of the CBOR items in the input.
- . (undefined, Promise) decodeFirst(input, options = { encoding: 'hex' }, cb) Decode the first CBOR item in the input.
- . (undefined, Promise) decodeAll(input, options = { encoding: 'hex' }, cb) Decode all of the CBOR items in the input.
Class Method Details
.
(void)
nullcheck(val)
Check the given value for a symbol encoding a NULL or UNDEFINED value in the CBOR stream.
Examples:
myDecoder.on('data', function(val) {
val = Decoder.nullcheck(val);
...
});
.
(anything)
decodeFirstSync(input, options = {
encoding: 'hex'
})
Decode the first CBOR item in the input, synchronously. This will throw an exception if the input is not valid CBOR.
.
(anything)
decodeAllSync(input, options = {
encoding: 'hex'
})
Decode all of the CBOR items in the input. This will throw an exception if the input is not valid CBOR; a zero-length input will return an empty array.
.
(undefined, Promise)
decodeFirst(input, options = {
encoding: 'hex'
}, cb)
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.
.
(undefined, Promise)
decodeAll(input, options = {
encoding: 'hex'
}, cb)
Decode all of the CBOR items in the input. This will error if there are more bytes left over at the end.
Constructor Details
#
(void)
constructor(options)
Create a parsing stream.