当前位置: 首页>>代码示例>>Java>>正文


Java TEnum类代码示例

本文整理汇总了Java中org.apache.thrift.TEnum的典型用法代码示例。如果您正苦于以下问题:Java TEnum类的具体用法?Java TEnum怎么用?Java TEnum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TEnum类属于org.apache.thrift包,在下文中一共展示了TEnum类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readI32

import org.apache.thrift.TEnum; //导入依赖的package包/类
@Override
public int readI32() throws TException {
    Class<?> fieldClass = getCurrentFieldClassIfIs(TEnum.class);
    if (fieldClass != null) {
        // Enum fields may be set by string, even though they represent integers.
        getCurrentContext().read();
        JsonNode elem = getCurrentContext().getCurrentChild();
        if (elem.isInt()) {
            return TypedParser.INTEGER.readFromJsonElement(elem);
        } else if (elem.isTextual()) {
            // All TEnum are enums
            @SuppressWarnings({ "unchecked", "rawtypes" })
            TEnum tEnum = (TEnum) Enum.valueOf((Class<Enum>) fieldClass,
                                               TypedParser.STRING.readFromJsonElement(elem));
            return tEnum.getValue();
        } else {
            throw new TTransportException("invalid value type for enum field: " + elem.getNodeType() +
                                          " (" + elem + ')');
        }
    } else {
        return readNameOrValue(TypedParser.INTEGER);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:24,代码来源:TTextProtocol.java

示例2: EnumMetaData

import org.apache.thrift.TEnum; //导入依赖的package包/类
public EnumMetaData(byte type, Class<? extends TEnum> sClass){
  super(type);
  this.enumClass = sClass;
}
 
开发者ID:adityayadav76,项目名称:internet_of_things_simulator,代码行数:5,代码来源:EnumMetaData.java

示例3: toThriftField

import org.apache.thrift.TEnum; //导入依赖的package包/类
private static ThriftField toThriftField(String name, Field field, ThriftField.Requirement requirement) {
  ThriftType type;
  switch (ThriftTypeID.fromByte(field.getType())) {
    case STOP:
    case VOID:
    default:
      throw new UnsupportedOperationException("can't convert type of " + field);
    case BOOL:
      type = new BoolType();
      break;
    case BYTE:
      type = new ByteType();
      break;
    case DOUBLE:
      type = new DoubleType();
      break;
    case I16:
      type = new I16Type();
      break;
    case I32:
      type = new I32Type();
      break;
    case I64:
      type = new I64Type();
      break;
    case STRING:
      StringType stringType = new StringType();
      FieldMetaData fieldMetaData = field.getFieldMetaData();
      // There is no real binary type (see THRIFT-1920) in Thrift,
      // binary data is represented by String type with an additional binary flag.
      if (fieldMetaData != null && fieldMetaData.valueMetaData.isBinary()) {
        stringType.setBinary(true);
      }
      type = stringType;
      break;
    case STRUCT:
      type = toStructType(field.gettStructDescriptor());
      break;
    case MAP:
      final Field mapKeyField = field.getMapKeyField();
      final Field mapValueField = field.getMapValueField();
      type = new ThriftType.MapType(
          toThriftField(mapKeyField.getName(), mapKeyField, requirement),
          toThriftField(mapValueField.getName(), mapValueField, requirement));
      break;
    case SET:
      final Field setElemField = field.getSetElemField();
      type = new ThriftType.SetType(toThriftField(setElemField.getName(), setElemField, requirement));
      break;
    case LIST:
      final Field listElemField = field.getListElemField();
      type = new ThriftType.ListType(toThriftField(listElemField.getName(), listElemField, requirement));
      break;
    case ENUM:
      Collection<TEnum> enumValues = field.getEnumValues();
      List<EnumValue> values = new ArrayList<ThriftType.EnumValue>();
      for (TEnum tEnum : enumValues) {
        values.add(new EnumValue(tEnum.getValue(), tEnum.toString()));
      }
      type = new EnumType(values);
      break;
  }
  return new ThriftField(name, field.getId(), requirement, type);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:65,代码来源:ThriftSchemaConverter.java


注:本文中的org.apache.thrift.TEnum类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。