For both CBOR and JSON decoders. const [value, remainder] = decodeFirst(buf). Where remainder is a subarray, so just a view over the original ArrayBuffer.
import { decodeFirst } from 'cborg'
let buf = Buffer.from('a16474686973a26269736543424f522163796179f564746869736269736543424f522163796179f5', 'hex')
while (buf.length) {
const [value, remainder] = decodeFirst(buf)
console.log('decoded:', value)
buf = remainder
}
decoded: { this: { is: 'CBOR!', yay: true } }
decoded: this
decoded: is
decoded: CBOR!
decoded: yay
decoded: true
This is a breaking change because the Tokenizer interface now needs to implement pos() which was previously just implemented as an internal detail but now we need to know where the tokenizer is up to in order to implement this.
For both CBOR and JSON decoders.
const [value, remainder] = decodeFirst(buf)
. Whereremainder
is a subarray, so just a view over the originalArrayBuffer
.This is a breaking change because the
Tokenizer
interface now needs to implementpos()
which was previously just implemented as an internal detail but now we need to know where the tokenizer is up to in order to implement this.