Search code examples
capnproto

how can I get a MessageReader from protobuf.ByteString in java


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


Solution

  • 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());