Search in sources :

Example 6 with FieldDescriptor

use of org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor in project hbase by apache.

the class AbstractMessage method hashFields.

/** Get a hash code for given fields and values, using the given seed. */
@SuppressWarnings("unchecked")
protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
    for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
        FieldDescriptor field = entry.getKey();
        Object value = entry.getValue();
        hash = (37 * hash) + field.getNumber();
        if (field.isMapField()) {
            hash = (53 * hash) + hashMapField(value);
        } else if (field.getType() != FieldDescriptor.Type.ENUM) {
            hash = (53 * hash) + value.hashCode();
        } else if (field.isRepeated()) {
            List<? extends EnumLite> list = (List<? extends EnumLite>) value;
            hash = (53 * hash) + Internal.hashEnumList(list);
        } else {
            hash = (53 * hash) + Internal.hashEnum((EnumLite) value);
        }
    }
    return hash;
}
Also used : EnumLite(org.apache.hadoop.hbase.shaded.com.google.protobuf.Internal.EnumLite) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) FieldDescriptor(org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor)

Example 7 with FieldDescriptor

use of org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor in project hbase by apache.

the class DynamicMessage method hasOneof.

@Override
public boolean hasOneof(OneofDescriptor oneof) {
    verifyOneofContainingType(oneof);
    FieldDescriptor field = oneofCases[oneof.getIndex()];
    if (field == null) {
        return false;
    }
    return true;
}
Also used : FieldDescriptor(org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor)

Example 8 with FieldDescriptor

use of org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor in project hbase by apache.

the class ExtensionRegistry method add.

private void add(final ExtensionInfo extension, final Extension.ExtensionType extensionType) {
    if (!extension.descriptor.isExtension()) {
        throw new IllegalArgumentException("ExtensionRegistry.add() was given a FieldDescriptor for a regular " + "(non-extension) field.");
    }
    Map<String, ExtensionInfo> extensionsByName;
    Map<DescriptorIntPair, ExtensionInfo> extensionsByNumber;
    switch(extensionType) {
        case IMMUTABLE:
            extensionsByName = immutableExtensionsByName;
            extensionsByNumber = immutableExtensionsByNumber;
            break;
        case MUTABLE:
            extensionsByName = mutableExtensionsByName;
            extensionsByNumber = mutableExtensionsByNumber;
            break;
        default:
            // Ignore the unknown supported type.
            return;
    }
    extensionsByName.put(extension.descriptor.getFullName(), extension);
    extensionsByNumber.put(new DescriptorIntPair(extension.descriptor.getContainingType(), extension.descriptor.getNumber()), extension);
    final FieldDescriptor field = extension.descriptor;
    if (field.getContainingType().getOptions().getMessageSetWireFormat() && field.getType() == FieldDescriptor.Type.MESSAGE && field.isOptional() && field.getExtensionScope() == field.getMessageType()) {
        // This is an extension of a MessageSet type defined within the extension
        // type's own scope.  For backwards-compatibility, allow it to be looked
        // up by type name.
        extensionsByName.put(field.getMessageType().getFullName(), extension);
    }
}
Also used : FieldDescriptor(org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor)

Aggregations

FieldDescriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor)8 List (java.util.List)4 TreeMap (java.util.TreeMap)4 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 Descriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.Descriptor)2 EnumDescriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.EnumDescriptor)2 EnumValueDescriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.EnumValueDescriptor)2 FileDescriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FileDescriptor)2 OneofDescriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.OneofDescriptor)2 HashMap (java.util.HashMap)1 EnumLite (org.apache.hadoop.hbase.shaded.com.google.protobuf.Internal.EnumLite)1