Java Code Examples for com.google.protobuf.Message#toByteString()
The following examples show how to use
com.google.protobuf.Message#toByteString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessagePayloadSerializerPb.java From stateful-functions with Apache License 2.0 | 8 votes |
@Override public Object copy(@Nonnull ClassLoader targetClassLoader, @Nonnull Object what) { Objects.requireNonNull(targetClassLoader); if (!(what instanceof Message)) { throw new IllegalStateException(); } Message message = (Message) what; ByteString messageBytes = message.toByteString(); try { Parser<? extends Message> parser = parserForClassName(targetClassLoader, what.getClass().getName()); return parser.parseFrom(messageBytes); } catch (InvalidProtocolBufferException | ClassNotFoundException e) { throw new IllegalStateException(e); } }
Example 2
Source File: MessagePayloadSerializerPb.java From flink-statefun with Apache License 2.0 | 6 votes |
@Override public Object copy(@Nonnull ClassLoader targetClassLoader, @Nonnull Object what) { Objects.requireNonNull(targetClassLoader); if (!(what instanceof Message)) { throw new IllegalStateException(); } Message message = (Message) what; ByteString messageBytes = message.toByteString(); try { Parser<? extends Message> parser = parserForClassName(targetClassLoader, what.getClass().getName()); return parser.parseFrom(messageBytes); } catch (InvalidProtocolBufferException | ClassNotFoundException e) { throw new IllegalStateException(e); } }
Example 3
Source File: DynamicProtoUtil.java From rejoiner with Apache License 2.0 | 6 votes |
/** * Encodes the data portion of an ExecutionResult as ByteString. * * <p>The FileDescriptorSet must contain a message with the name "{operationName}Response". This * message will be populated with data from the execution result and encoded as a ByteString. */ public static ByteString encodeResponse( String operationName, FileDescriptorSet fileDescriptorSet, ExecutionResult executionResult) { try { // TODO: Support multiple FileDescriptors in FileDescriptorSet FileDescriptor fileDescriptor = FileDescriptor.buildFrom(fileDescriptorSet.getFileList().get(0), new FileDescriptor[] {}); Descriptor messageType = fileDescriptor.findMessageTypeByName(operationName + "Response"); Message message = DynamicMessage.parseFrom(messageType, ByteString.EMPTY); Message responseData = QueryResponseToProto.buildMessage(message, executionResult.getData()); return responseData.toByteString(); } catch (DescriptorValidationException | InvalidProtocolBufferException e) { e.printStackTrace(); throw new RuntimeException(e); } }
Example 4
Source File: MessagePayloadSerializerPb.java From stateful-functions with Apache License 2.0 | 5 votes |
@Override public Payload serialize(@Nonnull Object what) { final Message message = (Message) what; final String className = what.getClass().getName(); final ByteString body = message.toByteString(); return Payload.newBuilder().setClassName(className).setPayloadBytes(body).build(); }
Example 5
Source File: MessagePayloadSerializerPb.java From flink-statefun with Apache License 2.0 | 5 votes |
@Override public Payload serialize(@Nonnull Object what) { final Message message = (Message) what; final String className = what.getClass().getName(); final ByteString body = message.toByteString(); return Payload.newBuilder().setClassName(className).setPayloadBytes(body).build(); }