Hi,
I am using Cap'n Proto to serialise a data tree which is then sent as a blob to a client to be unpacked. I was using something similar to:
kj::VectorOutputStream out;
capnp::writePackedMessage(out, builder);
auto arr = out.getArray();
char* buffer = (char*)malloc(arr.size());
memcpy(buffer, arr.begin(), arr.size());
and
kj::ArrayPtr<kj::byte> buffer(reinterpret_cast<kj::byte*>(const_cast<char*>(bytes)), size);
kj::ArrayInputStream in(buffer);
capnp::PackedMessageReader reader{in};
This is working for small tree sizes but segfaults when I get to larger number of elements.
I've found a solution that works by switching to messageToFlatArray and FlatArrayMessageReader but this dramatically increases the amount of data that needs to be sent, especially for small trees.
I've also found that writing the buffer to a file and then using PackedFdMessageReader also works but i'd rather avoid creating files unnessarily.
Is there a way to use the PackedMessageReader with a byte buffer?
Cheers,
Jonathan.