本文整理汇总了Java中com.google.protobuf.ExtensionRegistry.ExtensionInfo方法的典型用法代码示例。如果您正苦于以下问题:Java ExtensionRegistry.ExtensionInfo方法的具体用法?Java ExtensionRegistry.ExtensionInfo怎么用?Java ExtensionRegistry.ExtensionInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.ExtensionRegistry
的用法示例。
在下文中一共展示了ExtensionRegistry.ExtensionInfo方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleValue
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private void handleValue(JsonParser parser,
ExtensionRegistry extensionRegistry,
Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension,
boolean unknown) throws IOException {
Object value = null;
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
value = handleObject(parser, extensionRegistry, builder, field, extension, unknown);
} else {
value = handlePrimitive(parser, field);
}
if (value != null) {
if (field.isRepeated()) {
builder.addRepeatedField(field, value);
} else {
builder.setField(field, value);
}
}
}
示例2: handleValue
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private void handleValue(Tokenizer tokenizer,
ExtensionRegistry extensionRegistry,
Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension,
boolean unknown) throws ParseException {
Object value = null;
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
value = handleObject(tokenizer, extensionRegistry, builder, field, extension, unknown);
} else {
value = handlePrimitive(tokenizer, field);
}
if (value != null) {
if (field.isRepeated()) {
builder.addRepeatedField(field, value);
} else {
builder.setField(field, value);
}
}
}
示例3: createSubBuilder
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private Message.Builder createSubBuilder(Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension) {
Message.Builder subBuilder;
if (extension == null) {
subBuilder = builder.newBuilderForField(field);
} else {
subBuilder = extension.defaultInstance.newBuilderForType();
}
return subBuilder;
}
示例4: handleObject
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private Object handleObject(XMLEventReader parser,
XMLEvent startEvent,
ExtensionRegistry extensionRegistry,
Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension) throws XMLStreamException {
Message.Builder subBuilder = createSubBuilder(builder, field, extension);
XMLEvent event = startEvent;
int depth = 0; // initialize to 0
do {
if (event.isStartElement()) {
depth++; // we're inside the element
mergeField(parser, event,
extensionRegistry, subBuilder);
XMLEvent nextEvent = parser.nextTag();
if (nextEvent.isEndElement()) {
depth--;
// if we're back under the top level obj, and there is another close, we're done.
if (depth <= 0 && parser.peek().isEndElement()) {
break;
}
} else if (nextEvent.isStartElement()) {
depth++;
}
} else {
// something is potentially wrong..
break;
}
} while (parser.hasNext() && (event = parser.nextTag()) != null);
return subBuilder.build();
}
示例5: handleValue
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private Object handleValue(Tokenizer tokenizer,
ExtensionRegistry extensionRegistry,
Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension) throws ParseException {
Object value = null;
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
value = handleObject(tokenizer, extensionRegistry, builder, field, extension);
} else {
value = handlePrimitive(tokenizer, field);
}
return value;
}
示例6: handleObject
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private Object handleObject(Tokenizer tokenizer,
ExtensionRegistry extensionRegistry,
Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension) throws ParseException {
Object value;
Message.Builder subBuilder;
if (extension == null) {
subBuilder = builder.newBuilderForField(field);
} else {
subBuilder = extension.defaultInstance.newBuilderForType();
}
//tokenizer.consume("<");
String endToken = "</";
while (!tokenizer.tryConsume(endToken)) {
if (tokenizer.atEnd()) {
throw tokenizer.parseException("Expected \"" + endToken + "\".");
}
mergeField(tokenizer, extensionRegistry, subBuilder);
}
value = subBuilder.build();
return value;
}
示例7: handleObject
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private Object handleObject(JsonParser parser,
ExtensionRegistry extensionRegistry,
Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension,
boolean unknown) throws IOException {
Message.Builder subBuilder;
if (extension == null) {
subBuilder = builder.newBuilderForField(field);
} else {
subBuilder = extension.defaultInstance.newBuilderForType();
}
JsonToken token = parser.getCurrentToken();
if (JsonToken.VALUE_NULL == token) {
return null;
}
if (unknown) {
ByteString data = ByteString.copyFrom(parser.getBinaryValue());
try {
subBuilder.mergeFrom(data);
return subBuilder.build();
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Failed to build " + field.getFullName() + " from " + data);
}
}
//token = parser.nextToken();
if (token.equals(JsonToken.START_OBJECT)) {
token = parser.nextToken();
while (token != null && !token.equals(JsonToken.END_OBJECT)) {
mergeField(parser, extensionRegistry, subBuilder);
token = parser.nextToken();
}
}
return subBuilder.build();
}
示例8: handleObject
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private Object handleObject(Tokenizer tokenizer,
ExtensionRegistry extensionRegistry,
Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension,
boolean unknown) throws ParseException {
Message.Builder subBuilder;
if (extension == null) {
subBuilder = builder.newBuilderForField(field);
} else {
subBuilder = extension.defaultInstance.newBuilderForType();
}
if (unknown) {
ByteString data = tokenizer.consumeByteString();
try {
subBuilder.mergeFrom(data);
return subBuilder.build();
} catch (InvalidProtocolBufferException e) {
throw tokenizer.parseException("Failed to build " + field.getFullName() + " from " + data);
}
}
tokenizer.consume("{");
String endToken = "}";
while (!tokenizer.tryConsume(endToken)) {
if (tokenizer.atEnd()) {
throw tokenizer.parseException("Expected \"" + endToken + "\".");
}
mergeField(tokenizer, extensionRegistry, subBuilder);
if (tokenizer.tryConsume(",")) {
// there are more fields in the object, so continue
continue;
}
}
return subBuilder.build();
}
示例9: addPlatformExtensions
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private TypeRegistry.Builder addPlatformExtensions(TypeRegistry.Builder registryBuilder) {
ExtensionRegistry extensions = ToolProtoUtil.getStandardPlatformExtensions();
for (String extendedType : EXTENDED_ELEMENTS) {
for (ExtensionRegistry.ExtensionInfo info :
extensions.getAllImmutableExtensionsByExtendedType(extendedType)) {
if (null != info.defaultInstance) {
registryBuilder.add(info.defaultInstance.getDescriptorForType());
}
}
}
return registryBuilder;
}
示例10: newBuilderForField
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
/**
* Calls {@code parent.newBuilderForField()} or uses the
* {@code ExtensionRegistry} to find an appropriate builder, depending
* on what type is being tested.
*/
private Message.Builder newBuilderForField(
Message.Builder parent, Descriptors.FieldDescriptor field) {
if (extensionRegistry == null) {
return parent.newBuilderForField(field);
} else {
ExtensionRegistry.ExtensionInfo extension =
extensionRegistry.findExtensionByNumber(field.getContainingType(),
field.getNumber());
Assert.assertNotNull(extension);
Assert.assertNotNull(extension.defaultInstance);
return extension.defaultInstance.newBuilderForType();
}
}
示例11: mergeField
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
/**
* Parse a single field from {@code tokenizer} and merge it into {@code builder}. If a ',' is
* detected after the field ends, the next field will be parsed automatically
*/
protected void mergeField(Tokenizer tokenizer,
ExtensionRegistry extensionRegistry,
Message.Builder builder) throws ParseException {
FieldDescriptor field;
Descriptor type = builder.getDescriptorForType();
ExtensionRegistry.ExtensionInfo extension = null;
boolean unknown = false;
String name = tokenizer.consumeIdentifier();
field = type.findFieldByName(name);
// Group names are expected to be capitalized as they appear in the
// .proto file, which actually matches their type names, not their field
// names.
if (field == null) {
// Explicitly specify US locale so that this code does not break when
// executing in Turkey.
String lowerName = name.toLowerCase(Locale.US);
field = type.findFieldByName(lowerName);
// If the case-insensitive match worked but the field is NOT a group,
if ((field != null) && (field.getType() != FieldDescriptor.Type.GROUP)) {
field = null;
}
}
// Again, special-case group names as described above.
if ((field != null) && (field.getType() == FieldDescriptor.Type.GROUP)
&& !field.getMessageType().getName().equals(name)) {
field = null;
}
// Last try to lookup by field-index if 'name' is numeric,
// which indicates a possible unknown field
if (field == null && TextUtils.isDigits(name)) {
field = type.findFieldByNumber(Integer.parseInt(name));
unknown = true;
}
// Finally, look for extensions
extension = extensionRegistry.findExtensionByName(name);
if (extension != null) {
if (extension.descriptor.getContainingType() != type) {
throw tokenizer.parseExceptionPreviousToken("Extension \"" + name
+ "\" does not extend message type \""
+ type.getFullName() + "\".");
}
field = extension.descriptor;
}
// Disabled throwing exception if field not found, since it could be a different version.
if (field == null) {
handleMissingField(tokenizer, extensionRegistry, builder);
//throw tokenizer.parseExceptionPreviousToken("Message type \"" + type.getFullName()
// + "\" has no field named \"" + name
// + "\".");
}
if (field != null) {
tokenizer.consume(":");
boolean array = tokenizer.tryConsume("[");
if (array) {
while (!tokenizer.tryConsume("]")) {
handleValue(tokenizer, extensionRegistry, builder, field, extension, unknown);
tokenizer.tryConsume(",");
}
} else {
handleValue(tokenizer, extensionRegistry, builder, field, extension, unknown);
}
}
if (tokenizer.tryConsume(",")) {
// Continue with the next field
mergeField(tokenizer, extensionRegistry, builder);
}
}