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); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.calcite.avatica.proto.Common.WireMessage)) { return super.equals(obj); } org.apache.calcite.avatica.proto.Common.WireMessage other = (org.apache.calcite.avatica.proto.Common.WireMessage) obj; boolean result = true; result = result && getName() .equals(other.getName()); result = result && getWrappedMessage() .equals(other.getWrappedMessage()); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (!getNameBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); } if (!wrappedMessage_.isEmpty()) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(2, wrappedMessage_); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
if (!parseUnknownFieldProto3( input, unknownFields, extensionRegistry, tag)) { done = true; } finally { this.unknownFields = unknownFields.build(); makeExtensionsImmutable();
if (!parseUnknownFieldProto3( input, unknownFields, extensionRegistry, tag)) { done = true; } finally { this.unknownFields = unknownFields.build(); makeExtensionsImmutable();
e.getMessage()).setUnfinishedMessage(this)); } finally { makeExtensionsImmutable();
@Override public Response parseResponse(byte[] bytes) throws IOException { ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes); CodedInputStream inputStream = byteString.newCodedInput(); // Enable aliasing to avoid an extra copy to get at the serialized Response inside of the // WireMessage. inputStream.enableAliasing(true); WireMessage wireMsg = WireMessage.parseFrom(inputStream); String serializedMessageClassName = wireMsg.getName(); try { ResponseTranslator translator = getParserForResponse(serializedMessageClassName); return translator.transform(wireMsg.getWrappedMessage()); } catch (RuntimeException e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to parse response message '{}'", TextFormat.shortDebugString(wireMsg)); } throw e; } } }
@Override public Response parseResponse(byte[] bytes) throws IOException { ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes); CodedInputStream inputStream = byteString.newCodedInput(); // Enable aliasing to avoid an extra copy to get at the serialized Response inside of the // WireMessage. inputStream.enableAliasing(true); WireMessage wireMsg = WireMessage.parseFrom(inputStream); String serializedMessageClassName = wireMsg.getName(); try { ResponseTranslator translator = getParserForResponse(serializedMessageClassName); return translator.transform(wireMsg.getWrappedMessage()); } catch (RuntimeException e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to parse response message '{}'", TextFormat.shortDebugString(wireMsg)); } throw e; } } }
@Override public Request parseRequest(byte[] bytes) throws IOException { ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes); CodedInputStream inputStream = byteString.newCodedInput(); // Enable aliasing to avoid an extra copy to get at the serialized Request inside of the // WireMessage. inputStream.enableAliasing(true); WireMessage wireMsg = WireMessage.parseFrom(inputStream); String serializedMessageClassName = wireMsg.getName(); try { RequestTranslator translator = getParserForRequest(serializedMessageClassName); // The ByteString should be logical offsets into the original byte array return translator.transform(wireMsg.getWrappedMessage()); } catch (RuntimeException e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to parse request message '{}'", TextFormat.shortDebugString(wireMsg)); } throw e; } }
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); }
@Override public Request parseRequest(byte[] bytes) throws IOException { ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes); CodedInputStream inputStream = byteString.newCodedInput(); // Enable aliasing to avoid an extra copy to get at the serialized Request inside of the // WireMessage. inputStream.enableAliasing(true); WireMessage wireMsg = WireMessage.parseFrom(inputStream); String serializedMessageClassName = wireMsg.getName(); try { RequestTranslator translator = getParserForRequest(serializedMessageClassName); // The ByteString should be logical offsets into the original byte array return translator.transform(wireMsg.getWrappedMessage()); } catch (RuntimeException e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to parse request message '{}'", TextFormat.shortDebugString(wireMsg)); } throw e; } }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.calcite.avatica.proto.Common.WireMessage)) { return super.equals(obj); } org.apache.calcite.avatica.proto.Common.WireMessage other = (org.apache.calcite.avatica.proto.Common.WireMessage) obj; boolean result = true; result = result && getName() .equals(other.getName()); result = result && getWrappedMessage() .equals(other.getWrappedMessage()); result = result && unknownFields.equals(other.unknownFields); return result; }
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); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (!getNameBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); } if (!wrappedMessage_.isEmpty()) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(2, wrappedMessage_); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@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); }
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + NAME_FIELD_NUMBER; hash = (53 * hash) + getName().hashCode(); hash = (37 * hash) + WRAPPED_MESSAGE_FIELD_NUMBER; hash = (53 * hash) + getWrappedMessage().hashCode(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {