libcbor icon indicating copy to clipboard operation
libcbor copied to clipboard

Stream encoding

Open moeghassi opened this issue 5 years ago • 2 comments

Has there been any work done to implement stream encoder? I'm thinking of taking a look at it.

moeghassi avatar May 13 '20 19:05 moeghassi

Hi @mghicho, not really, but the current encoders can be used to encode e.g. an array or a map in a streaming manner by calling e.g. cbor_encode_indef_array_start and then encoding individual items and terminating, flushing buffers as needed. What would the API you have in mind look like?

PJK avatar May 14 '20 22:05 PJK

Hi, Sorry I somehow missed the notification that you replied. I actually went with the same method your suggested, it was enough for my application.

But when I was exploring ideas, I thought of an api that you can feed it your json text in a streaming fashion, and receive whatever binary is prepared at that time, something like:

streaming_encode(
    char* jsonText,  ///< [IN]
    int jsonTextLength,   ///< [IN]
    uint8_t outBuffer,    ///<  [OUT]
    int* outBufferLengthPtr ///<  [OUT])

moeghassi avatar Jun 27 '20 20:06 moeghassi