Search in sources :

Example 11 with Descriptor

use of com.google.protobuf.Descriptors.Descriptor in project core-java by SpineEventEngine.

the class ReferenceValidator method findSourceFieldByName.

/**
 * Searches for the event/context field with the name retrieved from the
 * enrichment field {@code by} option.
 *
 * @param name            the name of the searched field
 * @param enrichmentField the field of the enrichment targeted onto the searched field
 * @param strict          if {@code true} the field must be found, an exception is thrown
 *                        otherwise.
 *                        <p>If {@code false} {@code null} will be returned upon an
 *                        unsuccessful search
 * @return {@link FieldDescriptor} for the field with the given name or {@code null} if the
 * field is absent and if not in the strict mode
 */
private FieldDescriptor findSourceFieldByName(String name, FieldDescriptor enrichmentField, boolean strict) {
    checkSourceFieldName(name, enrichmentField);
    final Descriptor srcMessage = getSrcMessage(name);
    final FieldDescriptor field = findField(name, srcMessage);
    if (field == null && strict) {
        throw noFieldException(name, srcMessage, enrichmentField);
    }
    return field;
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 12 with Descriptor

use of com.google.protobuf.Descriptors.Descriptor in project j2objc by google.

the class CompatibilityTest method testExtensionRegistryGetUnmodifiable.

public void testExtensionRegistryGetUnmodifiable() throws Exception {
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    ExtensionRegistry registry2 = registry.getUnmodifiable();
    registry.add(Typical.myPrimitiveExtension);
    // Extension added to registry should be visible in registry2.
    Descriptor descriptor = TypicalData.getDescriptor();
    ExtensionRegistry.ExtensionInfo extensionInfo = registry2.findExtensionByNumber(descriptor, 1001);
    assertNotNull(extensionInfo);
    ExtensionRegistryLite registryLite = ExtensionRegistryLite.newInstance();
    ExtensionRegistryLite registryLite2 = registryLite.getUnmodifiable();
    assertNotNull(registryLite2);
}
Also used : ExtensionRegistryLite(com.google.protobuf.ExtensionRegistryLite) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Example 13 with Descriptor

use of com.google.protobuf.Descriptors.Descriptor in project j2objc by google.

the class CompatibilityTest method testEnumDescriptor.

public void testEnumDescriptor() throws Exception {
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    FieldDescriptor fieldDescriptor = descriptor.findFieldByNumber(3);
    assertEquals(Type.ENUM, fieldDescriptor.getType());
    EnumDescriptor enumDescriptor = fieldDescriptor.getEnumType();
    assertNotNull(enumDescriptor);
    EnumValueDescriptor enumValueDescriptor = enumDescriptor.findValueByNumber(1);
    assertEquals(1, enumValueDescriptor.getNumber());
    assertEquals("VALUE1", enumValueDescriptor.getName());
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 14 with Descriptor

use of com.google.protobuf.Descriptors.Descriptor in project j2objc by google.

the class CompatibilityTest method testClearFieldWithDescriptor.

public void testClearFieldWithDescriptor() throws Exception {
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    FieldDescriptor intField = descriptor.findFieldByNumber(1);
    FieldDescriptor repeatedIntField = descriptor.findFieldByNumber(4);
    TypicalData.Builder dataBuilder = TypicalData.newBuilder().setMyInt(42).addRepeatedInt32(43).addRepeatedInt32(44);
    assertEquals(42, dataBuilder.getMyInt());
    dataBuilder.clearField(intField);
    assertFalse(dataBuilder.hasMyInt());
    assertEquals(2, dataBuilder.getRepeatedInt32Count());
    dataBuilder.clearField(repeatedIntField);
    assertEquals(0, dataBuilder.getRepeatedInt32Count());
}
Also used : TypicalData(protos.TypicalData) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 15 with Descriptor

use of com.google.protobuf.Descriptors.Descriptor in project j2objc by google.

the class CompatibilityTest method testGetMessageType.

public void testGetMessageType() throws Exception {
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    FieldDescriptor fieldDescriptor = descriptor.findFieldByNumber(11);
    Descriptor messageDescriptor = fieldDescriptor.getMessageType();
    assertNotNull(messageDescriptor);
    FieldDescriptor messageFieldDescriptor = messageDescriptor.findFieldByNumber(1);
    assertEquals(1, messageFieldDescriptor.getNumber());
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Aggregations

Descriptor (com.google.protobuf.Descriptors.Descriptor)30 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)26 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)13 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)13 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)4 ArrayList (java.util.ArrayList)4 TypicalData (protos.TypicalData)4 Message (com.google.protobuf.Message)3 HashSet (java.util.HashSet)3 TypicalDataMessage (protos.TypicalDataMessage)3 GenericDescriptor (com.google.protobuf.Descriptors.GenericDescriptor)2 GeneratedMessage (com.google.protobuf.GeneratedMessage)2 ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)1 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)1 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)1 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)1 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)1 VisitsBefore (com.google.api.tools.framework.util.VisitsBefore)1 ByteString (com.google.protobuf.ByteString)1 Descriptors (com.google.protobuf.Descriptors)1