• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ExtendableBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:27,代码来源:OptionResolver.java


示例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;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:39,代码来源:OptionResolver.java


示例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);
    }
  }
}
 
开发者ID:bdceo,项目名称:bd-codes,代码行数:43,代码来源:AbstractMessage.java


示例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;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:47,代码来源:OptionResolver.java



注:本文中的com.google.protobuf.GeneratedMessage.ExtendableBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HBaseCluster类代码示例发布时间:2022-05-22
下一篇:
Java HAServiceTarget类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap