Are you transmitting one big buffer containing all the segments, or are you transmitting each segment separately?
It looks like you're trying to do the latter, but in that case you cannot use Serialize.read() to read it. You need to use `new MessageReader(segments)`. -Kenton On Mon, Sep 30, 2019 at 5:52 AM 张小 <[email protected]> wrote: > First Time: > In C++ server,I Use capnp::DynamicStruct, code like this: > capnp::MallocMessageBuilder msg; > capnp::DynamicStruct::Builder fullinfo_builder > = msg.initRoot<capnp::DynamicStruct>(g_schema); > capnp::DynamicStruct::Builder fullInfo = > msg.initRoot<capnp::DynamicStruct>(g_schema); > > capnp::messageToFlatArray(msg); ---->convert it to char* send to > java_cliet > > Java Client ,code like this: > MessageReader message > = org.capnproto.Serialize.read(capn_object_bytes.asReadOnlyByteBuffer());, > Info.Reader adInfo = message.getRoot(Info.factory); > > Above , My First Time do work , but The Second Time, I do like this ,it do > not work: > In C++ server, code like this: > > capnp::MallocMessageBuilder message; > Info::Builder info = message.initRoot<Info>(); > info.setId(123); > kj::ArrayPtr<const kj::ArrayPtr<const capnp::word>> segments = > message.getSegmentsForOutput(); > > then I convert the segments object to char* send to java_client by proto > rpc_call (bytes field) > > > Java Client ,code like this: > MessageReader message > = org.capnproto.Serialize.read(capn_object_bytes.asReadOnlyByteBuffer());, > Info.Reader adInfo = message.getRoot(Info.factory); > > > In Second Time, happen Error like this: > > Exception in thread "main" java.lang.IllegalArgumentException > at java.nio.Buffer.limit(Buffer.java:275) > at org.capnproto.Serialize.read(Serialize.java:140) > at org.capnproto.Serialize.read(Serialize.java:111) > > How Can I do , In Second Time ,thanks > > > > > > > 在 2019年9月30日星期一 UTC+8下午8:29:41,David Renshaw写道: >> >> On the Java side, you need to first read the bytes into a >> `MessageReader`. That's typically done via one of the `Serialize.read()` >> methods. >> >> The `AnyPointer.Reader()` is not intended for external use. Probably we >> should make it private. >> >> >> On Mon, Sep 30, 2019 at 6:25 AM 张小 <[email protected]> wrote: >> >>> C++ server send Capn Object to JavaClient like this >>> >>> capnp::MallocMessageBuilder message; >>> Info::Builder info = message.initRoot<Info>(); >>> info.setId(123); >>> kj::ArrayPtr<const kj::ArrayPtr<const capnp::word>> segments = >>> message.getSegmentsForOutput(); >>> >>> then I convert the segments object to char* send to java_client by >>> proto rpc_call (bytes field) >>> >>> >>> Then In java_client, I do like this to read the capn object >>> com.google.protobuf.ByteString capn_object_bytes = >>> response.getCapnObject() >>> SegmentReader segment = new >>> SegmentReader(capn_object_bytes.asReadOnlyByteBuffer(), null); >>> AnyPointer.Reader any = new AnyPointer.Reader(segment, 0, 64*1024*1024); >>> Info.Reader info = any.getAs(Info.factory); >>> System.out.println("Id:" + info.getId()); >>> >>> >>> run java_cliet ,happend error like this : >>> Exception in thread "main" java.lang.NullPointerException >>> at org.capnproto.WireHelpers.readStructPointer(WireHelpers.java:918) >>> at >>> org.capnproto.StructFactory.fromPointerReaderRefDefault(StructFactory.java:34) >>> at org.capnproto.StructFactory.fromPointerReader(StructFactory.java:41) >>> at org.capnproto.StructFactory.fromPointerReader(StructFactory.java:24) >>> at org.capnproto.AnyPointer$Reader.getAs(AnyPointer.java:56) >>> >>> >>> >>> >>> -- >>> 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/081ab20b-5eae-43d5-a4fc-8230ef39d4a5%40googlegroups.com >>> <https://groups.google.com/d/msgid/capnproto/081ab20b-5eae-43d5-a4fc-8230ef39d4a5%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/816c3227-c2b2-4b72-8ead-e707759a257c%40googlegroups.com > <https://groups.google.com/d/msgid/capnproto/816c3227-c2b2-4b72-8ead-e707759a257c%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/CAJouXQnRDH-CvJRr6jgKYzjenuOG2gHDDxKMzURQST2bN4ktoA%40mail.gmail.com.
