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


Java Descriptors.FieldDescriptor方法代码示例

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


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

示例1: requireAllFieldsExcept

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
private static void requireAllFieldsExcept(AbstractMessage message, int... fieldNumbersNotRequired) {
    Collection<Descriptors.FieldDescriptor> required = new ArrayList<>(message.getDescriptorForType().getFields());
    Collection<Descriptors.FieldDescriptor> actual = message.getAllFields().keySet();
    required.removeAll(actual);
    if(fieldNumbersNotRequired != null) {
        for(int fieldNumber : fieldNumbersNotRequired) {
            required.remove(message.getDescriptorForType().findFieldByNumber(fieldNumber));
        }
    }
    if(!required.isEmpty()) {
        Collection<String> names = new ArrayList<>(required.size());
        for(Descriptors.FieldDescriptor desc : required) {
            names.add(desc.getName());
        }
        throw new ProtobufReadException(message.getDescriptorForType().getFullName(),
                                        "Missing required fields: " + names.toString());
    }
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:19,代码来源:ProtobufReader.java

示例2: messageForFilter

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
private static <M extends Message, B extends Message.Builder> M messageForFilter(
        ProtocolStringList filter,
        Constructor<B> builderConstructor, Message wholeMessage)
        throws InstantiationException,
               IllegalAccessException,
               InvocationTargetException {
    final B builder = builderConstructor.newInstance();

    final List<Descriptors.FieldDescriptor> fields = wholeMessage.getDescriptorForType()
                                                                 .getFields();
    for (Descriptors.FieldDescriptor field : fields) {
        if (filter.contains(field.getFullName())) {
            builder.setField(field, wholeMessage.getField(field));
        }
    }
    @SuppressWarnings("unchecked")
    // It's fine as the constructor is of {@code MessageCls.Builder} type.
    final M result = (M) builder.build();
    return result;
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:21,代码来源:FieldMasks.java

示例3: addMapField

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
private static void addMapField(final JsonObjectBuilder json, final Message msg, final Descriptors.FieldDescriptor field) {
    final JsonObjectBuilder map = Json.createObjectBuilder();
    final List<MapEntry<String, Object>> mapEntries = (List<MapEntry<String, Object>>) msg.getField(field);
    mapEntries.forEach(entry -> {
        final Object value = entry.getValue();
        if (value instanceof Message) {
            map.add(entry.getKey(), protobuMessageToJson((Message) value));
        } else if (value instanceof String) {
            map.add(entry.getKey(), (String) value);
        } else if (value instanceof Integer) {
            map.add(entry.getKey(), (Integer) value);
        } else if (value instanceof Long) {
            map.add(entry.getKey(), (Long) value);
        } else if (value instanceof Double) {
            map.add(entry.getKey(), (Double) value);
        } else if (value instanceof Float) {
            map.add(entry.getKey(), (Float) value);
        } else if (value instanceof Boolean) {
            map.add(entry.getKey(), (Boolean) value);
        } else if (value instanceof ByteString) {
            map.add(entry.getKey(), Base64.getEncoder().encodeToString(((ByteString) value).toByteArray()));
        }
    });
    json.add(field.getName(), map);
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:26,代码来源:ProtobufUtils.java

示例4: ProtobufDataParser

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public ProtobufDataParser(
    ProtoConfigurableEntity.Context context,
    String messageId,
    Descriptors.Descriptor descriptor,
    Map<String, Set<Descriptors.FieldDescriptor>> messageTypeToExtensionMap,
    ExtensionRegistry extensionRegistry,
    InputStream inputStream,
    String readerOffset,
    int maxObjectLength,
    boolean isDelimited
) throws IOException, Descriptors.DescriptorValidationException, DataParserException {
  this.context = context;
  this.inputStream = new OverrunInputStream(inputStream, maxObjectLength, true);
  this.messageId = messageId;
  this.messageTypeToExtensionMap = messageTypeToExtensionMap;
  this.extensionRegistry = extensionRegistry;
  this.descriptor = descriptor;
  this.builder = DynamicMessage.newBuilder(descriptor);
  this.isDelimited = isDelimited;

  // skip to the required location
  if (readerOffset != null && !readerOffset.isEmpty() && !readerOffset.equals("0")) {
    int offset = Integer.parseInt(readerOffset);
    this.inputStream.skip(offset);
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:27,代码来源:ProtobufDataParser.java

示例5: 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

示例6: print

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
private void print(final Message message,
                          final JavaPropsGenerator generator)
    throws IOException {
  for (final Map.Entry<Descriptors.FieldDescriptor, Object> field :
       message.getAllFields().entrySet()) {
    printField(field.getKey(), field.getValue(), generator);
  }
  printUnknownFields(message.getUnknownFields(), generator);
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:10,代码来源:JavaPropsFormat.java

示例7: printField

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public void printField(final Descriptors.FieldDescriptor field,
                              final Object value,
                              final Appendable output)
                              throws IOException {
  final JavaPropsGenerator generator = new JavaPropsGenerator(output);
  printField(field, value, generator);
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:8,代码来源:JavaPropsFormat.java

示例8: printFieldToString

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public String printFieldToString(final Descriptors.FieldDescriptor field,
                                        final Object value) {
  try {
    final StringBuilder text = new StringBuilder();
    printField(field, value, text);
    return text.toString();
  } catch (IOException e) {
    throw new RuntimeException(
      "Writing to a StringBuilder threw an IOException (should never " +
      "happen).", e);
  }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:13,代码来源:JavaPropsFormat.java

示例9: populate

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
/**
 * 
 * @param rs
 * @param builder
 * @throws SQLException
 */
private void populate(ResultSet rs, Message.Builder builder)
		throws SQLException {
	ResultSetMetaData metaData = rs.getMetaData();
	int columnCount = metaData.getColumnCount();// 列个数
	String columnLabel = null;// 列名
	Object columnValue = null;// 列值
	Descriptors.FieldDescriptor fieldDescriptor = null;
	for (int i = 1; i <= columnCount; i++) {
		columnLabel = metaData.getColumnLabel(i);
		columnValue = rs.getObject(i);
		if (columnValue == null)
			continue;// 如果为空,继续下一个
		fieldDescriptor = descriptor.findFieldByName(columnLabel);
		if (fieldDescriptor == null)
			continue;// 如果为空,继续下一个
		// 转换为相应的类型 ,会自动将 date 类型转换为long
		if (fieldDescriptor.getType().equals(FieldDescriptor.Type.ENUM)) {
			columnValue = fieldDescriptor.getEnumType().findValueByNumber(
					(int) columnValue);
		} else {
			columnValue = ConvertUtils.convert(columnValue, fieldDescriptor
					.getDefaultValue().getClass());
		}
		builder.setField(fieldDescriptor, columnValue);
	}
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:33,代码来源:JdbcProtobufTemplate.java

示例10: convert

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public static SharedPreferences.Editor convert(Message message, SharedPreferences.Editor editor) {
    Map<Descriptors.FieldDescriptor,Object> fields = message.getAllFields();
    for (Descriptors.FieldDescriptor desc : fields.keySet()) {
        Log.i(TAG,"processing \""+desc.getName()+"\" with value \""+ fields.get(desc)+"\" ");
        switch (desc.getJavaType()) {

            case INT:
                editor.putInt(desc.getName(),(Integer)fields.get(desc));
                break;
            case LONG:
                editor.putLong(desc.getName(),(Long)fields.get(desc));
                break;
            case FLOAT:
                break;
            case DOUBLE:
                break;
            case BOOLEAN:
                editor.putBoolean(desc.getName(),(Boolean)fields.get(desc));
                break;
            case STRING:
                editor.putString(desc.getName(),(String)fields.get(desc));
                break;
            case BYTE_STRING:
                break;
            case ENUM:
                break;
            case MESSAGE:
                break;
        }

    }
    return editor;
}
 
开发者ID:TheCopycat,项目名称:protobuf-powered-android,代码行数:34,代码来源:ProtoToPrefConverter.java

示例11: convertFromPrefs

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public static Message.Builder convertFromPrefs(Message.Builder builder, SharedPreferences prefs) {
    List<Descriptors.FieldDescriptor> fields = builder.getDescriptorForType().getFields();
    for (Descriptors.FieldDescriptor desc : fields) {
        Log.i(TAG,"processing \""+desc.getName()+"\"");
        switch (desc.getJavaType()) {

            case INT:
                builder.setField(desc,prefs.getInt(desc.getName(),0));
                break;
            case LONG:
                builder.setField(desc,prefs.getLong(desc.getName(),0L));
                break;
            case FLOAT:
                break;
            case DOUBLE:
                break;
            case BOOLEAN:
                builder.setField(desc,prefs.getBoolean(desc.getName(),false));
                break;
            case STRING:
                builder.setField(desc,prefs.getString(desc.getName(),""));
                break;
            case BYTE_STRING:
                break;
            case ENUM:
                break;
            case MESSAGE:
                break;
        }

    }
    return builder;
}
 
开发者ID:TheCopycat,项目名称:protobuf-powered-android,代码行数:34,代码来源:ProtoToPrefConverter.java

示例12: getValueByFieldNameOrNull

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public Object getValueByFieldNameOrNull(MessageOrBuilder message, String fieldName, Object defaultValue){
    Descriptors.FieldDescriptor field=message.getDescriptorForType().findFieldByName(fieldName);
    if(field!=null && message.hasField(field)){
        return message.getField(field);
    }
    return defaultValue;
}
 
开发者ID:taojoe,项目名称:protobuf-transformer,代码行数:8,代码来源:Transformer.java

示例13: maskOf

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
/**
 * Creates a new instance of {@code FieldMask} basing on the target type
 * {@link Descriptor descriptor} and field tags defined in the Protobuf message.
 *
 * @param typeDescriptor {@link Descriptor descriptor} of the type to create a mask for.
 * @param fieldTags      field tags to include into the mask.
 * @return an instance of {@code FieldMask} for the target type with the fields specified.
 */
public static FieldMask maskOf(Descriptor typeDescriptor, int... fieldTags) {
    if (fieldTags.length == 0) {
        return FieldMask.getDefaultInstance();
    }

    final FieldMask.Builder result = FieldMask.newBuilder();
    for (int fieldNumber : fieldTags) {
        final Descriptors.FieldDescriptor field = typeDescriptor.findFieldByNumber(fieldNumber);
        final String fieldPath = field.getFullName();
        result.addPaths(fieldPath);
    }

    return result.build();
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:23,代码来源:FieldMasks.java

示例14: return_multiple_results_for_projection_batch_read_by_ids_with_field_mask

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
@Test
public void return_multiple_results_for_projection_batch_read_by_ids_with_field_mask() {
    final List<Descriptors.FieldDescriptor> projectFields = Project.getDescriptor()
                                                                   .getFields();
    doCheckReadingCustomersByIdAndFieldMask(
            projectFields.get(0)
                         .getFullName(), // ID
            projectFields.get(1)
                         .getFullName()); // Name
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:11,代码来源:StandShould.java

示例15: retrieve_all_data_if_field_mask_is_not_set

import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
@Test
public void retrieve_all_data_if_field_mask_is_not_set() {
    final Stand stand = prepareStandWithAggregateRepo(createStandStorage());

    final Customer sampleCustomer = getSampleCustomer();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(sampleCustomer.getId(), sampleCustomer, stateVersion));

    final Query customerQuery = requestFactory.query().all(Customer.class);

    //noinspection OverlyComplexAnonymousInnerClass
    final MemoizeQueryResponseObserver observer = new MemoizeQueryResponseObserver() {
        @Override
        public void onNext(QueryResponse value) {
            super.onNext(value);
            final List<Any> messages = value.getMessagesList();
            assertFalse(messages.isEmpty());

            final Customer customer = unpack(messages.get(0));
            for (Descriptors.FieldDescriptor field : customer.getDescriptorForType()
                                                             .getFields()) {
                assertTrue(customer.getField(field)
                                   .equals(sampleCustomer.getField(field)));
            }
        }
    };

    stand.execute(customerQuery, observer);

    verifyObserver(observer);
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:32,代码来源:StandShould.java


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