當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。