Comments (13)
Because there might have been multiple CBOR objects in your buffer. We could perhaps add an option that only returns the first one, but it would probably need to return the number of bytes eaten as well.
from node-cbor.
It would be good for it to understand that it was serialized only '1' JSON object and that it was not serialized inside an array, so that decode(encode(a)) === a
is true, otherwise it might be understood as it changing the data that was serialized
from node-cbor.
I can't stand functions that return different types based on their inputs. What I would be willing to do is add a decodeOne
method that returns the first thing. Ideally, I'd change decode to be decodeOne
and make the current decode
be decodeAll
, but that would be a breaking API change that I'd prefer not to make.
from node-cbor.
I can't stand functions that return different types based on their inputs.
I think your point is valid and it is for that reason why I am strongly in favor of returning the exact same object that was encoded.
but that would be a breaking API change that I'd prefer not to make.
Agree that is a PITA, but then again, would it be better to have the decoding returning a different type of that of what was encoded? Would love to have more opinions on this.
from node-cbor.
having too much experience with tons of serialization systems + codecs, I would expect
x === decode(encode(x))
to hold
decodeOne
seems like a good option.- understood about not breaking api.
- but i probably would.
- if not breaking api, clearly document + provide other file (like
require('cbor/one')
)
from node-cbor.
The more I think about this, the more I want to redo the whole interface for Node4, using Maps instead of objects, and not dealing with streams. It would be a lot faster, use less memory, be simpler with less code, and deal with integer keys correctly. It would also likely fix the recursion depth issue we have by getting rid of recursion.
from node-cbor.
What do you mean by not dealing with streams?
(Our use case is duplex streams of cbor objects)
—
Sent from Mailbox
On Wed, Sep 16, 2015 at 12:04 PM, Joe Hildebrand [email protected]
wrote:
The more I think about this, the more I want to redo the whole interface for Node4, using Maps instead of objects, and not dealing with streams. It would be a lot faster, use less memory, be simpler with less code, and deal with integer keys correctly. It would also likely fix the recursion depth issue we have by getting rid of recursion.
Reply to this email directly or view it on GitHub:
#21 (comment)
from node-cbor.
Yeah, the approach I'm thinking of would break your use case, @jbenet. Let me keep thinking.
from node-cbor.
I found a way that I think is going to work nicely for streaming. It would get rid of the SAX-style evented parser, and might be a little faster. It requires node4 (or at least --harmony). See: https://github.com/hildjj/node-cbor/blob/node4/src/stream.coffee
from node-cbor.
(Fwiw, node 4 fine for us. We're pushing for it too (it brings balance to the force))
—
Sent from Mailbox
On Thu, Sep 17, 2015 at 1:10 PM, Joe Hildebrand [email protected]
wrote:
I found a way that I think is going to work nicely for streaming. It would get rid of the SAX-style evented parser, and might be a little faster. It requires node4 (or at least --harmony). See: https://github.com/hildjj/node-cbor/blob/node4/src/stream.coffee
Reply to this email directly or view it on GitHub:
#21 (comment)
from node-cbor.
OK, I have a completed node4 branch that I would appreciate feedback on before I commit it. It does fix #15 as well. Note that the API is now decodeFirst or decodeAll.
from node-cbor.
Fixed in #22
from node-cbor.
Thank you @hildjj, apologies for the delay on feedback, but this does look good!
from node-cbor.
Related Issues (20)
- MAXINT64: BigInt('0xffffffffffffffff') crashes on React-Native HOT 12
- Error: Unexpected data: 0x44 HOT 32
- react-native-cli HOT 5
- Webpack minimize causes cbor.encode to generate a different value HOT 5
- Fix Buffer converter matcher being mangled in minimised builds HOT 1
- ReferenceError: Can't find variable: TextDecoder HOT 20
- cbor-diag HOT 5
- Behavior in Nativescript HOT 19
- Encode error when source is too large HOT 4
- switch to using Uint8Array instead of using buffer HOT 3
- Type array tags CBOR HOT 2
- Support `ArrayBufferView` as `BufferLike` HOT 1
- Move to ESM HOT 4
- cbor tagged object not same after decoding and again encoding HOT 8
- cbor-web: Unexpected token on rollup build, is `for(;;)` supposed to be here? HOT 8
- Encoding a "large" 5MB JSON Object HOT 4
- Cbor <> CborWeb issue HOT 1
- empty maps parsed as objects, not maps HOT 4
- diagnose crashes when cose sign1 payload is null HOT 2
- How to turn off taging on Encode for Uint8Arrays? HOT 8
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 node-cbor.