Hi Ambrase,

copyToUnchecked() does not write a segment table at the beginning of the
message. That's probably why you're seeing a message 8 bytes shorter.

copyToUnchecked() and readMessageUnchecked() are difficult to use correctly
(and are insecure when used incorrectly). I strongly recommend against
using them.

Instead, consider using capnp::clone(reader) if you just want to clone the
message in memory that you can then pass around with move semantics.

-Kenton

On Tue, Sep 29, 2020 at 9:40 AM Ambrase <[email protected]> wrote:

> Hi
>
> I have an input byte buffer with N messages. There are 2 cases: this byte
> buffer is zero-byte packed or not.
> I read messages like this:
> capnp::PackedMessageReader packedReader(cpnpReader.getAdapter(),
> capnp::ReaderOptions(), cpnpReader.getArray()); (where the adapter is an
> adapter for InputStream on the top of the received packet from UDP/Mcast,
> the array is an unpacked output buffer).
> or with capnp::FlatArrayMessageReader if the message isn't packed.
>
> I'm trying to save some received messages in the way that they will be
> movable, unpacked and at the same time ready to send.
> I get a reader as:
> auto anymessage = packedReader.getRoot<capnp::AnyStruct>();
> then I can copy it to a bytebuffer that can be moved or stored:
> capnp::copyToUnchecked(anymessage, arrayPtr);
>
> The copied buffer is 8 byte less. I assume it is lacking the WirePointer.
> 1)Can I somehow save it with WirePointer at all?
> 2)How to reuse the saved buffer without the WirePointer as a ready message
> for
> MallocMessageBuilder?
>
> I also tried this way:
> capnp::AnyPointer::Reader reader =
> capnp::readMessageUnchecked<capnp::AnyPointer>(reinterpret_cast<const
> capnp::word*>(storedBuffer.data()));
> m_builder.setRoot(kj::fwd<capnp::AnyPointer::Reader>(reader));
>
> But the builder writes 0. So, I did something wrong.
>
> Thanks for your help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/a6951785-d283-4460-a3e5-9ef94a2efffen%40googlegroups.com
> <https://groups.google.com/d/msgid/capnproto/a6951785-d283-4460-a3e5-9ef94a2efffen%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQ%3DZRR-_2143fWPgok0QKS6Bj77hDzzsR%2BEcbx4Jgp_wYQ%40mail.gmail.com.

Reply via email to