rvagg / cborg

fast CBOR with a focus on strictness
Other
47 stars 13 forks source link

decodeFirst() #93

Closed rvagg closed 1 year ago

rvagg commented 1 year ago

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.

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 4.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: