Giter VIP home page Giter VIP logo

Comments (2)

jfromaniello avatar jfromaniello commented on June 1, 2024

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.

jfromaniello avatar jfromaniello commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.