how can I get char* from message.getSegmentsForOutput();

34 views
Skip to first unread message

张小

unread,
Sep 29, 2019, 11:28:24 AM9/29/19
to Cap'n Proto
capnp::MallocMessageBuilder message;

kj::ArrayPtr<const kj::ArrayPtr<const capnp::word>> segments = message.getSegmentsForOutput();

and I want get char* from segments how can i do ? 

Kenton Varda

unread,
Sep 29, 2019, 4:26:27 PM9/29/19
to 张小, Cap'n Proto
Like this (broken into three lines with full types for illustrative purposes):

    kj::ArrayPtr<const capnp::word> segment = segments[i];
    kj::ArrayPtr<const char> chars = segment.asChars();
    const char* ptr = chars.begin();
    size_t charCount = chars.size();

-Kenton

--
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 capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/67493bb0-5396-4eb0-a5f8-5c05c8b9cd4c%40googlegroups.com.

张小

unread,
Sep 29, 2019, 11:07:19 PM9/29/19
to Cap'n Proto
when i  get the char* mem addr how can I convert char* to  kj::ArrayPtr<const capnp::word> segment ?

在 2019年9月30日星期一 UTC+8上午4:26:27,Kenton Varda写道:
Like this (broken into three lines with full types for illustrative purposes):

    kj::ArrayPtr<const capnp::word> segment = segments[i];
    kj::ArrayPtr<const char> chars = segment.asChars();
    const char* ptr = chars.begin();
    size_t charCount = chars.size();

-Kenton

On Sun, Sep 29, 2019 at 8:28 AM 张小 <7745...@qq.com> wrote:
capnp::MallocMessageBuilder message;

kj::ArrayPtr<const kj::ArrayPtr<const capnp::word>> segments = message.getSegmentsForOutput();

and I want get char* from segments how can i do ? 

--
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 capn...@googlegroups.com.
Message has been deleted

Kenton Varda

unread,
Sep 30, 2019, 11:49:31 AM9/30/19
to 张小, Cap'n Proto
On Sun, Sep 29, 2019 at 9:45 PM 张小 <7745...@qq.com> wrote:
I hava do this ,how can I get the Message from char* val_buf
kj::ArrayPtr<capnp::word> capn_buf = kj::arrayPtr(reinterpret_cast<capnp::word*>(val_buf), data_file_size);

That works with the caveat that it doesn't consider alignment -- if val_buf is not word-aligned then all the reads from this buffer will be misaligned. That may or may not matter depending on your CPU architecture and performance requirements.

-Kenton
 

在 2019年9月30日星期一 UTC+8上午11:07:19,张小写道:
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/2666e0d4-cd04-4baa-9cad-f173be03ca44%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages