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 Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { org.apache.calcite.avatica.proto.Common.WireMessage parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (org.apache.calcite.avatica.proto.Common.WireMessage) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; }
/** * <code>string name = 1;</code> */ public Builder setName( java.lang.String value) { if (value == null) { throw new NullPointerException(); } name_ = value; onChanged(); return this; } /**
@java.lang.Override public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { org.apache.calcite.avatica.proto.Common.WireMessage parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (org.apache.calcite.avatica.proto.Common.WireMessage) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; }
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); }
public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { org.apache.calcite.avatica.proto.Common.WireMessage parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (org.apache.calcite.avatica.proto.Common.WireMessage) e.getUnfinishedMessage(); throw e; } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; }
@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); }
private Builder() { maybeForceBuilderInitialization(); }
@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); }
private Builder() { maybeForceBuilderInitialization(); }
private Builder() { maybeForceBuilderInitialization(); }
public static Builder newBuilder(org.apache.calcite.avatica.proto.Common.WireMessage prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } @java.lang.Override
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; }
/** * <code>string name = 1;</code> */ public Builder setNameBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } checkByteStringIsUtf8(value); name_ = value; onChanged(); return this; }
/** * <code>optional string name = 1;</code> */ public Builder setNameBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } checkByteStringIsUtf8(value); name_ = value; onChanged(); return this; }
/** * <code>bytes wrapped_message = 2;</code> */ public Builder clearWrappedMessage() { wrappedMessage_ = getDefaultInstance().getWrappedMessage(); onChanged(); return this; } @java.lang.Override
/** * <code>bytes wrapped_message = 2;</code> */ public Builder setWrappedMessage(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } wrappedMessage_ = value; onChanged(); return this; } /**
@java.lang.Override protected Builder newBuilderForType( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**