Search in sources :

Example 6 with EnumValueDescriptor

use of org.infinispan.protostream.descriptors.EnumValueDescriptor in project protostream by infinispan.

the class ImportedProtoTypeMetadata method getEnumMemberByName.

@Override
public ProtoEnumValueMetadata getEnumMemberByName(String name) {
    if (!isEnum()) {
        throw new IllegalStateException(getFullName() + " is not an enum");
    }
    EnumValueDescriptor evd = ((EnumDescriptor) descriptor).findValueByName(name);
    if (evd == null) {
        return null;
    }
    Enum<?> enumConstant = ((EnumMarshaller) marshaller).decode(evd.getNumber());
    return new ProtoEnumValueMetadata(evd.getNumber(), name, enumConstant.ordinal(), enumConstant.getDeclaringClass().getCanonicalName() + '.' + enumConstant.name(), null);
}
Also used : EnumMarshaller(org.infinispan.protostream.EnumMarshaller) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) EnumValueDescriptor(org.infinispan.protostream.descriptors.EnumValueDescriptor)

Aggregations

EnumValueDescriptor (org.infinispan.protostream.descriptors.EnumValueDescriptor)6 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)4 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 EnumDescriptorProto (com.google.protobuf.DescriptorProtos.EnumDescriptorProto)1 IOException (java.io.IOException)1 Date (java.util.Date)1 GuardedBy (net.jcip.annotations.GuardedBy)1 EnumMarshaller (org.infinispan.protostream.EnumMarshaller)1 TagHandler (org.infinispan.protostream.TagHandler)1 AnnotatedDescriptor (org.infinispan.protostream.descriptors.AnnotatedDescriptor)1 Descriptor (org.infinispan.protostream.descriptors.Descriptor)1 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)1 FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)1