Search in sources :

Example 6 with Descriptor

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;
}
Also used : ArrayList(java.util.ArrayList) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 7 with Descriptor

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;
}
Also used : ArrayList(java.util.ArrayList) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 8 with Descriptor

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));
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 9 with Descriptor

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;
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) HashSet(java.util.HashSet) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 10 with Descriptor

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;
}
Also used : GenericDescriptor(com.google.protobuf.Descriptors.GenericDescriptor) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) HashSet(java.util.HashSet)

Aggregations

Descriptor (com.google.protobuf.Descriptors.Descriptor)25 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)22 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)13 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)13 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)4 TypicalData (protos.TypicalData)4 ArrayList (java.util.ArrayList)3 TypicalDataMessage (protos.TypicalDataMessage)3 GenericDescriptor (com.google.protobuf.Descriptors.GenericDescriptor)2 GeneratedMessage (com.google.protobuf.GeneratedMessage)2 HashSet (java.util.HashSet)2 ByteString (com.google.protobuf.ByteString)1 Descriptors (com.google.protobuf.Descriptors)1 Type (com.google.protobuf.Descriptors.FieldDescriptor.Type)1 ExtensionRegistryLite (com.google.protobuf.ExtensionRegistryLite)1 ExtendableMessageOrBuilder (com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder)1 Message (com.google.protobuf.Message)1 KnownTypes.getDescriptor (io.spine.type.KnownTypes.getDescriptor)1 TypeUrl (io.spine.type.TypeUrl)1 NonDeterministicException (org.apache.beam.sdk.coders.Coder.NonDeterministicException)1