com.google.protobuf.Message.toString()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(285)

本文整理了Java中com.google.protobuf.Message.toString()方法的一些代码示例,展示了Message.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.toString()方法的具体详情如下:
包路径:com.google.protobuf.Message
类名称:Message
方法名:toString

Message.toString介绍

[英]Converts the message to a string in protocol buffer text format. This is just a trivial wrapper around TextFormat#printToString(MessageOrBuilder).
[中]将消息转换为协议缓冲区文本格式的字符串。这只是TextFormat#printToString(MessageOrBuilder)的一个简单包装。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

  1. @Override
  2. public void describeTo(Description description) {
  3. description.appendText(expected.toString());
  4. }
  5. }

代码示例来源:origin: google/truth

  1. static FieldScope createFromSetFields(Message message) {
  2. return create(
  3. FieldScopeLogic.partialScope(message),
  4. Functions.constant(String.format("FieldScopes.fromSetFields({%s})", message.toString())));
  5. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. protected Message callExecService(final RpcController controller,
  3. final Descriptors.MethodDescriptor method, final Message request,
  4. final Message responsePrototype)
  5. throws IOException {
  6. if (LOG.isTraceEnabled()) {
  7. LOG.trace("Call: " + method.getName() + ", " + request.toString());
  8. }
  9. // Try-with-resources so close gets called when we are done.
  10. try (MasterCallable<CoprocessorServiceResponse> callable =
  11. new MasterCallable<CoprocessorServiceResponse>(connection,
  12. connection.getRpcControllerFactory()) {
  13. @Override
  14. protected CoprocessorServiceResponse rpcCall() throws Exception {
  15. CoprocessorServiceRequest csr =
  16. CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
  17. return this.master.execMasterService(getRpcController(), csr);
  18. }
  19. }) {
  20. // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller
  21. callable.prepare(false);
  22. int operationTimeout = connection.getConnectionConfiguration().getOperationTimeout();
  23. CoprocessorServiceResponse result = callable.call(operationTimeout);
  24. return CoprocessorRpcUtils.getResponse(result, responsePrototype);
  25. }
  26. }
  27. };

代码示例来源:origin: apache/hbase

  1. @Override
  2. protected Message callExecService(final RpcController controller,
  3. final Descriptors.MethodDescriptor method, final Message request,
  4. final Message responsePrototype)
  5. throws IOException {
  6. if (LOG.isTraceEnabled()) {
  7. LOG.trace("Call: " + method.getName() + ", " + request.toString());
  8. }
  9. if (row == null) {
  10. throw new NullPointerException("Can't be null!");
  11. }
  12. ClientServiceCallable<CoprocessorServiceResponse> callable =
  13. new ClientServiceCallable<CoprocessorServiceResponse>(this.conn,
  14. this.table, this.row, this.conn.getRpcControllerFactory().newController(), HConstants.PRIORITY_UNSET) {
  15. @Override
  16. protected CoprocessorServiceResponse rpcCall() throws Exception {
  17. byte [] regionName = getLocation().getRegionInfo().getRegionName();
  18. CoprocessorServiceRequest csr =
  19. CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request, row, regionName);
  20. return getStub().execService(getRpcController(), csr);
  21. }
  22. };
  23. CoprocessorServiceResponse result =
  24. this.rpcCallerFactory.<CoprocessorServiceResponse> newCaller().callWithRetries(callable,
  25. operationTimeout);
  26. this.lastRegion = result.getRegion().getValue().toByteArray();
  27. return CoprocessorRpcUtils.getResponse(result, responsePrototype);
  28. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. protected Message callExecService(RpcController controller,
  3. Descriptors.MethodDescriptor method, Message request, Message responsePrototype)
  4. throws IOException {
  5. if (LOG.isTraceEnabled()) {
  6. LOG.trace("Call: " + method.getName() + ", " + request.toString());
  7. }
  8. CoprocessorServiceRequest csr =
  9. CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
  10. // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller
  11. // TODO: Make this same as RegionCoprocessorRpcChannel and MasterCoprocessorRpcChannel. They
  12. // are all different though should do same thing; e.g. RpcChannel setup.
  13. ClientProtos.ClientService.BlockingInterface stub = connection.getClient(serverName);
  14. CoprocessorServiceResponse result;
  15. try {
  16. result = stub.
  17. execRegionServerService(connection.getRpcControllerFactory().newController(), csr);
  18. return CoprocessorRpcUtils.getResponse(result, responsePrototype);
  19. } catch (ServiceException e) {
  20. throw ProtobufUtil.handleRemoteException(e);
  21. }
  22. }
  23. };

代码示例来源:origin: org.apache.hbase/hbase-client

  1. @Override
  2. protected Message callExecService(RpcController controller,
  3. Descriptors.MethodDescriptor method, Message request, Message responsePrototype)
  4. throws IOException {
  5. if (LOG.isTraceEnabled()) {
  6. LOG.trace("Call: " + method.getName() + ", " + request.toString());
  7. }
  8. CoprocessorServiceRequest csr =
  9. CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
  10. // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller
  11. // TODO: Make this same as RegionCoprocessorRpcChannel and MasterCoprocessorRpcChannel. They
  12. // are all different though should do same thing; e.g. RpcChannel setup.
  13. ClientProtos.ClientService.BlockingInterface stub = connection.getClient(serverName);
  14. CoprocessorServiceResponse result;
  15. try {
  16. result = stub.
  17. execRegionServerService(connection.getRpcControllerFactory().newController(), csr);
  18. return CoprocessorRpcUtils.getResponse(result, responsePrototype);
  19. } catch (ServiceException e) {
  20. throw ProtobufUtil.handleRemoteException(e);
  21. }
  22. }
  23. };

代码示例来源:origin: org.apache.hbase/hbase-client

  1. @Override
  2. protected Message callExecService(final RpcController controller,
  3. final Descriptors.MethodDescriptor method, final Message request,
  4. final Message responsePrototype)
  5. throws IOException {
  6. if (LOG.isTraceEnabled()) {
  7. LOG.trace("Call: " + method.getName() + ", " + request.toString());
  8. }
  9. // Try-with-resources so close gets called when we are done.
  10. try (MasterCallable<CoprocessorServiceResponse> callable =
  11. new MasterCallable<CoprocessorServiceResponse>(connection,
  12. connection.getRpcControllerFactory()) {
  13. @Override
  14. protected CoprocessorServiceResponse rpcCall() throws Exception {
  15. CoprocessorServiceRequest csr =
  16. CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
  17. return this.master.execMasterService(getRpcController(), csr);
  18. }
  19. }) {
  20. // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller
  21. callable.prepare(false);
  22. int operationTimeout = connection.getConnectionConfiguration().getOperationTimeout();
  23. CoprocessorServiceResponse result = callable.call(operationTimeout);
  24. return CoprocessorRpcUtils.getResponse(result, responsePrototype);
  25. }
  26. }
  27. };

代码示例来源:origin: org.apache.hbase/hbase-client

  1. @Override
  2. protected Message callExecService(final RpcController controller,
  3. final Descriptors.MethodDescriptor method, final Message request,
  4. final Message responsePrototype)
  5. throws IOException {
  6. if (LOG.isTraceEnabled()) {
  7. LOG.trace("Call: " + method.getName() + ", " + request.toString());
  8. }
  9. if (row == null) {
  10. throw new NullPointerException("Can't be null!");
  11. }
  12. ClientServiceCallable<CoprocessorServiceResponse> callable =
  13. new ClientServiceCallable<CoprocessorServiceResponse>(this.conn,
  14. this.table, this.row, this.conn.getRpcControllerFactory().newController(), HConstants.PRIORITY_UNSET) {
  15. @Override
  16. protected CoprocessorServiceResponse rpcCall() throws Exception {
  17. byte [] regionName = getLocation().getRegionInfo().getRegionName();
  18. CoprocessorServiceRequest csr =
  19. CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request, row, regionName);
  20. return getStub().execService(getRpcController(), csr);
  21. }
  22. };
  23. CoprocessorServiceResponse result =
  24. this.rpcCallerFactory.<CoprocessorServiceResponse> newCaller().callWithRetries(callable,
  25. operationTimeout);
  26. this.lastRegion = result.getRegion().getValue().toByteArray();
  27. return CoprocessorRpcUtils.getResponse(result, responsePrototype);
  28. }

代码示例来源:origin: google/closure-templates

  1. @Override
  2. public String coerceToString() {
  3. // TODO(gboyer): Make this consistent with Javascript or AbstractMap.
  4. // TODO(gboyer): Respect ProtoUtils.shouldJsIgnoreField(...)?
  5. return proto.toString();
  6. }

代码示例来源:origin: apache/tajo

  1. @Override
  2. public String toString() {
  3. return value.toString();
  4. }
  5. }

代码示例来源:origin: com.google.template/soy

  1. @Override
  2. public String coerceToString() {
  3. // TODO(gboyer): Make this consistent with Javascript or AbstractMap.
  4. // TODO(gboyer): Respect ProtoUtils.shouldJsIgnoreField(...)?
  5. return proto.toString();
  6. }

代码示例来源:origin: org.apache.tajo/tajo-common

  1. @Override
  2. public String toString() {
  3. return value.toString();
  4. }
  5. }

代码示例来源:origin: kubernetes-client/java

  1. public String toString() {
  2. if (object != null) {
  3. return object.toString();
  4. }
  5. return status.toString();
  6. }
  7. }

代码示例来源:origin: io.kubernetes/client-java

  1. public String toString() {
  2. if (object != null) {
  3. return object.toString();
  4. }
  5. return status.toString();
  6. }
  7. }

代码示例来源:origin: com.hubspot.jackson/jackson-datatype-protobuf

  1. @Override
  2. public void serialize(Message value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
  3. jgen.writeStartObject();
  4. jgen.writeStringField("toString", value.toString());
  5. jgen.writeEndObject();
  6. }
  7. });

代码示例来源:origin: com.google.truth.extensions/truth-proto-extension

  1. static FieldScope createFromSetFields(Message message) {
  2. return create(
  3. FieldScopeLogic.partialScope(message),
  4. Functions.constant(String.format("FieldScopes.fromSetFields({%s})", message.toString())));
  5. }

代码示例来源:origin: com.aliyun.hbase/alihbase-client

  1. @Override
  2. protected Message callExecService(RpcController controller,
  3. Descriptors.MethodDescriptor method, Message request, Message responsePrototype)
  4. throws IOException {
  5. if (LOG.isTraceEnabled()) {
  6. LOG.trace("Call: " + method.getName() + ", " + request.toString());
  7. }
  8. CoprocessorServiceRequest csr =
  9. CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
  10. // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller
  11. // TODO: Make this same as RegionCoprocessorRpcChannel and MasterCoprocessorRpcChannel. They
  12. // are all different though should do same thing; e.g. RpcChannel setup.
  13. ClientProtos.ClientService.BlockingInterface stub = connection.getClient(serverName);
  14. CoprocessorServiceResponse result;
  15. try {
  16. result = stub.
  17. execRegionServerService(connection.getRpcControllerFactory().newController(), csr);
  18. return CoprocessorRpcUtils.getResponse(result, responsePrototype);
  19. } catch (ServiceException e) {
  20. throw ProtobufUtil.handleRemoteException(e);
  21. }
  22. }
  23. };

代码示例来源:origin: com.aliyun.openservices/tablestore

  1. @Override
  2. public Object getObject(ResponseMessage response)
  3. throws ResultParseException {
  4. Map<String, String> headers = response.getHeadersMap();
  5. String requestId = headers.get(Constants.OTS_HEADER_REQUEST_ID);
  6. if (requestId == null){
  7. throw new ClientException("The required header is missing: " + Constants.OTS_HEADER_REQUEST_ID);
  8. }
  9. try {
  10. Message result = message.newBuilderForType().mergeFrom(response.getContent()).buildPartial();
  11. if (!result.isInitialized()) {
  12. throw new UninitializedMessageException(
  13. result).asInvalidProtocolBufferException();
  14. }
  15. if (logger.isDebugEnabled()) {
  16. logger.debug("PBResponseMessage: {}, RequestId: {}, TraceId: {}", result.toString(), requestId, traceId);
  17. }
  18. return new ResponseContentWithMeta(
  19. result,
  20. new Response(requestId));
  21. } catch(Exception e) {
  22. throw new ResultParseException("Failed to parse response as protocol buffer message.", e);
  23. }
  24. }

代码示例来源:origin: FoundationDB/fdb-record-layer

  1. @Test
  2. public void asyncUniqueInserts() throws Exception {
  3. List<TestRecords1Proto.MySimpleRecord> records = new ArrayList<>();
  4. Random r = new Random(0xdeadc0deL);
  5. for (int i = 0; i < 100; i++) {
  6. records.add(TestRecords1Proto.MySimpleRecord.newBuilder()
  7. .setRecNo(r.nextLong())
  8. .setNumValueUnique(r.nextInt())
  9. .build()
  10. );
  11. }
  12. try (FDBRecordContext context = openContext()) {
  13. openSimpleRecordStore(context);
  14. CompletableFuture<?>[] futures = new CompletableFuture<?>[records.size()];
  15. for (int i = 0; i < records.size(); i++) {
  16. futures[i] = recordStore.saveRecordAsync(records.get(i));
  17. }
  18. CompletableFuture.allOf(futures).get();
  19. commit(context);
  20. }
  21. try (FDBRecordContext context = openContext()) {
  22. openSimpleRecordStore(context);
  23. for (TestRecords1Proto.MySimpleRecord record : records) {
  24. assertEquals(record.toString(), recordStore.loadRecord(Tuple.from(record.getRecNo())).getRecord().toString());
  25. }
  26. }
  27. }

代码示例来源:origin: org.openbase.bco/dal.lib

  1. String serviceAttributeRepresentation = StringProcessor.formatHumanReadable(serviceAttribute.toBuilder().clearField(ProtoBufFieldProcessor.getFieldDescriptor(serviceAttribute, Service.RESPONSIBLE_ACTION_FIELD_NAME)).build().toString());
  2. description = description.replace(ActionDescriptionProcessor.SERVICE_ATTIBUTE_KEY, serviceAttributeRepresentation);
  3. actionDescription.setLabel(actionDescription.getLabel().replace(ActionDescriptionProcessor.SERVICE_ATTIBUTE_KEY, serviceAttributeRepresentation));

相关文章