Hi All,

We serialise some binary blobs as part of our data using the C++
implementation of Avro. Currently the C++ API has several calls for this
that pass values back to the client via std::vector<uint8_t>, for example...

    std::vector<uint8_t> Decode::decodeBytes();
    void Decode::decodeBytes(std::vector<uint8_t> &value);

If the client isn't holding the data in a std::vector, or using some other
allocation method, this forces the client to do a separate allocation and
memcpy the data out of the vector that the API returns the data in. We've
implemented a new API on the decoder that allows the client to allocate the
data and pass the buffers into the decoder. The API is...

    /// Decodes the number of bytes that will be read in a subsequent
    /// \ref decodeBytesData call.
    size_t Decode::decodeBytesSize();

    /// Decodes the bytes data into an allocated buffer of length len, which
    /// must contain at least as many bytes as was returned by the previous
    /// \ref decodeBytesSize() call.
    void Decode::decodeBytesData(uint8_t *buffer, size_t len);

So the client would do 2 calls to read the data blob,
    size_t nBytesToRead = decoder->decodeBytesSize();
    void *buffer = myAllocationMethod(nBytesToRead);
    decoder->decodeBytes(buffer, nBytesToRead);

Would this be a thing you'd want to integrate onto the mainline of avro? If
so we can tidy it up, make some tests and make a PR for it.

thanks

Bruno

-- 
Bruno Nicoletti, CTO and Co-founder
Filigree Technologies Ltd,

Reply via email to