GithubHelp home page GithubHelp logo

Nesting complex data about cbor HOT 7 CLOSED

DanielSoCra avatar DanielSoCra commented on July 21, 2024 1
Nesting complex data

from cbor.

Comments (7)

nailgilaziev avatar nailgilaziev commented on July 21, 2024

Yeah, I interested in this too.
I encode data like this
(map with different type values)
{1:11,2:22,3:[{1:123,4:true,9:"text"}]}
or (arrays with different type items)
{1:11,2:22,3:[123,true,"text"]}

How to do this efficiently?

from cbor.

shamblett avatar shamblett commented on July 21, 2024

OK, for the first poster why can't you do this

 encoder.writeArray([{1:123456789}]);

this decodes to

81a1011a075bcd15

and decodes correctly in cbor.me

Also second poster can you not do this

encoder.writeMap({1:11,2:22,3:[{1:123,4:true,9:"text"}]});

which also works?

from cbor.

DanielSoCra avatar DanielSoCra commented on July 21, 2024

Hi,
thank you for your work!

The issue is when working with tags, such as the BigInt()

from cbor.

shamblett avatar shamblett commented on July 21, 2024

Yes Ok, I think we need a tag builder package of some sort to assist with tag encoding, we also need some way of assembling a map/list inline, e.g.

open map
add key
add value
add keyValue
close map

so you can do this without using indefinites, does this sound OK, do you have anything else in mind?

from cbor.

DanielSoCra avatar DanielSoCra commented on July 21, 2024

Yes, that is absolutely what I was thinking of.
The existing way of doing things can be left untouched.

It would be great if we could use still definite arrays / maps with the open / close principle.

The length of the map / array can be calculated from the actual length of the map / array and encoded after the array / map is closed.

from cbor.

shamblett avatar shamblett commented on July 21, 2024

Yep OK I'll start putting together some updates along these lines and see how it pans out.

from cbor.

shamblett avatar shamblett commented on July 21, 2024

OK, package updated and re published at version 3.0.0, please have a look at the examples for the new list builder and map builder encoder classes and read the API for docs for these, hopefully we can now better encode lists/maps with complex items without using indefinite sequences.

from 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.