cbor-java icon indicating copy to clipboard operation
cbor-java copied to clipboard

Creating a finite/fixed-size map

Open Avamander opened this issue 2 years ago • 2 comments

Quite a few embedded libraries do not like indefinite-sized CBOR maps (or arrays for that matter).

For demonstration, I created a map with:

            new CborEncoder(baos).encode(new CborBuilder()
                    .startMap(4)
                    .put("Timestamp", 123456789)
                    .end()
                    .build()

and the resulting map is:

BF                         # map(*)
   69                      # text(9)
      54696D657374616D70   # "Timestamp"
   1A 075BCD15             # unsigned(123456789)

Is there a way to assemble a map that has a specified length in the end result?

Avamander avatar Nov 28 '21 18:11 Avamander

Hi @Avamander, is commit https://github.com/c-rack/cbor-java/commit/0ef74dc1a8dfa74fbb5cdcba6b64ad185bb1ba54 what you are looking for?

c-rack avatar Nov 28 '21 19:11 c-rack

It probably is if you're proposing it :sweat_smile: as you know your library and CBOR much better.

I could test it out specifically if at some point you'd make a release with the change incorporated, I don't know how to build this library myself.

Avamander avatar Nov 28 '21 19:11 Avamander