Search in sources :

Example 6 with TFieldIdEnum

use of org.apache.thrift.TFieldIdEnum in project commons by twitter.

the class StructContext method computeFieldNameMap.

/**
   * Compute a new field name map for the current thrift message
   * we are parsing.
   */
private Map<String, TField> computeFieldNameMap() {
    Map<String, TField> map = new HashMap<String, TField>();
    Class<? extends TBase> clazz = getCurrentThriftMessageClass();
    // Get the metaDataMap for this Thrift class
    Map<? extends TFieldIdEnum, FieldMetaData> metaDataMap = FieldMetaData.getStructMetaDataMap(clazz);
    for (TFieldIdEnum key : metaDataMap.keySet()) {
        final String fieldName = key.getFieldName();
        final FieldMetaData metaData = metaDataMap.get(key);
        // Workaround a bug in the generated thrift message read()
        // method by mapping the ENUM type to the INT32 type
        // The thrift generated parsing code requires that, when expecting
        // a value of enum, we actually parse a value of type int32. The
        // generated read() method then looks up the enum value in a map.
        byte type = (TType.ENUM == metaData.valueMetaData.type) ? TType.I32 : metaData.valueMetaData.type;
        map.put(fieldName, new TField(fieldName, type, key.getThriftFieldId()));
    }
    return map;
}
Also used : FieldMetaData(org.apache.thrift.meta_data.FieldMetaData) TField(org.apache.thrift.protocol.TField) HashMap(java.util.HashMap) TFieldIdEnum(org.apache.thrift.TFieldIdEnum)

Aggregations

TFieldIdEnum (org.apache.thrift.TFieldIdEnum)6 RpcException (com.alibaba.dubbo.rpc.RpcException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 TBase (org.apache.thrift.TBase)3 TException (org.apache.thrift.TException)3 TMessage (org.apache.thrift.protocol.TMessage)3 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)2 RpcResult (com.alibaba.dubbo.rpc.RpcResult)2 RandomAccessByteArrayOutputStream (com.alibaba.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream)2 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 TApplicationException (org.apache.thrift.TApplicationException)2 FieldMetaData (org.apache.thrift.meta_data.FieldMetaData)2 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)2 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)2 Request (com.alibaba.dubbo.remoting.exchange.Request)1 Response (com.alibaba.dubbo.remoting.exchange.Response)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1