本文整理汇总了Java中com.google.protobuf.GeneratedMessage.ExtendableBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ExtendableBuilder类的具体用法?Java ExtendableBuilder怎么用?Java ExtendableBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExtendableBuilder类属于com.google.protobuf.GeneratedMessage包,在下文中一共展示了ExtendableBuilder类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveUninterpretedOptions
import com.google.protobuf.GeneratedMessage.ExtendableBuilder; //导入依赖的package包/类
private <MType extends ExtendableMessage<MType>, BType extends ExtendableBuilder<MType, BType>> boolean resolveUninterpretedOptions(
final BType optionsBuilder, final FieldDescriptor uninterpretedField) {
ensureRegistry();
boolean anyUninterpetedOptionResolved = false;
@SuppressWarnings("unchecked")
final List<UninterpretedOption> options =
new ArrayList<UninterpretedOption>(
(List<UninterpretedOption>) optionsBuilder.getField(uninterpretedField));
for (final Iterator<UninterpretedOption> iterator = options.iterator(); iterator.hasNext();) {
final UninterpretedOption option = iterator.next();
if (resolveUninterpretedOption(option, optionsBuilder)) {
anyUninterpetedOptionResolved = true;
iterator.remove();
}
}
if (options.isEmpty()) {
optionsBuilder.clearField(uninterpretedField);
} else {
optionsBuilder.setField(uninterpretedField, options);
}
return anyUninterpetedOptionResolved;
}
示例2: resolveUninterpretedOption
import com.google.protobuf.GeneratedMessage.ExtendableBuilder; //导入依赖的package包/类
private <MType extends ExtendableMessage<MType>, BType extends ExtendableBuilder<MType, BType>> boolean resolveUninterpretedOption(
final UninterpretedOptionOrBuilder option, final BType optionsBuilder) {
if (option.getNameCount() == 0) {
throw new IllegalArgumentException("custom option cannot be empty");
}
if (!option.getName(0).getIsExtension()) {
throw new IllegalArgumentException("custom option name should start with '('");
}
final Map.Entry<FieldDescriptor, Object> fieldValue;
if (option.getNameCount() == 1) {
fieldValue = processUninterpretedOptionValue(option, optionsBuilder);
} else {
fieldValue = processUninterpretedOptionMessage(option, optionsBuilder);
}
if (fieldValue == null) {
return false;
}
final FieldDescriptor field = fieldValue.getKey();
final Object value = fieldValue.getValue();
if (field == null || value == null) {
// the UninterpretedOption is not resolved
return false;
}
if (field.isRepeated()) {
optionsBuilder.addRepeatedField(field, value);
} else {
optionsBuilder.setField(field, value);
}
return true;
}
示例3: mergeMessageSetExtensionFromBytes
import com.google.protobuf.GeneratedMessage.ExtendableBuilder; //导入依赖的package包/类
private static void mergeMessageSetExtensionFromBytes(
ByteString rawBytes,
ExtensionRegistry.ExtensionInfo extension,
ExtensionRegistryLite extensionRegistry,
Message.Builder builder,
FieldSet<FieldDescriptor> extensions) throws IOException {
FieldDescriptor field = extension.descriptor;
boolean hasOriginalValue = hasOriginalMessage(builder, extensions, field);
if (hasOriginalValue || ExtensionRegistryLite.isEagerlyParseMessageSets()) {
// If the field already exists, we just parse the field.
Message value = null;
if (hasOriginalValue) {
Message originalMessage =
getOriginalMessage(builder, extensions, field);
Message.Builder subBuilder= originalMessage.toBuilder();
subBuilder.mergeFrom(rawBytes, extensionRegistry);
value = subBuilder.buildPartial();
} else {
value = extension.defaultInstance.getParserForType()
.parsePartialFrom(rawBytes, extensionRegistry);
}
setField(builder, extensions, field, value);
} else {
// Use LazyField to load MessageSet lazily.
LazyField lazyField = new LazyField(
extension.defaultInstance, extensionRegistry, rawBytes);
if (builder != null) {
// TODO(xiangl): it looks like this method can only be invoked by
// ExtendableBuilder, but I'm not sure. So I double check the type of
// builder here. It may be useless and need more investigation.
if (builder instanceof ExtendableBuilder) {
builder.setField(field, lazyField);
} else {
builder.setField(field, lazyField.getValue());
}
} else {
extensions.setField(field, lazyField);
}
}
}
示例4: buildOptions
import com.google.protobuf.GeneratedMessage.ExtendableBuilder; //导入依赖的package包/类
private <MType extends ExtendableMessage<MType>, BType extends ExtendableBuilder<MType, BType>> boolean buildOptions(
final BType optionsBuilder) {
final FieldDescriptor uninterpretedField =
getFD(optionsBuilder, UNINTERPRETED_OPTION_FIELD_NUMBER);
final boolean isUninterpretedEmpty =
optionsBuilder.getRepeatedFieldCount(uninterpretedField) == 0;
final boolean anyUninterpetedOptionResolved =
!isUninterpretedEmpty && resolveUninterpretedOptions(optionsBuilder, uninterpretedField);
final boolean isUnknownFieldsEmpty = optionsBuilder.getUnknownFields().asMap().isEmpty();
Map<FieldDescriptor, Object> allFields = null;
if (isUninterpretedEmpty && isUnknownFieldsEmpty) {
allFields = optionsBuilder.getAllFields();
if (allFields.isEmpty()) {
return false;
}
}
if (customOptionsAsExtensions) {
if (!isUnknownFieldsEmpty) {
reparseBuilder(optionsBuilder, ensureRegistry());
}
} else {
boolean anyExtension = anyUninterpetedOptionResolved;
if (!anyUninterpetedOptionResolved) {
if (allFields == null) {
allFields = optionsBuilder.getAllFields();
}
for (final FieldDescriptor fd : allFields.keySet()) {
if (fd.isExtension()) {
anyExtension = true;
break;
}
}
}
if (anyExtension) {
reparseBuilder(optionsBuilder, ExtensionRegistry.getEmptyRegistry());
}
}
return true;
}