hildjj / node-cbor

Encode and decode CBOR documents, with both easy mode, streaming mode, and SAX-style evented mode.
MIT License
356 stars 73 forks source link

cbor tagged object not same after decoding and again encoding #181

Closed Veeramani41 closed 1 year ago

Veeramani41 commented 1 year ago

cbor tagged object not same after decoding and again encoding.

steps: creating cbor with 0 tag like cbor = 0("2023-07-21T07:10:09Z") when decoding the above cbor it is coming with datetime value with localtime zone.

then again if try to encode the cbor it is tagged as 1(1689923409)

it is creating problem while persisting the data and again try to reuse the same data.

hildjj commented 1 year ago

pass dateType = 'string' into the encoder?

Veeramani41 commented 1 year ago

is there anyway to stop tagged object decoding and I need to get actual tagged object instead of decoded value. I need to persist all the tags in the data.

hildjj commented 1 year ago

Yep. Pass tags = {} in the decoder options. If you want to decode some tags and not others, you can make a copy of cbor.Tagged.TAGS, modify it however you like, and pass that in for the tags option.

Veeramani41 commented 1 year ago

I tried tags: {} in the decoder options. it is not working, still decodes the tagged object.

hildjj commented 1 year ago

It's going to be {tags: {1: null}}, but there's a bug I need to fix before that works like the docs say it does.

hildjj commented 1 year ago

From the test I just added in #31

  const buf = Buffer.from('c100', 'hex');
  t.deepEqual(cbor.decode(buf), new Date(0));
  t.deepEqual(cbor.decode(buf, {tags: {1: null}}), new cbor.Tagged(1, 0));

9.0.1 release forthcoming.

hildjj commented 1 year ago

I opened this back up to make sure that 9.0.1 fixes your issue. Will close when you confirm.

Veeramani41 commented 1 year ago

now the issue has been fixed