-
Notifications
You must be signed in to change notification settings - Fork 658
Closed
Labels
Description
What is your use-case and why do you need this feature?
I want to use this library to communicate with an API that uses CBOR for payloads. This API is strictly requesting Arrays and Maps to be encoded with a definite length, because of / lack of dynamic memory allocation.
Encoding a Kotlin Array
or a Kotlin Map
will always result in their indefinite-length counterpart, so the API will fail when decoding my payload.
Describe the solution you'd like
This line:
Cbor.encodeToByteArray(arrayOf(mapOf(\* stuff *\)))
now serializes to:
9F # array(*)
BF # map(*)
/* stuff */
FF # primitive(*)
FF # primitive(*)
I'd like to be able to, e.g., pass a parameter:
Cbor.encodeToByteArray(arrayOf(mapOf(\* stuff *\)), Lengths.DEFINITE)
to be able to change the serialization to:
81 # array(1)
A1 # map(1)
/* stuff */
tkirshboim, eirikvaa, LaStrada, SilverAndro and angelix