shamblett / cbor

A CBOR implementation for Dart
MIT License
36 stars 16 forks source link

Encoding complex maps #8

Closed itavero closed 4 years ago

itavero commented 4 years ago

For my application I have some more complex structures in which there is a map that has nested maps (and sometimes even nested lists in side of them). Just creating a Dart map with all the data and calling encoder.writeMap doesn't work (throws an exception, because the nested map/list isn't being handled nicely).

I figured I could work around this by calling encoder.writeMap with the map that has the "simple" stuff in it, setting indefinite to false and passing the total number of elements to length. The first byte it generates shows the correct length, but somehow the calls I do to the encoder afterwards are not taken into account. Calls I do afterwards include encoder.writeString (to write the key) and encoder.writeMap (to write the nested map).

There is not much documentation on how these more complex types should be handled and I was hoping this would be a solution. Can someone elaborate on how this should be done (or tell me if I'm missing a call or something)?

itavero commented 4 years ago

Really don't know what happened. I ran my code again and it magically works. 😵