Comments (2)
A weird thing is that if I just hard code the value shown in the encode function, it does produces the expected result:
encode: (obj, enc) => {
// const encodedByteString = encoder.encode(obj.data);
// console.log(`enc byte string: ${encodedByteString.toString('hex')}`);
const buffer = Buffer.from('b9000163666f6f6362617a', 'hex');
enc(buffer);
},
outputs;
encoded: d8184bb9000163666f6f6362617a
So, it seems like the problem is calling an extra encode inside the encode function. I've also tried creating a new instance of the encoder inside the encode function of the extension but it didn't work.
from cbor-x.
I think I figure a way, is not nice... but the issue seems to be related to the module scoped state:
https://github.com/kriszyp/cbor-x/blob/master/encode.js#L15
const importFresh = require('import-fresh');
const { Encoder: Encoder2 } = importFresh('cbor-x');
...
then in the extension encode function:
encode: (obj, enc) => {
const tmpEncoder = new Encoder2(encoderDefaults);
const encodedByteString = tmpEncoder.encode(obj.data);
enc(encodedByteString);
},
from cbor-x.
Related Issues (20)
- Problem when variableMapSize is true and keyMap is used HOT 1
- RangeError while decoding with `largeBigIntToFloat: true,` enabled HOT 5
- packed cbor link in readme doesn't work
- addExtension like msgpackr HOT 1
- resizable arraybuffer
- Incompatible with Bun.js? HOT 4
- Cannot read properties of undefined (reading 'get') on referenceMap.get(id) HOT 5
- Behavior of tagUint8Array HOT 3
- inline-record definitions are not scoped
- TypeError: newPackedValues.concat is not a function HOT 2
- `segmentation fault` / `bus error` randomly on the same input HOT 2
- `Tag` class is not exported from `index.d.ts` HOT 1
- Web/WhatWG Streams API Support
- TypeError: Cannot create property 'slowReads' on number '0'
- TypeScript can't find types when importing `cbor-x/index-no-eval` HOT 1
- Maximum call Stack exceeded when calling decodeMultiple in a service worker in Edge Browser
- Bug in value sharing extension, discards revived state by Object.assign HOT 2
- Invalid property name type object when key is Buffer HOT 2
- How can I encode JS `BigInt`s with cbor-x?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cbor-x.