本文整理匯總了Java中com.google.protobuf.Descriptors.Descriptor.getFields方法的典型用法代碼示例。如果您正苦於以下問題:Java Descriptor.getFields方法的具體用法?Java Descriptor.getFields怎麽用?Java Descriptor.getFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.Descriptors.Descriptor
的用法示例。
在下文中一共展示了Descriptor.getFields方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAllFieldsMutable
import com.google.protobuf.Descriptors.Descriptor; //導入方法依賴的package包/類
/** Internal helper which returns a mutable map. */
private Map<FieldDescriptor, Object> getAllFieldsMutable() {
final TreeMap<FieldDescriptor, Object> result =
new TreeMap<FieldDescriptor, Object>();
final Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
for (final FieldDescriptor field : descriptor.getFields()) {
if (field.isRepeated()) {
final List value = (List) getField(field);
if (!value.isEmpty()) {
result.put(field, value);
}
} else {
if (hasField(field)) {
result.put(field, getField(field));
}
}
}
return result;
}
示例2: createProtoBuf
import com.google.protobuf.Descriptors.Descriptor; //導入方法依賴的package包/類
Message createProtoBuf(
Descriptor descriptor, Message.Builder builder, Map<String, Object> input) {
if (input == null) {
return builder.build();
}
for (FieldDescriptor field : descriptor.getFields()) {
String fieldName = field.getName();
if (!input.containsKey(fieldName)) {
// TODO: validate required fields
continue;
}
if (field.isRepeated()) {
List<Object> values = (List<Object>) input.get(fieldName);
for (Object value : values) {
builder.addRepeatedField(field, getValueForField(field, value, builder));
}
} else {
builder.setField(field, getValueForField(field, input.get(fieldName), builder));
}
}
return builder.build();
}
示例3: isInitialized
import com.google.protobuf.Descriptors.Descriptor; //導入方法依賴的package包/類
private static boolean isInitialized(Descriptor type,
FieldSet<FieldDescriptor> fields) {
// Check that all required fields are present.
for (final FieldDescriptor field : type.getFields()) {
if (field.isRequired()) {
if (!fields.hasField(field)) {
return false;
}
}
}
// Check that embedded messages are initialized.
return fields.isInitialized();
}
示例4: getFieldNameMap
import com.google.protobuf.Descriptors.Descriptor; //導入方法依賴的package包/類
private Map<String, FieldDescriptor> getFieldNameMap(Descriptor descriptor) {
if (!fieldNameMaps.containsKey(descriptor)) {
Map<String, FieldDescriptor> fieldNameMap = new HashMap<String, FieldDescriptor>();
for (FieldDescriptor field : descriptor.getFields()) {
fieldNameMap.put(field.getName(), field);
fieldNameMap.put(field.getJsonName(), field);
}
fieldNameMaps.put(descriptor, fieldNameMap);
return fieldNameMap;
}
return fieldNameMaps.get(descriptor);
}