com.google.protobuf.Message Java Examples
The following examples show how to use
com.google.protobuf.Message.
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: TransformedRecordSerializerTest.java From fdb-record-layer with Apache License 2.0 | 6 votes |
@Test public void encryptWhenSerializing() throws Exception { KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(128); SecretKey key = keyGen.generateKey(); TransformedRecordSerializer<Message> serializer = TransformedRecordSerializerJCE.newDefaultBuilder() .setEncryptWhenSerializing(true) .setEncryptionKey(key) .build(); MySimpleRecord mediumRecord = MySimpleRecord.newBuilder().setRecNo(1066L).setStrValueIndexed(SONNET_108).build(); assertTrue(Bytes.indexOf(mediumRecord.toByteArray(), "brain".getBytes()) >= 0, "should contain clear text"); byte[] serialized = serialize(serializer, mediumRecord); assertEquals(TransformedRecordSerializer.ENCODING_ENCRYPTED, serialized[0]); assertFalse(Bytes.indexOf(serialized, "brain".getBytes()) >= 0, "should not contain clear text"); Message deserialized = deserialize(serializer, Tuple.from(1066L), serialized); assertEquals(mediumRecord, deserialized); }
Example #2
Source File: ProtoLanguageFileWriter.java From metastore with Apache License 2.0 | 6 votes |
private void writeOptionForList( Descriptors.FieldDescriptor fieldDescriptor, Object value, int indent, String optionType) { if (fieldDescriptor.getFullName().startsWith("google.protobuf." + optionType + "Options")) { writer.print(fieldDescriptor.getName()); } else { writer.print("("); writer.print(fieldDescriptor.getFullName()); writer.print(")"); } writer.print(" = "); if (fieldDescriptor.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) { writeMessageValue((Message) value, indent + 1); } else { writeValue(fieldDescriptor, value); } }
Example #3
Source File: CheckpointManagerServerTest.java From incubator-heron with Apache License 2.0 | 6 votes |
@Test public void testSaveInstanceState() throws Exception { runTest(TestRequestHandler.RequestType.SAVE_INSTANCE_STATE, new HeronServerTester.SuccessResponseHandler( CheckpointManager.SaveInstanceStateResponse.class, new HeronServerTester.TestResponseHandler() { @Override public void handleResponse(HeronClient client, StatusCode status, Object ctx, Message response) throws Exception { verify(statefulStorage).storeCheckpoint( any(CheckpointInfo.class), any(Checkpoint.class)); assertEquals(CHECKPOINT_ID, ((CheckpointManager.SaveInstanceStateResponse) response).getCheckpointId()); assertEquals(instance, ((CheckpointManager.SaveInstanceStateResponse) response).getInstance()); } }) ); }
Example #4
Source File: GeophileSpatialFunctionKeyExpression.java From fdb-record-layer with Apache License 2.0 | 6 votes |
@Nonnull @Override public <M extends Message> List<Key.Evaluated> evaluateFunction(@Nullable FDBRecord<M> record, @Nullable Message message, @Nonnull Key.Evaluated arguments) { SpatialObject spatialObject; try { spatialObject = parseSpatialObject(arguments); } catch (ParseException ex) { throw new RecordCoreException(ex); } if (spatialObject == null) { return Collections.singletonList(Key.Evaluated.NULL); } long[] zs = new long[spatialObject.maxZ()]; GeophileSpatial.shuffle(space, spatialObject, zs); List<Key.Evaluated> result = new ArrayList<>(zs.length); for (long z : zs) { if (z == Space.Z_NULL) { break; } result.add(Key.Evaluated.scalar(z)); } return result; }
Example #5
Source File: ProtoInputOutputFormatTest.java From parquet-mr with Apache License 2.0 | 6 votes |
@Test public void testProto3CustomProtoClass() throws Exception { TestProto3.FirstCustomClassMessage.Builder inputMessage; inputMessage = TestProto3.FirstCustomClassMessage.newBuilder(); inputMessage.setString("writtenString"); Path outputPath = new WriteUsingMR().write(new Message[]{inputMessage.build()}); ReadUsingMR readUsingMR = new ReadUsingMR(); String customClass = TestProto3.SecondCustomClassMessage.class.getName(); ProtoReadSupport.setProtobufClass(readUsingMR.getConfiguration(), customClass); List<Message> result = readUsingMR.read(outputPath); assertEquals(1, result.size()); Message msg = result.get(0); assertFalse("Class from header returned.", msg instanceof TestProto3.FirstCustomClassMessage); assertTrue("Custom class was not used", msg instanceof TestProto3.SecondCustomClassMessage); String stringValue; stringValue = ((TestProto3.SecondCustomClassMessage) msg).getString(); assertEquals("writtenString", stringValue); }
Example #6
Source File: ProtobufJsonFormatHttpMessageConverterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void write() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MediaType contentType = ProtobufHttpMessageConverter.PROTOBUF; this.converter.write(this.testMsg, contentType, outputMessage); assertEquals(contentType, outputMessage.getHeaders().getContentType()); assertTrue(outputMessage.getBodyAsBytes().length > 0); Message result = Msg.parseFrom(outputMessage.getBodyAsBytes()); assertEquals(this.testMsg, result); String messageHeader = outputMessage.getHeaders().getFirst(ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER); assertEquals("Msg", messageHeader); String schemaHeader = outputMessage.getHeaders().getFirst(ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER); assertEquals("sample.proto", schemaHeader); }
Example #7
Source File: ProtoInputOutputFormatTest.java From parquet-mr with Apache License 2.0 | 6 votes |
@Test public void testProto3RepeatedInnerMessageClass() throws Exception { TestProto3.RepeatedInnerMessage msgEmpty = TestProto3.RepeatedInnerMessage.newBuilder().build(); TestProto3.RepeatedInnerMessage msgNonEmpty = TestProto3.RepeatedInnerMessage.newBuilder() .addRepeatedInnerMessage(TestProto3.InnerMessage.newBuilder().setOne("one").build()) .addRepeatedInnerMessage(TestProto3.InnerMessage.newBuilder().setTwo("two").build()) .build(); Path outputPath = new WriteUsingMR().write(msgEmpty, msgNonEmpty); ReadUsingMR readUsingMR = new ReadUsingMR(); String customClass = TestProto3.RepeatedInnerMessage.class.getName(); ProtoReadSupport.setProtobufClass(readUsingMR.getConfiguration(), customClass); List<Message> result = readUsingMR.read(outputPath); assertEquals(2, result.size()); assertEquals(msgEmpty, result.get(0)); assertEquals(msgNonEmpty, result.get(1)); }
Example #8
Source File: ProtoInputOutputFormatTest.java From parquet-mr with Apache License 2.0 | 6 votes |
@Test public void testProto3RepeatedIntMessageClassSchemaCompliant() throws Exception { TestProto3.RepeatedIntMessage msgEmpty = TestProto3.RepeatedIntMessage.newBuilder().build(); TestProto3.RepeatedIntMessage msgNonEmpty = TestProto3.RepeatedIntMessage.newBuilder() .addRepeatedInt(1).addRepeatedInt(2) .build(); Configuration conf = new Configuration(); ProtoWriteSupport.setWriteSpecsCompliant(conf, true); Path outputPath = new WriteUsingMR(conf).write(msgEmpty, msgNonEmpty); ReadUsingMR readUsingMR = new ReadUsingMR(); String customClass = TestProto3.RepeatedIntMessage.class.getName(); ProtoReadSupport.setProtobufClass(readUsingMR.getConfiguration(), customClass); List<Message> result = readUsingMR.read(outputPath); assertEquals(2, result.size()); assertEquals(msgEmpty, result.get(0)); assertEquals(msgNonEmpty, result.get(1)); }
Example #9
Source File: RpcFutureUtils.java From krpc with Apache License 2.0 | 6 votes |
public void accept(T m) { try { if( closure != null ) { closure.restoreContext(); } action.accept(m); } catch (Throwable e) { String traceId = "no_trace_id"; if( Trace.currentContext() != null && Trace.currentContext().getTrace() != null ) traceId = Trace.currentContext().getTrace().getTraceId(); log.error("accept exception, traceId="+traceId, e); if( closure != null ) { Message bizErrorMsg = createBizErrorMessage(closure); if( bizErrorMsg != null ) { closure.done(bizErrorMsg); } } throw e; } }
Example #10
Source File: ProtoInputOutputFormatTest.java From parquet-mr with Apache License 2.0 | 6 votes |
@Test public void testProto3MapIntMessageClassSchemaCompliant() throws Exception { TestProto3.MapIntMessage msgEmpty = TestProto3.MapIntMessage.newBuilder().build(); TestProto3.MapIntMessage msgNonEmpty = TestProto3.MapIntMessage.newBuilder() .putMapInt(1, 123).putMapInt(2, 234) .build(); Configuration conf = new Configuration(); ProtoWriteSupport.setWriteSpecsCompliant(conf, true); Path outputPath = new WriteUsingMR(conf).write(msgEmpty, msgNonEmpty); ReadUsingMR readUsingMR = new ReadUsingMR(conf); String customClass = TestProto3.MapIntMessage.class.getName(); ProtoReadSupport.setProtobufClass(readUsingMR.getConfiguration(), customClass); List<Message> result = readUsingMR.read(outputPath); assertEquals(2, result.size()); assertEquals(msgEmpty, result.get(0)); assertEquals(msgNonEmpty, result.get(1)); }
Example #11
Source File: ProtobufQueryHandler.java From fuchsia with Apache License 2.0 | 6 votes |
/** * @see org.apache.cxf.transports.http.QueryHandler#writeResponse(String,. * String, org.apache.cxf.service.model.EndpointInfo, * java.io.OutputStream) */ @SuppressWarnings("unchecked") public void writeResponse(String fullQueryString, String ctx, EndpointInfo endpoint, OutputStream os) { try { Class<? extends Message> messageClass = endpoint.getProperty( ProtobufServerFactoryBean.PROTOBUF_MESSAGE_CLASS, Class.class); PrintStream out = new PrintStream(os); Descriptor wrapperMessage = ((Descriptor) messageClass.getMethod( "getDescriptor").invoke(null)); new ProtoGenerator().generateProtoFromDescriptor(wrapperMessage .getFile(), out, wrapperMessage); out.flush(); } catch (Exception x) { throw new RuntimeException(x); } }
Example #12
Source File: OutgoingTupleCollection.java From incubator-heron with Apache License 2.0 | 6 votes |
public OutgoingTupleCollection( PhysicalPlanHelper helper, Communicator<Message> outQueue, ReentrantLock lock, ComponentMetrics metrics) { this.outQueue = outQueue; this.helper = helper; this.metrics = metrics; SystemConfig systemConfig = (SystemConfig) SingletonRegistry.INSTANCE.getSingleton(SystemConfig.HERON_SYSTEM_CONFIG); this.serializer = SerializeDeSerializeHelper.getSerializer(helper.getTopologyContext().getTopologyConfig()); // Initialize the values in constructor this.totalDataEmittedInBytes.set(0); this.currentDataTupleSizeInBytes = 0; // Read the config values this.dataTupleSetCapacity = systemConfig.getInstanceSetDataTupleCapacity(); this.maxDataTupleSize = systemConfig.getInstanceSetDataTupleSize(); this.controlTupleSetCapacity = systemConfig.getInstanceSetControlTupleCapacity(); this.lock = lock; }
Example #13
Source File: RRServer.java From twister2 with Apache License 2.0 | 6 votes |
protected TCPMessage sendMessage(Message message, RequestID requestID, SocketChannel channel) { byte[] data = message.toByteArray(); String messageType = message.getDescriptorForType().getFullName(); // lets serialize the message int capacity = requestID.getId().length + data.length + messageType.getBytes().length + 8; ByteBuffer buffer = ByteBuffer.allocate(capacity); // we send message id, worker id and data buffer.put(requestID.getId()); // pack the name of the message ByteUtils.packString(messageType, buffer); // pack the worker id buffer.putInt(serverID); // pack data buffer.put(data); TCPMessage send = server.send(channel, buffer, capacity, 0); if (send != null) { pendingSendCount++; } return send; }
Example #14
Source File: RpcCallableBase.java From krpc with Apache License 2.0 | 5 votes |
void endCall(RpcClosure closure, Object res) { List<RpcPlugin> calledPlugins = (List<RpcPlugin>) closure.getCtx().getAttribute("calledClientPlugins"); if (calledPlugins != null && !closure.isRaw() ) { for (RpcPlugin p : calledPlugins) { p.postCall(closure.getCtx(), closure.asReqMessage(), closure.asResMessage()); } } if(!closure.isRaw()) closure.done((Message)res); else closure.done((RpcRawMessage)res); ClientContextData ctx = closure.asClientCtx(); ctx.getFuture().complete(res); RpcRetryTask retryTask = (RpcRetryTask) closure.getCtx().getAttribute("retryTask"); if (retryTask != null && !closure.isRaw() ) { rpcRetrier.submit(closure.getRetCode(),retryTask); } String status = closure.getRetCode() == 0 ? "SUCCESS" : "ERROR"; long timeUsedMicros = ctx.getTimeUsedMicros(); ctx.getSpan().stopWithTime(status,timeUsedMicros); if (monitorService != null) { monitorService.callDone(closure); } }
Example #15
Source File: HtmlFormat.java From jigsaw-payment with Apache License 2.0 | 5 votes |
private void printTitle(final Message message, final HtmlGenerator generator) throws IOException { generator.print("<html><head>"); generator.print(META_CONTENT); generator.print("<title>"); generator.print(message.getDescriptorForType().getFullName()); generator.print("</title></head><body>"); generator.print("<div style=\""); generator.print(MAIN_DIV_STYLE); generator.print("\">message : "); generator.print(message.getDescriptorForType().getFullName()); generator.print("</div>"); }
Example #16
Source File: CryptoCurrencyAccountPayload.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
@Override public Message toProtoMessage() { return getPaymentAccountPayloadBuilder() .setCryptoCurrencyAccountPayload(protobuf.CryptoCurrencyAccountPayload.newBuilder() .setAddress(address)) .build(); }
Example #17
Source File: RequestVoteRequestProcessor.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Override public Message processRequest0(final RaftServerService service, final RequestVoteRequest request, final RpcRequestClosure done) { if (request.getPreVote()) { return service.handlePreVoteRequest(request); } else { return service.handleRequestVoteRequest(request); } }
Example #18
Source File: SimpleRpcChannel.java From fuchsia with Apache License 2.0 | 5 votes |
/** * @param messageSender * @param wrapperMessage * @throws org.apache.cxf.endpoint.EndpointException */ public SimpleRpcChannel(String address, Class<? extends Message> wrapperMessage) throws EndpointException { this.messageSender = new ProtobufClient(address, wrapperMessage); this.wrapperMessage = wrapperMessage; initialize(); }
Example #19
Source File: Service.java From calcite-avatica with Apache License 2.0 | 5 votes |
@Override CloseConnectionResponse deserialize(Message genericMsg) { final Responses.CloseConnectionResponse msg = ProtobufService.castProtobufMessage(genericMsg, Responses.CloseConnectionResponse.class); RpcMetadataResponse metadata = null; if (msg.hasField(METADATA_DESCRIPTOR)) { metadata = RpcMetadataResponse.fromProto(msg.getMetadata()); } return new CloseConnectionResponse(metadata); }
Example #20
Source File: MetricsManagerServer.java From incubator-heron with Apache License 2.0 | 5 votes |
@Override public void onRequest(REQID rid, SocketChannel channel, Message request) { if (request instanceof Metrics.MetricPublisherRegisterRequest) { handleRegisterRequest(rid, channel, (Metrics.MetricPublisherRegisterRequest) request); } else { LOG.severe("Unknown kind of request received from Metrics Manager"); } }
Example #21
Source File: CollateFunctionKeyExpression.java From fdb-record-layer with Apache License 2.0 | 5 votes |
@Nonnull @Override public <M extends Message> List<Key.Evaluated> evaluateFunction(@Nullable FDBRecord<M> record, @Nullable Message message, @Nonnull Key.Evaluated arguments) { final String value = arguments.getString(0); if (value == null) { return Collections.singletonList(Key.Evaluated.NULL); } final TextCollator textCollator = getTextCollator(arguments); return Collections.singletonList(Key.Evaluated.scalar(textCollator.getKey(value))); }
Example #22
Source File: Converter.java From protobuf-converter with MIT License | 5 votes |
@SuppressWarnings("unchecked") private <T, E extends Message, K extends Collection> K toProtobuf(final Class<K> collectionClass, final Class<E> protobufClass, final Collection<T> domainCollection) { Collection<E> protobufCollection = List.class.isAssignableFrom(collectionClass) ? new ArrayList<E>() : new HashSet<E>(); if (domainCollection != null) { for (T domain : domainCollection) { protobufCollection.add(toProtobuf(protobufClass, domain)); } } return (K) protobufCollection; }
Example #23
Source File: Service.java From calcite-avatica with Apache License 2.0 | 5 votes |
SyncResultsResponse deserialize(Message genericMsg) { final Responses.SyncResultsResponse msg = ProtobufService.castProtobufMessage(genericMsg, Responses.SyncResultsResponse.class); RpcMetadataResponse metadata = null; if (msg.hasField(METADATA_DESCRIPTOR)) { metadata = RpcMetadataResponse.fromProto(msg.getMetadata()); } return new SyncResultsResponse(msg.getMoreResults(), msg.getMissingStatement(), metadata); }
Example #24
Source File: ProtoFieldInfo.java From curiostack with MIT License | 5 votes |
/** * Return the Java {@link Class} that corresponds to the value of this field. Generally used for * method resolution and casting generics. */ Class<?> javaClass() { if (isMapField() && valueJavaType() == JavaType.MESSAGE) { Message mapEntry = containingPrototype.newBuilderForType().newBuilderForField(field).build(); return mapEntry.getField(mapEntry.getDescriptorForType().findFieldByName("value")).getClass(); } switch (valueJavaType()) { case INT: return int.class; case LONG: return long.class; case FLOAT: return float.class; case DOUBLE: return double.class; case BOOLEAN: return boolean.class; case STRING: return String.class; case BYTE_STRING: return ByteString.class; case ENUM: return int.class; case MESSAGE: return containingPrototype .newBuilderForType() .newBuilderForField(valueField().descriptor()) .build() .getClass(); default: throw new IllegalArgumentException("Unknown field type: " + valueJavaType()); } }
Example #25
Source File: SnapshotExecutorTest.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Test public void testInterruptInstallaling() throws Exception { final RpcRequests.InstallSnapshotRequest.Builder irb = RpcRequests.InstallSnapshotRequest.newBuilder(); irb.setGroupId("test"); irb.setPeerId(this.addr.toString()); irb.setServerId("localhost:8080"); irb.setUri("remote://localhost:8080/99"); irb.setTerm(0); irb.setMeta(RaftOutter.SnapshotMeta.newBuilder().setLastIncludedIndex(1).setLastIncludedTerm(1)); Mockito.when(this.raftClientService.connect(new Endpoint("localhost", 8080))).thenReturn(true); final FutureImpl<Message> future = new FutureImpl<>(); final RpcRequests.GetFileRequest.Builder rb = RpcRequests.GetFileRequest.newBuilder().setReaderId(99) .setFilename(Snapshot.JRAFT_SNAPSHOT_META_FILE).setCount(Integer.MAX_VALUE).setOffset(0) .setReadPartly(true); //mock get metadata final ArgumentCaptor<RpcResponseClosure> argument = ArgumentCaptor.forClass(RpcResponseClosure.class); Mockito.when( this.raftClientService.getFile(eq(new Endpoint("localhost", 8080)), eq(rb.build()), eq(this.copyOpts.getTimeoutMs()), argument.capture())).thenReturn(future); Utils.runInThread(new Runnable() { @Override public void run() { SnapshotExecutorTest.this.executor.installSnapshot(irb.build(), RpcRequests.InstallSnapshotResponse .newBuilder(), new RpcRequestClosure(SnapshotExecutorTest.this.asyncCtx)); } }); this.executor.interruptDownloadingSnapshots(1); this.executor.join(); assertEquals(0, this.executor.getLastSnapshotTerm()); assertEquals(0, this.executor.getLastSnapshotIndex()); }
Example #26
Source File: InteracETransferAccountPayload.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
@Override public Message toProtoMessage() { return getPaymentAccountPayloadBuilder() .setInteracETransferAccountPayload(protobuf.InteracETransferAccountPayload.newBuilder() .setEmail(email) .setHolderName(holderName) .setQuestion(question) .setAnswer(answer)) .build(); }
Example #27
Source File: TestUtils.java From parquet-mr with Apache License 2.0 | 5 votes |
public static List<Message> asMessages(List<MessageOrBuilder> mobs) { List<Message> result = new ArrayList<Message>(); for (MessageOrBuilder messageOrBuilder : mobs) { result.add(asMessage(messageOrBuilder)); } return result; }
Example #28
Source File: FDBSortQueryIndexSelectionTest.java From fdb-record-layer with Apache License 2.0 | 5 votes |
/** * Verify that reverse sorts can be implemented by a reverse index scan. */ @DualPlannerTest public void testComplexLimits1() throws Exception { RecordMetaDataHook hook = complexQuerySetupHook(); complexQuerySetup(hook); RecordQuery query = RecordQuery.newBuilder() .setRecordType("MySimpleRecord") .setSort(field("str_value_indexed"), true) .build(); RecordQueryPlan plan = planner.plan(query); assertThat(plan, indexScan(allOf(indexName("MySimpleRecord$str_value_indexed"), unbounded()))); assertTrue(plan.isReverse(), "plan is reversed"); assertEquals(324762955, plan.planHash()); try (FDBRecordContext context = openContext()) { openSimpleRecordStore(context, hook); int i = 0; try (RecordCursorIterator<FDBQueriedRecord<Message>> cursor = recordStore.executeQuery(plan, null, ExecuteProperties.newBuilder().setReturnedRowLimit(10).build()).asIterator()) { while (cursor.hasNext()) { FDBQueriedRecord<Message> rec = cursor.next(); TestRecords1Proto.MySimpleRecord.Builder myrec = TestRecords1Proto.MySimpleRecord.newBuilder(); myrec.mergeFrom(rec.getRecord()); assertEquals("odd", myrec.getStrValueIndexed()); i += 1; } } assertEquals(10, i); assertDiscardedNone(context); } }
Example #29
Source File: ProtobufRpcMethodInfo.java From brpc-java with Apache License 2.0 | 5 votes |
@Override public byte[] inputEncode(Object input) throws IOException { if (input instanceof Message) { return ((Message) input).toByteArray(); } return null; }
Example #30
Source File: WellKnownTypeMarshaller.java From curiostack with MIT License | 5 votes |
@Override public void doMerge(JsonParser parser, int unused, Message.Builder messageBuilder) throws IOException { Duration.Builder builder = (Duration.Builder) messageBuilder; try { builder.mergeFrom(Durations.parse(ParseSupport.parseString(parser))); } catch (ParseException e) { throw new InvalidProtocolBufferException( "Failed to readValue duration: " + parser.getText()); } }