use of com.google.protobuf.Descriptors.Descriptor in project j2objc by google.
the class PerformanceBenchmarks method getRepeatedFieldDescriptors.
private static List<FieldDescriptor> getRepeatedFieldDescriptors() {
Descriptor descriptor = TypicalData.Builder.getDescriptor();
List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>();
fields.add(descriptor.findFieldByNumber(4));
fields.add(descriptor.findFieldByNumber(19));
fields.add(descriptor.findFieldByNumber(20));
fields.add(descriptor.findFieldByNumber(21));
fields.add(descriptor.findFieldByNumber(5));
fields.add(descriptor.findFieldByNumber(6));
fields.add(descriptor.findFieldByNumber(7));
fields.add(descriptor.findFieldByNumber(8));
fields.add(descriptor.findFieldByNumber(9));
fields.add(descriptor.findFieldByNumber(10));
return fields;
}
use of com.google.protobuf.Descriptors.Descriptor in project j2objc by google.
the class PerformanceBenchmarks method getPrimitiveFieldDescriptors.
private static List<FieldDescriptor> getPrimitiveFieldDescriptors() {
Descriptor descriptor = TypicalData.Builder.getDescriptor();
List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>();
fields.add(descriptor.findFieldByNumber(1));
fields.add(descriptor.findFieldByNumber(12));
fields.add(descriptor.findFieldByNumber(13));
fields.add(descriptor.findFieldByNumber(14));
fields.add(descriptor.findFieldByNumber(16));
fields.add(descriptor.findFieldByNumber(17));
fields.add(descriptor.findFieldByNumber(18));
return fields;
}
use of com.google.protobuf.Descriptors.Descriptor in project core-java by SpineEventEngine.
the class MessageValidator method validateAlternativeFields.
private void validateAlternativeFields(Message message, ImmutableList.Builder<ConstraintViolation> result) {
final Descriptor typeDescr = message.getDescriptorForType();
final AlternativeFieldValidator altFieldValidator = new AlternativeFieldValidator(typeDescr, rootFieldPath);
result.addAll(altFieldValidator.validate(message));
}
use of com.google.protobuf.Descriptors.Descriptor in project core-java by SpineEventEngine.
the class ReferenceValidator method findSourceFieldsByNames.
private Collection<FieldDescriptor> findSourceFieldsByNames(String[] names, FieldDescriptor enrichmentField) {
checkArgument(names.length > 0, "Names may not be empty");
checkArgument(names.length > 1, "Enrichment target field names may not be a singleton array. " + "Use findSourceFieldByName().");
final Collection<FieldDescriptor> result = new HashSet<>(names.length);
FieldDescriptor.Type basicType = null;
Descriptor messageType = null;
for (String name : names) {
final FieldDescriptor field = findSourceFieldByName(name, enrichmentField, false);
if (field == null) {
/* We don't know at this stage the type of the event.
The enrichment is to be included anyway,
but by other ReferenceValidator instance */
continue;
}
if (basicType == null) {
// Get type of the first field
basicType = field.getType();
if (basicType == MESSAGE) {
messageType = field.getMessageType();
}
} else {
// Compare the type with each of the next
checkState(basicType == field.getType(), differentTypesErrorMessage(enrichmentField));
if (basicType == MESSAGE) {
checkState(messageType.equals(field.getMessageType()), differentTypesErrorMessage(enrichmentField));
}
}
final boolean noDuplicateFiled = result.add(field);
checkState(noDuplicateFiled, "Enrichment target field names may contain no duplicates. " + "Found duplicate field: %s", name);
}
return result;
}
use of com.google.protobuf.Descriptors.Descriptor in project beam by apache.
the class ProtobufUtil method getRecursiveDescriptorsForClass.
/**
* Returns the {@link Descriptor} for the given Protocol Buffers {@link Message} as well as
* every class it can include transitively.
*
* @throws IllegalArgumentException if there is an error in Java reflection.
*/
static Set<Descriptor> getRecursiveDescriptorsForClass(Class<? extends Message> clazz, ExtensionRegistry registry) {
Descriptor root = getDescriptorForClass(clazz);
Set<Descriptor> descriptors = new HashSet<>();
recursivelyAddDescriptors(root, descriptors, registry);
return descriptors;
}
Aggregations