Description
What is your use-case and why do you need this feature?
When encoding data as JSON, it's possible to write serialized data directly into an OutputStream
, via Json.encodeToStream(SerializationStrategy<T>, T, OutputStream)
.
Yet, with CBOR, only writing to or reading from a ByteArray
(byte[]
JVM type) seems possible (Cbor.encodeToByteArray(SerializationStrategy<T>, T): ByteArray
), and the byte array returned gets allocated by the library itself, can't be supplied externally, nor can it be reused.
This leads to extra allocations and frequent OutOfMemoryError
's when encoding large data hierarchies as CBOR, which never happens with JSON.
Describe the solution you'd like
We'd appreciate if any of the following extensions, with the corresponding decodeXyz()
counterparts, are eventually implemented:
Cbor.encodeToStream(SerializationStrategy<T>, T, OutputStream)
Cbor.encodeToChannel(SerializationStrategy<T>, T, WritableByteChannel)
Cbor.encodeToBuffer(SerializationStrategy<T>, T, ByteBuffer)