本文整理了Java中com.google.protobuf.Internal.getDefaultInstance()
方法的一些代码示例,展示了Internal.getDefaultInstance()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Internal.getDefaultInstance()
方法的具体详情如下:
包路径:com.google.protobuf.Internal
类名称:Internal
方法名:getDefaultInstance
暂无
代码示例来源:origin: com.google.protobuf/protobuf-java
@java.lang.SuppressWarnings("unchecked")
public <T extends com.google.protobuf.Message> T unpack(
java.lang.Class<T> clazz)
throws com.google.protobuf.InvalidProtocolBufferException {
if (!is(clazz)) {
throw new com.google.protobuf.InvalidProtocolBufferException(
"Type of the Any message does not match the given class.");
}
if (cachedUnpackValue != null) {
return (T) cachedUnpackValue;
}
T defaultInstance =
com.google.protobuf.Internal.getDefaultInstance(clazz);
T result = (T) defaultInstance.getParserForType()
.parseFrom(getValue());
cachedUnpackValue = result;
return result;
}
public static final int TYPE_URL_FIELD_NUMBER = 1;
代码示例来源: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: com.google.protobuf/protobuf-java
/**
* Parse a text-format message from {@code input}.
*
* @return the parsed message, guaranteed initialized
*/
public static <T extends Message> T parse(final CharSequence input,
final Class<T> protoClass)
throws ParseException {
Message.Builder builder =
Internal.getDefaultInstance(protoClass).newBuilderForType();
merge(input, builder);
@SuppressWarnings("unchecked")
T output = (T) builder.build();
return output;
}
代码示例来源:origin: com.google.protobuf/protobuf-java
/**
* Parse a text-format message from {@code input}. Extensions will be
* recognized if they are registered in {@code extensionRegistry}.
*
* @return the parsed message, guaranteed initialized
*/
public static <T extends Message> T parse(
final CharSequence input,
final ExtensionRegistry extensionRegistry,
final Class<T> protoClass)
throws ParseException {
Message.Builder builder =
Internal.getDefaultInstance(protoClass).newBuilderForType();
merge(input, extensionRegistry, builder);
@SuppressWarnings("unchecked")
T output = (T) builder.build();
return output;
}
代码示例来源:origin: com.google.protobuf/protobuf-java-util
/**
* Checks whether a given field path is valid.
*/
public static boolean isValid(Class<? extends Message> type, String path) {
Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();
return isValid(descriptor, path);
}
代码示例来源:origin: com.google.protobuf/protobuf-java-util
/**
* Checks whether paths in a given fields mask are valid.
*/
public static boolean isValid(Class<? extends Message> type, FieldMask fieldMask) {
Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();
return isValid(descriptor, fieldMask);
}
代码示例来源:origin: com.google.protobuf/protobuf-java-util
/**
* Constructs a FieldMask from the passed field numbers.
*
* @throws IllegalArgumentException if any of the fields are invalid for the message.
*/
public static FieldMask fromFieldNumbers(
Class<? extends Message> type, Iterable<Integer> fieldNumbers) {
Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();
FieldMask.Builder builder = FieldMask.newBuilder();
for (Integer fieldNumber : fieldNumbers) {
FieldDescriptor field = descriptor.findFieldByNumber(fieldNumber);
checkArgument(
field != null,
String.format("%s is not a valid field number for %s.", fieldNumber, type));
builder.addPaths(field.getName());
}
return builder.build();
}
内容来源于网络,如有侵权,请联系作者删除!