void serializeMessage(OutputStream out, Message msg) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); msg.writeTo(baos); // TODO Using ByteString is copying the bytes of the message which sucks. Could try to // lift the ZeroCopy implementation from HBase. WireMessage wireMsg = WireMessage.newBuilder().setName(msg.getClass().getName()). setWrappedMessage(ByteString.copyFrom(baos.toByteArray())).build(); wireMsg.writeTo(out); }
void serializeMessage(OutputStream out, Message msg) throws IOException { // Serialize the protobuf message UnsynchronizedBuffer buffer = threadLocalBuffer.get(); ByteString serializedMsg; try { msg.writeTo(buffer); // Make a bytestring from it serializedMsg = UnsafeByteOperations.unsafeWrap(buffer.toArray()); } finally { buffer.reset(); } // Wrap the serialized message in a WireMessage WireMessage wireMsg = WireMessage.newBuilder().setNameBytes(getClassNameBytes(msg.getClass())) .setWrappedMessage(serializedMsg).build(); // Write the WireMessage to the provided OutputStream wireMsg.writeTo(out); }
void serializeMessage(OutputStream out, Message msg) throws IOException { // Serialize the protobuf message UnsynchronizedBuffer buffer = threadLocalBuffer.get(); ByteString serializedMsg; try { msg.writeTo(buffer); // Make a bytestring from it serializedMsg = UnsafeByteOperations.unsafeWrap(buffer.toArray()); } finally { buffer.reset(); } // Wrap the serialized message in a WireMessage WireMessage wireMsg = WireMessage.newBuilder().setNameBytes(getClassNameBytes(msg.getClass())) .setWrappedMessage(serializedMsg).build(); // Write the WireMessage to the provided OutputStream wireMsg.writeTo(out); }
@Test public void testExecuteSerialization() throws Exception { Service.ExecuteRequest executeRequest = new Service.ExecuteRequest( new StatementHandle("connection", 12345, getSignature()), getTypedValues(), 0); Requests.ExecuteRequest pbExecuteRequest = executeRequest.serialize(); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); pbExecuteRequest.writeTo(baos); byte[] serialized = baos.toByteArray(); baos.reset(); WireMessage wireMsg = WireMessage.newBuilder().setName(Requests.ExecuteRequest.class.getName()) .setWrappedMessage(UnsafeByteOperations.unsafeWrap(serialized)).build(); wireMsg.writeTo(baos); serialized = baos.toByteArray(); ProtobufTranslation translator = new ProtobufTranslationImpl(); Request newRequest = translator.parseRequest(serialized); Assert.assertEquals(executeRequest, newRequest); }
@Test public void testExecuteSerialization() throws Exception { Service.ExecuteRequest executeRequest = new Service.ExecuteRequest( new StatementHandle("connection", 12345, getSignature()), getTypedValues(), 0); Requests.ExecuteRequest pbExecuteRequest = executeRequest.serialize(); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); pbExecuteRequest.writeTo(baos); byte[] serialized = baos.toByteArray(); baos.reset(); WireMessage wireMsg = WireMessage.newBuilder().setName(Requests.ExecuteRequest.class.getName()) .setWrappedMessage(UnsafeByteOperations.unsafeWrap(serialized)).build(); wireMsg.writeTo(baos); serialized = baos.toByteArray(); ProtobufTranslation translator = new ProtobufTranslationImpl(); Request newRequest = translator.parseRequest(serialized); Assert.assertEquals(executeRequest, newRequest); }
public Builder mergeFrom(org.apache.calcite.avatica.proto.Common.WireMessage other) { if (other == org.apache.calcite.avatica.proto.Common.WireMessage.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (other.getWrappedMessage() != com.google.protobuf.ByteString.EMPTY) { setWrappedMessage(other.getWrappedMessage()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
public Builder mergeFrom(org.apache.calcite.avatica.proto.Common.WireMessage other) { if (other == org.apache.calcite.avatica.proto.Common.WireMessage.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (other.getWrappedMessage() != com.google.protobuf.ByteString.EMPTY) { setWrappedMessage(other.getWrappedMessage()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
public Builder mergeFrom(org.apache.calcite.avatica.proto.Common.WireMessage other) { if (other == org.apache.calcite.avatica.proto.Common.WireMessage.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (other.getWrappedMessage() != com.google.protobuf.ByteString.EMPTY) { setWrappedMessage(other.getWrappedMessage()); } onChanged(); return this; }