当前位置: 首页>>代码示例>>Java>>正文


Java Descriptors.FileDescriptor方法代码示例

本文整理汇总了Java中com.google.protobuf.Descriptors.FileDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java Descriptors.FileDescriptor方法的具体用法?Java Descriptors.FileDescriptor怎么用?Java Descriptors.FileDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protobuf.Descriptors的用法示例。


在下文中一共展示了Descriptors.FileDescriptor方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: populateDefaultsAndExtensions

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
/**
 * Populates a map of protobuf extensions and map with the default values for
 * each message field from a map of file descriptors.
 *
 * @param fileDescriptorMap Map of file descriptors
 * @param typeToExtensionMap Map of extensions to populate
 * @param defaultValueMap Map of default values to populate
 */
public static void populateDefaultsAndExtensions(
    Map<String, Descriptors.FileDescriptor> fileDescriptorMap,
    Map<String, Set<Descriptors.FieldDescriptor>> typeToExtensionMap,
    Map<String, Object> defaultValueMap
) {
  for (Descriptors.FileDescriptor f : fileDescriptorMap.values()) {
    // go over every file descriptor and look for extensions and default values of those extensions
    for (Descriptors.FieldDescriptor fieldDescriptor : f.getExtensions()) {
      String containingType = fieldDescriptor.getContainingType().getFullName();
      Set<Descriptors.FieldDescriptor> fieldDescriptors = typeToExtensionMap.get(containingType);
      if (fieldDescriptors == null) {
        fieldDescriptors = new LinkedHashSet<>();
        typeToExtensionMap.put(containingType, fieldDescriptors);
      }
      fieldDescriptors.add(fieldDescriptor);
      if (fieldDescriptor.hasDefaultValue()) {
        defaultValueMap.put(containingType + "." + fieldDescriptor.getName(), fieldDescriptor.getDefaultValue());
      }
    }
    // go over messages within file descriptor and look for all fields and extensions and their defaults
    for (Descriptors.Descriptor d : f.getMessageTypes()) {
      addDefaultsAndExtensions(typeToExtensionMap, defaultValueMap, d);
    }
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:34,代码来源:ProtobufTypeUtil.java

示例2: assignDescriptors

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public ExtensionRegistry assignDescriptors(Descriptors.FileDescriptor root) {
	PushSMPMessageProtos.descriptor = root;
	PushSMPMessageProtos.internal_static_textsecure_IncomingPushMessageSignal_descriptor = (Descriptors.Descriptor)PushSMPMessageProtos.descriptor.getMessageTypes().get(0);
	PushSMPMessageProtos.internal_static_textsecure_IncomingPushMessageSignal_fieldAccessorTable = new GeneratedMessage.FieldAccessorTable(PushSMPMessageProtos.internal_static_textsecure_IncomingPushMessageSignal_descriptor, new String[]{"Type", "Source", "SourceDevice", "Relay", "Timestamp", "Message"});
	PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_descriptor = (Descriptors.Descriptor)PushSMPMessageProtos.descriptor.getMessageTypes().get(1);
	PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_fieldAccessorTable = new GeneratedMessage.FieldAccessorTable(PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_descriptor, new String[]{"Body", "Attachments", "Group", "Flags", "Sync"});
	PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_AttachmentPointer_descriptor = (Descriptors.Descriptor)PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_descriptor.getNestedTypes().get(0);
	PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_AttachmentPointer_fieldAccessorTable = new GeneratedMessage.FieldAccessorTable(PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_AttachmentPointer_descriptor, new String[]{"Id", "ContentType", "Key"});
	PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_GroupContext_descriptor = (Descriptors.Descriptor)PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_descriptor.getNestedTypes().get(1);
	PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_GroupContext_fieldAccessorTable = new GeneratedMessage.FieldAccessorTable(PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_GroupContext_descriptor, new String[]{"Id", "Type", "Name", "Members", "Avatar"});
	PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_SyncMessageContext_descriptor = (Descriptors.Descriptor)PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_descriptor.getNestedTypes().get(2);
	PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_SyncMessageContext_fieldAccessorTable = new GeneratedMessage.FieldAccessorTable(PushSMPMessageProtos.internal_static_textsecure_PushSMPMessageContent_SyncMessageContext_descriptor, new String[]{"Destination", "Timestamp"});
	return null;
}
 
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:15,代码来源:PushSMPMessageProtos.java

示例3: getAllFileDescriptors

import com.google.protobuf.Descriptors; //导入方法依赖的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

示例4: getDescriptor

import com.google.protobuf.Descriptors; //导入方法依赖的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

示例5: testDescriptorDependentsMap

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
@Test
public void testDescriptorDependentsMap() throws Exception {

  Assert.assertTrue(!fileDescriptorDependentsMap.isEmpty());
  Assert.assertEquals(0, fileDescriptorDependentsMap.get("Person.proto").size());

  Assert.assertEquals(1, fileDescriptorDependentsMap.get("Engineer.proto").size());
  Set<Descriptors.FileDescriptor> fileDescriptors = fileDescriptorDependentsMap.get("Engineer.proto");
  Iterator<Descriptors.FileDescriptor> iterator = fileDescriptors.iterator();
  Assert.assertEquals("Person.proto", iterator.next().getName());

  Assert.assertEquals(1, fileDescriptorDependentsMap.get("Executive.proto").size());
  fileDescriptors = fileDescriptorDependentsMap.get("Executive.proto");
  iterator = fileDescriptors.iterator();
  Assert.assertEquals("Person.proto", iterator.next().getName());

  Assert.assertEquals(3, fileDescriptorDependentsMap.get("Employee.proto").size());
  fileDescriptors = fileDescriptorDependentsMap.get("Employee.proto");
  iterator = fileDescriptors.iterator();
  Assert.assertEquals("Engineer.proto", iterator.next().getName());
  Assert.assertEquals("Executive.proto", iterator.next().getName());
  Assert.assertEquals("Person.proto", iterator.next().getName());


  Assert.assertEquals(4, fileDescriptorDependentsMap.get("Extensions.proto").size());
  fileDescriptors = fileDescriptorDependentsMap.get("Extensions.proto");
  iterator = fileDescriptors.iterator();
  Assert.assertEquals("Person.proto", iterator.next().getName());
  Assert.assertEquals("Engineer.proto", iterator.next().getName());
  Assert.assertEquals("Executive.proto", iterator.next().getName());
  Assert.assertEquals("Employee.proto", iterator.next().getName());

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

示例6: main

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public static void main(String[] args) throws InvalidProtocolBufferException {
        Descriptors.FileDescriptor descriptor = Gpb.getDescriptor();

        Gpb.Request build = Gpb.Request.newBuilder()
                .setId(1)
                .setApi(1001)
                .build();
        Gpb.Response response = Gpb.Response.newBuilder()
                .setId(1)
                .setData(build.toByteString())
                .setError(
                        Gpb.Error.newBuilder()
                                .setMsg("SomeThing")
                                .setRet(1)
                                .build()
                )
                .build();

        //  收到的数据
//        Message parseFrom = Gpb.Request.parseFrom(build.toByteArray());
        Message parseFrom = Gpb.Response.parseFrom(response.toByteArray());

        Map<FieldDescriptor, Object> fields = parseFrom.getAllFields();
        Object[] objects = parseFrom.getAllFields().values().toArray();

        Object[] params = new Object[parseFrom.getAllFields().size()];


        for (Map.Entry<FieldDescriptor, Object> entry : fields.entrySet()) {
            Object covert = covert(entry.getKey(), entry.getValue());
            params[entry.getKey().getIndex()] = entry.getValue();
            System.out.println();
        }


        System.out.println();
    }
 
开发者ID:ogcs,项目名称:Okra,代码行数:38,代码来源:Gpb4JUtil.java

示例7: getDescriptor

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public static Descriptors.FileDescriptor getDescriptor() {
	return descriptor;
}
 
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:4,代码来源:PushSMPMessageProtos.java

示例8: getDependencies

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
private static Set<Descriptors.FileDescriptor> getDependencies(
    Map<String, Set<Descriptors.FileDescriptor>> dependenciesMap,
    Map<String, Descriptors.FileDescriptor> fileDescriptorMap,
    DescriptorProtos.FileDescriptorProto file,
    DescriptorProtos.FileDescriptorSet set
) throws StageException {
  Set<Descriptors.FileDescriptor> result = new LinkedHashSet<>();
  for (String name : file.getDependencyList()) {
    DescriptorProtos.FileDescriptorProto fileDescriptorProto = null;
    for (DescriptorProtos.FileDescriptorProto fdp : set.getFileList()) {
      if (name.equals(fdp.getName())) {
        fileDescriptorProto = fdp;
        break;
      }
    }
    if (fileDescriptorProto == null) {
      // could not find the message type from all the proto files contained in the descriptor file
      throw new StageException(Errors.PROTOBUF_01, file.getName());
    }
    Descriptors.FileDescriptor fileDescriptor;
    if (fileDescriptorMap.containsKey(fileDescriptorProto.getName())) {
      fileDescriptor = fileDescriptorMap.get(fileDescriptorProto.getName());
    } else {
      Set<Descriptors.FileDescriptor> deps = new LinkedHashSet<>();
      if (dependenciesMap.containsKey(name)) {
        deps.addAll(dependenciesMap.get(name));
      } else {
        deps.addAll(getDependencies(dependenciesMap, fileDescriptorMap, fileDescriptorProto, set));
      }
      try {
        fileDescriptor = Descriptors.FileDescriptor.buildFrom(
            fileDescriptorProto,
            deps.toArray(new Descriptors.FileDescriptor[deps.size()])
        );
      } catch (Descriptors.DescriptorValidationException e) {
        throw new StageException(Errors.PROTOBUF_07, e.getDescription(), e);
      }
    }
    result.add(fileDescriptor);
  }
  return result;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:43,代码来源:ProtobufTypeUtil.java

示例9: test

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
@Test
    public void test() {
//        LoginUser user = new LoginUser();

        Descriptors.FileDescriptor descriptor = ProLoginBeans.getDescriptor();

        List<Descriptors.Descriptor> messageTypes = descriptor.getMessageTypes();


        System.out.println();

    }
 
开发者ID:ogcs,项目名称:Okra-Ax,代码行数:13,代码来源:LoginUserTest.java


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