Giter Site home page Giter Site logo

Comments (5)

hildjj avatar hildjj commented on July 28, 2024

This is likely because the Buffer implementation you're using outside of the WebPack'd code is different from the one inside. The one inside got mangled, and the one outside didn't, so when node-cbor is trying to find out "is this a Buffer?" it doesn't get a match. This leads to the buffer being encoded as a plain object, which, if I recall correctly, serializes it as a string with comma-delimited decimal numbers, one per byte -- which will be much larger than the correct serialization.

To fix this, either pack all of your code together, or export the Buffer implementation from inside the packed code, then use that in your unpacked code. There are likely other ways to fix it, but let's see if this hypothesis proves out first.

from node-cbor.

noway avatar noway commented on July 28, 2024

You're right, Buffer.name gets mangled and the encoding can't find a proper converter. I'll make a PR.

from node-cbor.

hildjj avatar hildjj commented on July 28, 2024

Can you try passing in a genTypes option into the Encoder instance?

Encoder.encodeOne(Buffer.alloc(2), { genTypes: [Buffer, Encoder._pushBuffer] });

and if that doesn't work, try:

Encoder.encodeOne(Buffer.alloc(2), { genTypes: [Buffer.name, Encoder._pushBuffer] });

from node-cbor.

noway avatar noway commented on July 28, 2024

That worked! Passing in my implementation of Buffer from import { Buffer } from "buffer" package using genTypes worked for me. Now I don't need the patch in #166

I gonna close that pull request since this workaround solves it.

from node-cbor.

noway avatar noway commented on July 28, 2024

Here's how i've done it: vaxxnz/nzcp-js#60

from node-cbor.

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.