0

In Java Client I get a

com.google.protobuf.ByteString capn_object_bytes =   response.getCapnObject(); 

from C++ Server, and I want read the Capn Object from protobuf.ByteString

@Kenton Varda

Hadi GhahremanNezhad
  • 2,377
  • 5
  • 29
  • 58
whutbd
  • 3
  • 1

2 Answers2

0

Use ByteString#asReadOnlyByteBuffer() to get a ByteBuffer, which you can then read into Cap'n Proto:

MessageReader message =
    org.capnproto.Serialize.read(capn_object_bytes.asReadOnlyByteBuffer());
Kenton Varda
  • 41,353
  • 8
  • 121
  • 105
  • when in c++ server kj::ArrayPtr> segments = message.getSegmentsForOutput(); and java client do like this happen error MessageReader message = org.capnproto.Serialize.read(capn_object_bytes.asReadOnlyByteBuffer()); – whutbd Sep 30 '19 at 12:57
  • @whutbd `getSegmentsForOutput()` only returns the segment array, which is *not* the complete serialized message. A serialized message needs to be prefixed with a segment table that indicates the size of each segment. That said, if you're able to transmit the segments and keep track of their sizes in your own way, so that you have a `ByteBuffer[]` in Java containing all the segments, then you can pass that directly to `MessageReader`'s constructor in Java. – Kenton Varda Sep 30 '19 at 15:56
0

when in c++ server kj::ArrayPtr> segments = message.getSegmentsForOutput();

and java client do like this happen error MessageReader message = org.capnproto.Serialize.read(capn_object_bytes.asReadOnlyByteBuffer());

whutbd
  • 3
  • 1