aaronhuggins / cbor-redux

The Concise Binary Object Representation (CBOR) data format (RFC7049) implemented in pure JavaScript, revived.
https://doc.deno.land/https://deno.land/x/cbor_redux/mod.ts
Other
29 stars 6 forks source link

Add support for BigInt #18

Closed aaronhuggins closed 2 years ago

aaronhuggins commented 2 years ago

Similar to handling of number conversion to integer, BigInt should be handled. Currently, BigInt falls through all detection to be handled as a CBOR map.

import { decode, encode } from './mod.ts'

const bigint = 101n
const number = 100
const a = new Map<any, any>([
  [bigint, bigint],
  [number, number]
])
const encoded = encode(a)
const decoded = decode(encoded, null, { dictionary: 'map' })

console.log(decoded)
// Output: Map { Map {} => Map {}, 100 => 100 }

This is also a prerequisite for proper round-trip of large integer values between CBOR implementations.

aaronhuggins commented 2 years ago

Finished in commit f4ebdf7177240065cb389d7f2fcdf60c45d7e4c0