On Sun, Sep 29, 2019 at 9:45 PM 张小 <[email protected]> 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,张小写道: >> >> 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 张小 <[email protected]> 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 [email protected]. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/capnproto/67493bb0-5396-4eb0-a5f8-5c05c8b9cd4c%40googlegroups.com >>>> <https://groups.google.com/d/msgid/capnproto/67493bb0-5396-4eb0-a5f8-5c05c8b9cd4c%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/2666e0d4-cd04-4baa-9cad-f173be03ca44%40googlegroups.com > <https://groups.google.com/d/msgid/capnproto/2666e0d4-cd04-4baa-9cad-f173be03ca44%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/CAJouXQk226S3%2BiaR_2bR8iy%3D3COWyLEox9sTqDhH4huKxvs2oQ%40mail.gmail.com.
