本文整理汇总了Java中com.google.protobuf.Descriptors.FieldDescriptor.isRepeated方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDescriptor.isRepeated方法的具体用法?Java FieldDescriptor.isRepeated怎么用?Java FieldDescriptor.isRepeated使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.Descriptors.FieldDescriptor
的用法示例。
在下文中一共展示了FieldDescriptor.isRepeated方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllFieldsMutable
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的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: getExtension
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
/** Get the value of an extension. */
@SuppressWarnings("unchecked")
public final <Type> Type getExtension(
final GeneratedExtension<MessageType, Type> extension) {
verifyExtensionContainingType(extension);
FieldDescriptor descriptor = extension.getDescriptor();
final Object value = extensions.getField(descriptor);
if (value == null) {
if (descriptor.isRepeated()) {
return (Type) Collections.emptyList();
} else if (descriptor.getJavaType() ==
FieldDescriptor.JavaType.MESSAGE) {
return (Type) extension.getMessageDefaultInstance();
} else {
return (Type) extension.fromReflectionType(
descriptor.getDefaultValue());
}
} else {
return (Type) extension.fromReflectionType(value);
}
}
示例3: writeTo
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
public void writeTo(final CodedOutputStream output) throws IOException {
final boolean isMessageSet =
getDescriptorForType().getOptions().getMessageSetWireFormat();
for (final Map.Entry<FieldDescriptor, Object> entry :
getAllFields().entrySet()) {
final FieldDescriptor field = entry.getKey();
final Object value = entry.getValue();
if (isMessageSet && field.isExtension() &&
field.getType() == FieldDescriptor.Type.MESSAGE &&
!field.isRepeated()) {
output.writeMessageSetExtension(field.getNumber(), (Message) value);
} else {
FieldSet.writeField(field, value, output);
}
}
final UnknownFieldSet unknownFields = getUnknownFields();
if (isMessageSet) {
unknownFields.writeAsMessageSetTo(output);
} else {
unknownFields.writeTo(output);
}
}
示例4: buildValue
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Object buildValue(
Message.Builder parentBuilder, FieldDescriptor field, Object value) {
if (field.getType() == FieldDescriptor.Type.MESSAGE) {
if (field.isRepeated()) {}
Message.Builder fieldBuilder = parentBuilder.newBuilderForField(field);
return buildMessage(fieldBuilder, (Map<String, Object>) value);
} else if (field.getType() == FieldDescriptor.Type.ENUM) {
return field.getEnumType().findValueByName((String) value);
} else {
switch (field.getType()) {
case FLOAT: // float is a special case
return Float.valueOf(value.toString());
default:
return value;
}
}
}
示例5: convertType
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
/** Returns a GraphQLOutputType generated from a FieldDescriptor. */
static GraphQLOutputType convertType(FieldDescriptor fieldDescriptor) {
final GraphQLOutputType type;
if (fieldDescriptor.getType() == Type.MESSAGE) {
type = getReference(fieldDescriptor.getMessageType());
} else if (fieldDescriptor.getType() == Type.GROUP) {
type = getReference(fieldDescriptor.getMessageType());
} else if (fieldDescriptor.getType() == Type.ENUM) {
type = getReference(fieldDescriptor.getEnumType());
} else {
type = TYPE_MAP.get(fieldDescriptor.getType());
}
if (type == null) {
throw new RuntimeException("Unknown type: " + fieldDescriptor.getType());
}
if (fieldDescriptor.isRepeated()) {
return new GraphQLList(type);
} else {
return type;
}
}
示例6: createProtoBuf
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的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();
}
示例7: printField
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
private static void printField(final FieldDescriptor field,
final Object value,
final TextGenerator generator)
throws IOException {
if (field.isRepeated()) {
// Repeated field. Print each element.
for (final Object element : (List) value) {
printSingleField(field, element, generator);
}
} else {
printSingleField(field, value, generator);
}
}
示例8: isInitialized
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
@Override
public boolean isInitialized() {
for (final FieldDescriptor field : getDescriptorForType().getFields()) {
// Check that all required fields are present.
if (field.isRequired()) {
if (!hasField(field)) {
return false;
}
}
// Check that embedded messages are initialized.
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
if (field.isRepeated()) {
@SuppressWarnings("unchecked") final
List<Message> messageList = (List<Message>) getField(field);
for (final Message element : messageList) {
if (!element.isInitialized()) {
return false;
}
}
} else {
if (hasField(field) && !((Message) getField(field)).isInitialized()) {
return false;
}
}
}
}
return true;
}
示例9: FieldAccessorTable
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
/**
* Construct a FieldAccessorTable for a particular message class. Only
* one FieldAccessorTable should ever be constructed per class.
*
* @param descriptor The type's descriptor.
* @param camelCaseNames The camelcase names of all fields in the message.
* These are used to derive the accessor method names.
* @param messageClass The message type.
* @param builderClass The builder type.
*/
public FieldAccessorTable(
final Descriptor descriptor,
final String[] camelCaseNames,
final Class<? extends GeneratedMessage> messageClass,
final Class<? extends Builder> builderClass) {
this.descriptor = descriptor;
fields = new FieldAccessor[descriptor.getFields().size()];
for (int i = 0; i < fields.length; i++) {
final FieldDescriptor field = descriptor.getFields().get(i);
if (field.isRepeated()) {
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
fields[i] = new RepeatedMessageFieldAccessor(
field, camelCaseNames[i], messageClass, builderClass);
} else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) {
fields[i] = new RepeatedEnumFieldAccessor(
field, camelCaseNames[i], messageClass, builderClass);
} else {
fields[i] = new RepeatedFieldAccessor(
field, camelCaseNames[i], messageClass, builderClass);
}
} else {
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
fields[i] = new SingularMessageFieldAccessor(
field, camelCaseNames[i], messageClass, builderClass);
} else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) {
fields[i] = new SingularEnumFieldAccessor(
field, camelCaseNames[i], messageClass, builderClass);
} else {
fields[i] = new SingularFieldAccessor(
field, camelCaseNames[i], messageClass, builderClass);
}
}
}
}
示例10: printField
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
private void printField(FieldDescriptor field, Object value) throws IOException {
if (preservingProtoFieldNames) {
generator.print("\"" + field.getName() + "\":" + blankOrSpace);
} else {
generator.print("\"" + field.getJsonName() + "\":" + blankOrSpace);
}
if (field.isMapField()) {
printMapFieldValue(field, value);
} else if (field.isRepeated()) {
printRepeatedFieldValue(field, value);
} else {
printSingleFieldValue(field, value);
}
}
示例11: getField
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
public Object getField(final FieldDescriptor field) {
if (field.isRepeated()) {
// The underlying list object is still modifiable at this point.
// Make sure not to expose the modifiable list to the caller.
return Collections.unmodifiableList(
(List) internalGetResult().getField(field));
} else {
return internalGetResult().getField(field);
}
}
示例12: mergeField
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
private void mergeField(FieldDescriptor field, JsonElement json, Message.Builder builder)
throws InvalidProtocolBufferException {
if (field.isRepeated()) {
if (builder.getRepeatedFieldCount(field) > 0) {
throw new InvalidProtocolBufferException(
"Field " + field.getFullName() + " has already been set.");
}
} else {
if (builder.hasField(field)) {
throw new InvalidProtocolBufferException(
"Field " + field.getFullName() + " has already been set.");
}
if (field.getContainingOneof() != null
&& builder.getOneofFieldDescriptor(field.getContainingOneof()) != null) {
FieldDescriptor other = builder.getOneofFieldDescriptor(field.getContainingOneof());
throw new InvalidProtocolBufferException(
"Cannot set field "
+ field.getFullName()
+ " because another field "
+ other.getFullName()
+ " belonging to the same oneof has already been set ");
}
}
if (field.isRepeated() && json instanceof JsonNull) {
// We allow "null" as value for all field types and treat it as if the
// field is not present.
return;
}
if (field.isMapField()) {
mergeMapField(field, json, builder);
} else if (field.isRepeated()) {
mergeRepeatedField(field, json, builder);
} else {
Object value = parseFieldValue(field, json, builder);
if (value != null) {
builder.setField(field, value);
}
}
}
示例13: printField
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
public void printField(FieldDescriptor field, Object value, HtmlGenerator generator) throws IOException {
if (field.isRepeated()) {
// Repeated field. Print each element.
for (Object element : (List<?>) value) {
printSingleField(field, element, generator);
}
} else {
printSingleField(field, value, generator);
}
}
示例14: mustSkipNull
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
/**
* Determines whether we skip processing of the field if it is null. We usually skip null values
* in the JSON to treat them as default, but must actually process the null for {@link Value} and
* {@link NullValue} because it means their value must be set.
*/
private boolean mustSkipNull(FieldDescriptor field) {
if (field.isRepeated()) {
return true;
}
if (field.getJavaType() == JavaType.MESSAGE
&& field.getMessageType() == Value.getDescriptor()) {
return false;
}
if (field.getJavaType() == JavaType.ENUM && field.getEnumType() == NullValue.getDescriptor()) {
return false;
}
return true;
}
示例15: mergeFrom
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
public BuilderType mergeFrom(final Message other) {
if (other.getDescriptorForType() != getDescriptorForType()) {
throw new IllegalArgumentException(
"mergeFrom(Message) can only merge messages of the same type.");
}
// Note: We don't attempt to verify that other's fields have valid
// types. Doing so would be a losing battle. We'd have to verify
// all sub-messages as well, and we'd have to make copies of all of
// them to insure that they don't change after verification (since
// the Message interface itself cannot enforce immutability of
// implementations).
// TODO(kenton): Provide a function somewhere called makeDeepCopy()
// which allows people to make secure deep copies of messages.
for (final Map.Entry<FieldDescriptor, Object> entry :
other.getAllFields().entrySet()) {
final FieldDescriptor field = entry.getKey();
if (field.isRepeated()) {
for (final Object element : (List)entry.getValue()) {
addRepeatedField(field, element);
}
} else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
final Message existingValue = (Message)getField(field);
if (existingValue == existingValue.getDefaultInstanceForType()) {
setField(field, entry.getValue());
} else {
setField(field,
existingValue.newBuilderForType()
.mergeFrom(existingValue)
.mergeFrom((Message)entry.getValue())
.build());
}
} else {
setField(field, entry.getValue());
}
}
mergeUnknownFields(other.getUnknownFields());
return (BuilderType) this;
}