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

Java DescriptorProtos类代码示例

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

本文整理汇总了Java中com.google.protobuf.DescriptorProtos的典型用法代码示例。如果您正苦于以下问题:Java DescriptorProtos类的具体用法?Java DescriptorProtos怎么用?Java DescriptorProtos使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DescriptorProtos类属于com.google.protobuf包,在下文中一共展示了DescriptorProtos类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: extractServiceContext

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private Context extractServiceContext(
        ProtoTypeMap protoTypeMap,
        DescriptorProtos.ServiceDescriptorProto serviceProto) {
    Context ctx = new Context();
    ctx.fileName = serviceProto.getName() + CLASS_SUFFIX + ".java";
    ctx.className = serviceProto.getName() + CLASS_SUFFIX;
    ctx.serviceName = serviceProto.getName();
    ctx.deprecated = serviceProto.getOptions() != null && serviceProto.getOptions().getDeprecated();

    // Identify methods to generate a CompletableFuture-based client for.
    // Only unary methods are supported.
    serviceProto.getMethodList().stream()
            .filter(method -> !method.getClientStreaming() && !method.getServerStreaming())
            .forEach(method -> {
                ContextMethod ctxMethod = new ContextMethod();
                ctxMethod.methodName = lowerCaseFirst(method.getName());
                ctxMethod.inputType = protoTypeMap.toJavaTypeName(method.getInputType());
                ctxMethod.outputType = protoTypeMap.toJavaTypeName(method.getOutputType());
                ctxMethod.deprecated = method.getOptions() != null && method.getOptions().getDeprecated();
                ctx.methods.add(ctxMethod);
            });
    return ctx;
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:24,代码来源:Jdk8Generator.java


示例2: ProtoLocation

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
public ProtoLocation(
    DescriptorProtos.SourceCodeInfo.Location location, final ProtoElement element) {
  // Spit out "?:?" for line:column if there's no "span" set in the location.  This can happen
  // when (for example) a proto transform tool synthesizes a field that doesn't appear in the
  // source *.proto files.
  if (location.getSpanCount() > 0) {
    this.displayString =
        String.format(
            "%s:%d:%d",
            element.getFile().getLocation().getDisplayString(),
            location.getSpan(0) + 1,
            location.getSpan(1) + 1);
  } else {
    this.displayString =
        String.format("%s:?:?", element.getFile().getLocation().getDisplayString());
  }
  this.element = element;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:19,代码来源:ProtoLocation.java


示例3: add

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private void add(List<FieldDescriptorProto> extensions) {
  for (int i = 0; i < extensions.size(); i++) {
    pathSegments.push(i);
    FieldDescriptorProto extensionProto = extensions.get(i);
    String extendee = resolve(extensionProto.getExtendee());
    Multimap<String, Extension> messageExtensions = builder.get(extendee);
    if (messageExtensions == null) {
      messageExtensions = ArrayListMultimap.create();
      builder.put(extendee, messageExtensions);
    }
    String path = DOT_JOINER.join(pathSegments.descendingIterator());
    DescriptorProtos.SourceCodeInfo.Location location = locationMap.get(path).get(0);
    // Since paths are only unique within a file, we need a synthetic path to make them unique,
    // given that paths are used to uniquely identify elements in a ProtoFile, and we're
    // stuffing elements from another file into it.
    path = currentFile.getName() + ":" + path;
    Location fileLocation = new SimpleLocation(String.format(
        "%s:%d:%d", currentFile.getName(), location.getSpan(0) + 1, location.getSpan(1) + 1));
    Extension extension = new Extension(extensionProto, location, path, fileLocation);
    messageExtensions.put(getExtensionFieldName(extensionProto.getName()), extension);
    pathSegments.pop();
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:24,代码来源:ExtensionPool.java


示例4: getFileDescProtoForMsgType

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private static DescriptorProtos.FileDescriptorProto getFileDescProtoForMsgType(
    String packageName,
    String messageType,
    DescriptorProtos.FileDescriptorSet set
) {
  DescriptorProtos.FileDescriptorProto file = null;
  for (DescriptorProtos.FileDescriptorProto fileDescriptorProto : set.getFileList()) {
    if (!packageMatch(fileDescriptorProto, packageName)) {
      continue;
    }
    file = containsMessageType(fileDescriptorProto, messageType);
    if (file != null) {
      break;
    }
  }
  return file;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:18,代码来源:ProtobufTypeUtil.java


示例5: doTest

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
 * Write a protobuf to a buffer 'numProtos' times, and then
 * read them back, making sure all data comes through correctly.
 */
private void doTest(int numProtos) throws IOException {
  Configuration conf = new Configuration();
  DataOutputBuffer out = new DataOutputBuffer();

  // Write numProtos protobufs to the buffer
  Message[] sent = new Message[numProtos];
  for (int i = 0; i < numProtos; i++) {
    // Construct a test protocol buffer using one of the
    // protos that ships with the protobuf library
    Message testProto = DescriptorProtos.EnumValueDescriptorProto.newBuilder()
      .setName("test" + i).setNumber(i).build();
    ObjectWritable.writeObject(out, testProto,
        DescriptorProtos.EnumValueDescriptorProto.class, conf);
    sent[i] = testProto;
  }

  // Read back the data
  DataInputBuffer in = new DataInputBuffer();
  in.reset(out.getData(), out.getLength());
  
  for (int i = 0; i < numProtos; i++) {
    Message received = (Message)ObjectWritable.readObject(in, conf);
    
    assertEquals(sent[i], received);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:31,代码来源:TestObjectWritableProtos.java


示例6: of

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
 * Returns an instance of {@link ProtoTypeMap} based on the given FileDescriptorProto instances.
 *
 * @param fileDescriptorProtos the full collection of files descriptors from the code generator request
 */
public static ProtoTypeMap of(@Nonnull Collection<DescriptorProtos.FileDescriptorProto> fileDescriptorProtos) {
    Preconditions.checkNotNull(fileDescriptorProtos, "fileDescriptorProtos");
    Preconditions.checkArgument(!fileDescriptorProtos.isEmpty(), "fileDescriptorProtos.isEmpty()");

    final ImmutableMap.Builder<String, String> types = ImmutableMap.builder();

    for (final DescriptorProtos.FileDescriptorProto fileDescriptor : fileDescriptorProtos) {
        final DescriptorProtos.FileOptions fileOptions = fileDescriptor.getOptions();

        final String protoPackage = fileDescriptor.hasPackage() ? "." + fileDescriptor.getPackage() : "";
        final String javaPackage = Strings.emptyToNull(
                fileOptions.hasJavaPackage() ?
                        fileOptions.getJavaPackage() :
                        fileDescriptor.getPackage());
        final String enclosingClassName =
                fileOptions.getJavaMultipleFiles() ?
                        null :
                        getJavaOuterClassname(fileDescriptor, fileOptions);



        fileDescriptor.getEnumTypeList().forEach(
            e -> types.put(
                    protoPackage + "." + e.getName(),
                    toJavaTypeName(e.getName(), enclosingClassName, javaPackage)));

        fileDescriptor.getMessageTypeList().forEach(
            m -> types.put(
                    protoPackage + "." + m.getName(),
                    toJavaTypeName(m.getName(), enclosingClassName, javaPackage)));
    }

    return new ProtoTypeMap(types.build());
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:40,代码来源:ProtoTypeMap.java


示例7: getJavaOuterClassname

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private static String getJavaOuterClassname(
        DescriptorProtos.FileDescriptorProto fileDescriptor,
        DescriptorProtos.FileOptions fileOptions) {

    if (fileOptions.hasJavaOuterClassname()) {
        return fileOptions.getJavaOuterClassname();
    }

    // If the outer class name is not explicitly defined, then we take the proto filename, strip its extension,
    // and convert it from snake case to camel case.
    String filename = fileDescriptor.getName().substring(0, fileDescriptor.getName().length() - ".proto".length());
    filename = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, filename);
    return appendOuterClassSuffix(filename, fileDescriptor);
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:15,代码来源:ProtoTypeMap.java


示例8: appendOuterClassSuffix

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
 * In the event of a name conflict between the outer and inner type names, protoc adds an OuterClass suffix to the
 * outer type's name.
 */
private static String appendOuterClassSuffix(final String enclosingClassName, DescriptorProtos.FileDescriptorProto fd) {
    if (fd.getEnumTypeList().stream().anyMatch(enumProto -> enumProto.getName().equals(enclosingClassName)) ||
        fd.getMessageTypeList().stream().anyMatch(messageProto -> messageProto.getName().equals(enclosingClassName))) {
        return enclosingClassName + "OuterClass";
    } else {
        return enclosingClassName;
    }
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:13,代码来源:ProtoTypeMap.java


示例9: extractContext

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private Stream<Context> extractContext(ProtoTypeMap protoTypeMap, DescriptorProtos.FileDescriptorProto proto) {
    return proto.getServiceList().stream()
            .map(s -> extractServiceContext(protoTypeMap, s))
            .map(ctx -> {
                ctx.packageName = extractPackageName(proto); return ctx;
            })
            .map(ctx -> {
                ctx.protoName = proto.getName(); return ctx;
            });
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:11,代码来源:Jdk8Generator.java


示例10: extractPackageName

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private String extractPackageName(DescriptorProtos.FileDescriptorProto proto) {
    DescriptorProtos.FileOptions options = proto.getOptions();
    if (options != null) {
        String javaPackage = options.getJavaPackage();
        if (!Strings.isNullOrEmpty(javaPackage)) {
            return javaPackage;
        }
    }

    return Strings.nullToEmpty(proto.getPackage());
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:12,代码来源:Jdk8Generator.java


示例11: Extension

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private Extension(FieldDescriptorProto proto, DescriptorProtos.SourceCodeInfo.Location location,
    String path, Location fileLocation) {
  this.proto = proto;
  this.location = location;
  this.path = path;
  this.fileLocation = fileLocation;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:8,代码来源:ExtensionPool.java


示例12: buildLocationMap

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private static ImmutableListMultimap<String, DescriptorProtos.SourceCodeInfo.Location>
    buildLocationMap(FileDescriptorProto file) {
  return Multimaps.<String, DescriptorProtos.SourceCodeInfo.Location>index(
      file.getSourceCodeInfo().getLocationList(),
      new Function<DescriptorProtos.SourceCodeInfo.Location, String>() {
        @Override
        public String apply(DescriptorProtos.SourceCodeInfo.Location location) {
          return DOT_JOINER.join(location.getPathList());
        }
      });
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:12,代码来源:ExtensionPool.java


示例13: getDocumentation

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private String getDocumentation(String path) {
  String comment = "";
  DescriptorProtos.SourceCodeInfo.Location location = getSourceCodeLocation(path);
  if (location != null) {
    if (!Strings.isNullOrEmpty(location.getLeadingComments())) {
      comment = location.getLeadingComments();
    }
    if (!Strings.isNullOrEmpty(location.getTrailingComments())){
      comment += location.getTrailingComments();
    }
  }
  return comment;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:14,代码来源:ProtoFile.java


示例14: getSourceCodeLocation

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private DescriptorProtos.SourceCodeInfo.Location getSourceCodeLocation(String path) {
  if (locationMap.containsKey(path)) {
    // We get the first location.
    return locationMap.get(path).get(0);
  } else {
    return null;
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:9,代码来源:ProtoFile.java


示例15: getAllFileDescriptors

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
 * Loads a Protobuf file descriptor set into an ubermap of file descriptors.
 *
 * @param set               FileDescriptorSet
 * @param dependenciesMap   FileDescriptor dependency map
 * @param fileDescriptorMap The populated map of FileDescriptors
 * @throws StageException
 */
public static void getAllFileDescriptors(
    DescriptorProtos.FileDescriptorSet set,
    Map<String, Set<Descriptors.FileDescriptor>> dependenciesMap,
    Map<String, Descriptors.FileDescriptor> fileDescriptorMap
) throws StageException {
  List<DescriptorProtos.FileDescriptorProto> fileList = set.getFileList();
  try {
    for (DescriptorProtos.FileDescriptorProto fdp : fileList) {
      if (!fileDescriptorMap.containsKey(fdp.getName())) {
        Set<Descriptors.FileDescriptor> dependencies = dependenciesMap.get(fdp.getName());
        if (dependencies == null) {
          dependencies = new LinkedHashSet<>();
          dependenciesMap.put(fdp.getName(), dependencies);
          dependencies.addAll(getDependencies(dependenciesMap, fileDescriptorMap, fdp, set));
        }
        Descriptors.FileDescriptor fileDescriptor = Descriptors.FileDescriptor.buildFrom(
            fdp,
            dependencies.toArray(new Descriptors.FileDescriptor[dependencies.size()])
        );
        fileDescriptorMap.put(fdp.getName(), fileDescriptor);
      }
    }
  } catch (Descriptors.DescriptorValidationException e) {
    throw new StageException(Errors.PROTOBUF_07, e.getDescription(), e);
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:35,代码来源:ProtobufTypeUtil.java


示例16: getDescriptor

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
/**
 * Generates a protobuf descriptor instance from a FileDescriptor set.
 *
 * @param set               set of file descriptors
 * @param fileDescriptorMap map of message types to file descriptors
 * @param descriptorFile    descriptor file for message to be decoded
 * @param qualifiedMessageType       the name of the message to be decoded
 * @return protobuf descriptor instance
 * @throws StageException
 */
public static Descriptors.Descriptor getDescriptor(
    DescriptorProtos.FileDescriptorSet set,
    Map<String, Descriptors.FileDescriptor> fileDescriptorMap,
    String descriptorFile,
    String qualifiedMessageType
) throws StageException {

  // find the FileDescriptorProto which contains the message type
  // IF cannot find, then bail out
  String packageName = null;
  String messageType = qualifiedMessageType;
  int lastIndex = qualifiedMessageType.lastIndexOf('.');
  if (lastIndex != -1) {
    packageName = qualifiedMessageType.substring(0, lastIndex);
    messageType = qualifiedMessageType.substring(lastIndex + 1);
  }
  DescriptorProtos.FileDescriptorProto file = getFileDescProtoForMsgType(packageName, messageType, set);
  if (file == null) {
    // could not find the message type from all the proto files contained in the descriptor file
    throw new StageException(Errors.PROTOBUF_00, qualifiedMessageType, descriptorFile);
  }
  // finally get the FileDescriptor for the message type
  Descriptors.FileDescriptor fileDescriptor = fileDescriptorMap.get(file.getName());
  // create builder using the FileDescriptor
  // this can only find the top level message types
  return fileDescriptor.findMessageTypeByName(messageType);

}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:39,代码来源:ProtobufTypeUtil.java


示例17: containsMessageType

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private static DescriptorProtos.FileDescriptorProto containsMessageType(
  DescriptorProtos.FileDescriptorProto fileDescriptorProto, String messageType
) {
  DescriptorProtos.FileDescriptorProto file = null;
  for (DescriptorProtos.DescriptorProto descriptorProto :
    getAllMessageTypesInDescriptorProto(fileDescriptorProto)) {
    if (messageType.equals(descriptorProto.getName())) {
      file = fileDescriptorProto;
      break;
    }
  }
  return file;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:14,代码来源:ProtobufTypeUtil.java


示例18: getAllMessageTypesInDescriptorProto

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private static List<DescriptorProtos.DescriptorProto> getAllMessageTypesInDescriptorProto(
    DescriptorProtos.FileDescriptorProto fileDescriptorProto
) {
  Queue<DescriptorProtos.DescriptorProto> queue = new LinkedList<>();
  queue.addAll(fileDescriptorProto.getMessageTypeList());
  List<DescriptorProtos.DescriptorProto> result = new ArrayList<>();
  while (!queue.isEmpty()) {
    DescriptorProtos.DescriptorProto descriptorProto = queue.poll();
    queue.addAll(descriptorProto.getNestedTypeList());
    result.add(descriptorProto);
  }
  return result;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:14,代码来源:ProtobufTypeUtil.java


示例19: setUp

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  FileInputStream fin = new FileInputStream(Resources.getResource("Employee.desc").getPath());
  set = DescriptorProtos.FileDescriptorSet.parseFrom(fin);
  ProtobufTypeUtil.getAllFileDescriptors(set, fileDescriptorDependentsMap, fileDescriptorMap);
  ProtobufTypeUtil.populateDefaultsAndExtensions(fileDescriptorMap, typeToExtensionMap, defaultValueMap);
  md = ProtobufTypeUtil.getDescriptor(set, fileDescriptorMap, "Employee.desc", "util.Employee");
  extensionRegistry = ProtobufTestUtil.createExtensionRegistry(typeToExtensionMap);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:10,代码来源:TestProtobufTypeUtil.java


示例20: FileDescriptorEx

import com.google.protobuf.DescriptorProtos; //导入依赖的package包/类
private FileDescriptorEx() {
  delegate = DescriptorProtos.getDescriptor();
  proto = delegate.toProto();
  dependencies = Collections.<FileDescriptorEx>emptyList();
  deeplyCanonical = 1;
  hashCode = delegate.hashCode();
  reparseCustomOptions = false;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:9,代码来源:FileDescriptorEx.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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