本文整理汇总了Java中com.google.protobuf.MessageOrBuilder.getAllFields方法的典型用法代码示例。如果您正苦于以下问题:Java MessageOrBuilder.getAllFields方法的具体用法?Java MessageOrBuilder.getAllFields怎么用?Java MessageOrBuilder.getAllFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.MessageOrBuilder
的用法示例。
在下文中一共展示了MessageOrBuilder.getAllFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printValue
import com.google.protobuf.MessageOrBuilder; //导入方法依赖的package包/类
/** Prints google.protobuf.Value */
private void printValue(MessageOrBuilder message) throws IOException {
// For a Value message, only the value of the field is formatted.
Map<FieldDescriptor, Object> fields = message.getAllFields();
if (fields.isEmpty()) {
// No value set.
generator.print("null");
return;
}
// A Value message can only have at most one field set (it only contains
// an oneof).
if (fields.size() != 1) {
throw new InvalidProtocolBufferException("Invalid Value type.");
}
for (Map.Entry<FieldDescriptor, Object> entry : fields.entrySet()) {
printSingleFieldValue(entry.getKey(), entry.getValue());
}
}
示例2: writeAllFields
import com.google.protobuf.MessageOrBuilder; //导入方法依赖的package包/类
private void writeAllFields(MessageOrBuilder pb) {
//returns changed fields with values. Map is ordered by id.
Map<Descriptors.FieldDescriptor, Object> changedPbFields = pb.getAllFields();
for (Map.Entry<Descriptors.FieldDescriptor, Object> entry : changedPbFields.entrySet()) {
Descriptors.FieldDescriptor fieldDescriptor = entry.getKey();
if(fieldDescriptor.isExtension()) {
// Field index of an extension field might overlap with a base field.
throw new UnsupportedOperationException(
"Cannot convert Protobuf message with extension field(s)");
}
int fieldIndex = fieldDescriptor.getIndex();
fieldWriters[fieldIndex].writeField(entry.getValue());
}
}