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

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

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

Message.getDescriptorForType介绍

暂无

代码示例

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

/** Compare the two non-null messages, and return a detailed comparison report. */
DiffResult diffMessages(Message actual, Message expected) {
 checkNotNull(actual);
 checkNotNull(expected);
 checkArgument(
   actual.getDescriptorForType() == expected.getDescriptorForType(),
   "The actual [%s] and expected [%s] message descriptors do not match.",
   actual.getDescriptorForType(),
   expected.getDescriptorForType());
 return diffMessages(actual, expected, rootConfig);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the "X-Protobuf-*" HTTP headers when responding with a message of
 * content type "application/x-protobuf"
 * <p><b>Note:</b> <code>outputMessage.getBody()</code> should not have been called
 * before because it writes HTTP headers (making them read only).</p>
 */
private void setProtoHeader(HttpOutputMessage response, Message message) {
  response.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName());
  response.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName());
}

代码示例来源:origin: SonarSource/sonarqube

static MessageType of(Message message) {
  MessageType type = TYPES_BY_CLASS.get(message.getClass());
  if (type == null) {
   type = new MessageType(message.getDescriptorForType());
   TYPES_BY_CLASS.put(message.getClass(), type);
  }
  return type;
 }
}

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

private static Iterable<String> getDescriptors(Iterable<? extends Message> messages) {
 List<String> descriptors = Lists.newArrayList();
 for (Message message : messages) {
  descriptors.add(message == null ? "null" : message.getDescriptorForType().getFullName());
 }
 return descriptors;
}

代码示例来源:origin: osmandapp/Osmand

public FieldDescriptor getDescriptor() {
  return scope.getDescriptorForType().getExtensions()
    .get(descriptorIndex);
 }
},

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

private static boolean notMessagesWithSameDescriptor(
  @NullableDecl Message actual, @NullableDecl Object expected) {
 if (actual != null && expected instanceof Message) {
  return actual.getDescriptorForType() != ((Message) expected).getDescriptorForType();
 }
 return true;
}

代码示例来源:origin: com.google.protobuf/protobuf-java

@Override
 protected FieldDescriptor loadDescriptor() {
  return scope.getDescriptorForType().findFieldByName(name);
 }
},

代码示例来源:origin: com.google.protobuf/protobuf-java

@Override
 public FieldDescriptor loadDescriptor() {
  return scope.getDescriptorForType().getExtensions().get(descriptorIndex);
 }
},

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

RootPartialScopeLogic(Message message) {
 super(FieldNumberTree.fromMessage(message));
 this.message = message;
 this.expectedDescriptor = message.getDescriptorForType();
}

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

@Override
protected Schema getRecordSchema(Object record) {
 Descriptor descriptor = ((Message)record).getDescriptorForType();
 Schema schema = schemaCache.get(descriptor);
 if (schema == null) {
  schema = getSchema(descriptor);
  schemaCache.put(descriptor, schema);
 }
 return schema;
}

代码示例来源:origin: org.springframework/spring-web

/**
 * Set the "X-Protobuf-*" HTTP headers when responding with a message of
 * content type "application/x-protobuf"
 * <p><b>Note:</b> <code>outputMessage.getBody()</code> should not have been called
 * before because it writes HTTP headers (making them read only).</p>
 */
private void setProtoHeader(HttpOutputMessage response, Message message) {
  response.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName());
  response.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName());
}

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Construct a {@link Message.Builder} for a message of the same type as
 * {@code prototype}, and initialize it with {@code prototype}'s contents.
 */
public static Builder newBuilder(Message prototype) {
 return new Builder(prototype.getDescriptorForType()).mergeFrom(prototype);
}

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

private static Map<Object, Object> toProtoMap(@NullableDecl Object container) {
 if (container == null) {
  return Collections.emptyMap();
 }
 List<?> entryMessages = (List<?>) container;
 Map<Object, Object> retVal = Maps.newHashMap();
 for (Object entry : entryMessages) {
  Message message = (Message) entry;
  Object key = message.getAllFields().get(message.getDescriptorForType().findFieldByNumber(1));
  Object value =
    message.getAllFields().get(message.getDescriptorForType().findFieldByNumber(2));
  retVal.put(key, value);
 }
 return retVal;
}

代码示例来源:origin: osmandapp/Osmand

/**
 * Construct a {@link Message.Builder} for a message of the same type as
 * {@code prototype}, and initialize it with {@code prototype}'s contents.
 */
public static Builder newBuilder(Message prototype) {
 return new Builder(prototype.getDescriptorForType()).mergeFrom(prototype);
}

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

private ProtoTruthMessageDifferencer makeDifferencer(Message expected) {
 return config
   .withExpectedMessages(Arrays.asList(expected))
   .toMessageDifferencer(actual().getDescriptorForType());
}

代码示例来源:origin: com.google.protobuf/protobuf-java

public <T extends com.google.protobuf.Message> boolean is(
  java.lang.Class<T> clazz) {
 T defaultInstance =
   com.google.protobuf.Internal.getDefaultInstance(clazz);
 return getTypeNameFromTypeUrl(getTypeUrl()).equals(
   defaultInstance.getDescriptorForType().getFullName());
}

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

@Override
public final String formatDiff(@NullableDecl M actual, @NullableDecl M expected) {
 if (actual == null || expected == null) {
  return "";
 }
 return FluentEqualityConfig.this
   .toMessageDifferencer(actual.getDescriptorForType())
   .diffMessages(actual, expected)
   .printToString(FluentEqualityConfig.this.reportMismatchesOnly());
}

代码示例来源:origin: com.google.protobuf/protobuf-java

public static <T extends com.google.protobuf.Message> Any pack(
  T message) {
 return Any.newBuilder()
   .setTypeUrl(getTypeUrl("type.googleapis.com",
               message.getDescriptorForType()))
   .setValue(message.toByteString())
   .build();
}

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Packs a message using the given type URL prefix. The type URL will
 * be constructed by concatenating the message type's full name to the
 * prefix with an optional "/" separator if the prefix doesn't end
 * with "/" already.
 */
public static <T extends com.google.protobuf.Message> Any pack(
  T message, java.lang.String typeUrlPrefix) {
 return Any.newBuilder()
   .setTypeUrl(getTypeUrl(typeUrlPrefix,
               message.getDescriptorForType()))
   .setValue(message.toByteString())
   .build();
}

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

static Any toAny(Message message) {
 return Any.newBuilder()
   .setTypeUrl("type.googleapis.com/" + message.getDescriptorForType().getFullName())
   .setValue(message.toByteString())
   .build();
}

相关文章