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


Java TType.STRUCT属性代码示例

本文整理汇总了Java中org.apache.thrift.protocol.TType.STRUCT属性的典型用法代码示例。如果您正苦于以下问题:Java TType.STRUCT属性的具体用法?Java TType.STRUCT怎么用?Java TType.STRUCT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.thrift.protocol.TType的用法示例。


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

示例1: stringToTypeId

private byte stringToTypeId(String fieldType) throws TProtocolException {
    switch (fieldType) {
        case "bool":
            return TType.BOOL;
        case "i8":
            return TType.BYTE;
        case "i16":
            return TType.I16;
        case "i32":
            return TType.I32;
        case "i64":
            return TType.I64;
        case "double":
            return TType.DOUBLE;
        case "string":
            return TType.STRING;
        case "struct":
        case "union":
        case "exception":
            return TType.STRUCT;
        case "map":
            return TType.MAP;
        case "set":
            return TType.SET;
        case "list":
            return TType.LIST;
        default:
            throw new TProtocolException(TProtocolException.INVALID_DATA,
                    new Exception("Unknown type identifier " + fieldType));
    }
}
 
开发者ID:degupta,项目名称:human_readable_json_protocol,代码行数:31,代码来源:HumanReadableJsonProtocol.java

示例2: readFieldBegin

public TField readFieldBegin() throws TException {
	StructContext context = (StructContext) peekContext();
	if(context.fieldsStack.isEmpty()) {
     // Empty stack -> returns a TType.STOP
     return new TField();
   }
   String fieldName = context.fieldsStack.peek();

   TField currentField = getTField(context.thriftObject, fieldName);
   //currentField.id
   // IF the field is skiped change the type to void
   Map<Class<?>, List<Short>> filter = threadSafeFieldIds.get();

   if(filter!=null) {
     List<Short> fieldsFiltered =  filter.get(context.thriftObject.getClass());
     if(fieldsFiltered != null && fieldsFiltered.contains(currentField.id)) {
       return new TField(currentField.name, TType.VOID, currentField.id);
     }
   }

   // If the field is a struct push a struct context in the stack
   if (currentField.type == TType.STRUCT) {
     StructContext structContext = new StructContext(fieldName);
     structContext.setDbObject((DBObject) context.dbObject.get(fieldName));
     structContext.thriftObject = getThriftObject(context.thriftObject, fieldName);
     pushContext(structContext);
   }
   return currentField;
}
 
开发者ID:BreizhBeans,项目名称:ThriftMongoBridge,代码行数:29,代码来源:TBSONProtocol.java

示例3: getThriftObject

private Object getThriftObject(Object thriftObject, String fieldName) throws TException {
	try {
     Map<String, ThriftField> classFields = getClassFields(thriftObject);
     ThriftField thriftField = classFields.get(fieldName);

     if(thriftField!=null) {
       switch (thriftField.fieldMetaData.valueMetaData.type) {
         case TType.LIST:
           ListMetaData listMetaData = (ListMetaData) thriftField.fieldMetaData.valueMetaData;
           if( listMetaData.elemMetaData.isStruct()) {
             return ((StructMetaData) listMetaData.elemMetaData).structClass.newInstance();
           }
           return null;
         case TType.SET:
           SetMetaData setMetaData = (SetMetaData) thriftField.fieldMetaData.valueMetaData;
           if( setMetaData.isStruct()) {
             return ((StructMetaData) setMetaData.elemMetaData).structClass.newInstance();
           }
           return null;
         case TType.MAP:
           MapMetaData mapMetaData = (MapMetaData) thriftField.fieldMetaData.valueMetaData;
           if( mapMetaData.valueMetaData.isStruct()) {
             return ((StructMetaData) mapMetaData.valueMetaData).structClass.newInstance();
           }
           return null;
         case TType.STRUCT:
           return ((StructMetaData) thriftField.fieldMetaData.valueMetaData).structClass.newInstance();
       }
     }
		throw new Exception("FieldName not finded name=" + fieldName);
	} catch (Exception exp) {
     throw new TException("Unexpected getListThriftObject fieldName=" + fieldName, exp);
	}
}
 
开发者ID:BreizhBeans,项目名称:ThriftMongoBridge,代码行数:34,代码来源:TBSONProtocol.java

示例4: readMessageBegin

/**
 * Reading methods.
 */
public TMessage readMessageBegin() throws TException {
	byte[] buf = new byte[256];
	ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
	while (true) {
		int readLen = trans_.read(buf, 0, buf.length);
		if (readLen == 0) {
			break;
		}
		out.write(buf, 0, readLen);
		if (readLen < buf.length) {
			break;
		}
	}
	String sb = null;
	try {
		buf = out.toByteArray();
		sb = new String(buf, "UTF-8");
	} catch (UnsupportedEncodingException e1) {
		e1.printStackTrace();
	}
	// System.out.println("读取完毕: sb=" + sb);
	// TODO JSON 格式的检查
	if (sb.charAt(0) != '[' || sb.charAt(sb.length() - 1) != ']') {
		throw new TProtocolException(TProtocolException.INVALID_DATA, "bad format!");
	}
	JSONArray jsonArray = new JSONArray(sb);
	TMessage msg = new TMessage(jsonArray.getString(0), (byte) jsonArray.getInt(1), jsonArray.getInt(2));
	// System.out.println(msg + ", jsonArray.len = " + jsonArray.length());

	if (jsonArray.length() > 3) {
		if (argsTBaseClass == null) {
			try {
				argsTBaseClass = guessTBaseClassByMethodName(msg.name);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if (argsTBaseClass == null) {
			// throw new
			// TProtocolException(TApplicationException.UNKNOWN_METHOD,
			// "Invalid method name: '" + msg.name + "'");
			return new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid);
		}
		@SuppressWarnings("unchecked")
		StructMetaData meta = new StructMetaData(TType.STRUCT, argsTBaseClass);
		msgStruct = new BaseArray(meta, (ArrayJson) jsonArray.get(3));
	}
	return msg;
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:52,代码来源:TSimpleJSONProtocol.java

示例5: BaseArray

@SuppressWarnings("unchecked")
public BaseArray(FieldValueMetaData meta, ArrayJson obj) {
	this.obj = obj;
	this.metaData = meta;
	ARRAY_SIZE = obj.arraySize();
	int addStep = 1;
	if (meta.type == TType.STRUCT) {
		StructMetaData sm = (StructMetaData) meta;
		Map<TFieldIdEnum, FieldMetaData> map = (Map<TFieldIdEnum, FieldMetaData>) FieldMetaData
				.getStructMetaDataMap(sm.structClass);

		if (obj instanceof JSONObject) {
			this.fieldIndex = 1;
			addStep = 2;
			if (map != null && map.size() > 0) {
				elementMetas = new HashMap<String, Map.Entry<TFieldIdEnum, FieldMetaData>>(map.size());
				for (Map.Entry<TFieldIdEnum, FieldMetaData> m : map.entrySet()) {
					TFieldIdEnum k = m.getKey();
					// fieldName <-> metaData
					elementMetas.put(k.getFieldName(), m);
					// id <-> metaData
					elementMetas.put(String.valueOf(k.getThriftFieldId()), m);
				}
			}
			String fieldName = obj.getString(0);
			if (!useId && fieldName.length() > 0) {
				char c0 = fieldName.charAt(0);
				useId = c0 >= '0' && c0 <= '9';
			}
		} else {
			elementMetaArr = map.entrySet().toArray(new Map.Entry[0]);
			Arrays.sort(elementMetaArr, new Comparator<Map.Entry<TFieldIdEnum, FieldMetaData>>() {
				@Override
				public int compare(Entry<TFieldIdEnum, FieldMetaData> o1, Entry<TFieldIdEnum, FieldMetaData> o2) {
					return o1.getKey().getThriftFieldId() - o2.getKey().getThriftFieldId();
				}
			});
		}
	}
	this.addStep = addStep;
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:41,代码来源:BaseArray.java

示例6: isStruct

public boolean isStruct() {
  return type == TType.STRUCT; 
}
 
开发者ID:adityayadav76,项目名称:internet_of_things_simulator,代码行数:3,代码来源:FieldValueMetaData.java

示例7: readOneValue

void readOneValue(TProtocol in, TProtocol out, byte type)
    throws TException {
  switch (type) {
  case TType.LIST:
    readOneList(in, out);
    break;
  case TType.MAP:
    readOneMap(in, out);
    break;
  case TType.SET:
    readOneSet(in, out);
    break;
  case TType.STRUCT:
    readOneStruct(in, out);
    break;
  case TType.STOP:
    break;
  case TType.BOOL:
    out.writeBool(in.readBool());
    break;
  case TType.BYTE:
    out.writeByte(in.readByte());
    break;
  case TType.DOUBLE:
    out.writeDouble(in.readDouble());
    break;
  case TType.I16:
    out.writeI16(in.readI16());
    break;
  case TType.ENUM: // same as i32 => actually never seen in the protocol layer as enums are written as a i32 field
  case TType.I32:
    out.writeI32(in.readI32());
    break;
  case TType.I64:
    out.writeI64(in.readI64());
    break;
  case TType.STRING:
    out.writeBinary(in.readBinary());
    break;
  case TType.VOID:
    break;
  default:
    throw new TException("Unknown type: " + type);
  }
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:45,代码来源:ProtocolReadToWrite.java

示例8: readOneValue

/**
 * @return true when all value is consumed, false when some values is ignored due to the field is not defined in expectedType
 * @throws TException
 */
private boolean readOneValue(TProtocol in, byte type, List<Action> buffer, ThriftType expectedType) throws TException {
  if (expectedType != null && expectedType.getType().getSerializedThriftType() != type) {
    throw new DecodingSchemaMismatchException("the data type does not match the expected thrift structure: expected " + expectedType + " got " + typeName(type));
  }
  boolean hasFieldsIgnored = false;
  switch (type) {
  case TType.LIST:
    hasFieldsIgnored = readOneList(in, buffer, (ListType)expectedType);
    break;
  case TType.MAP:
    hasFieldsIgnored = readOneMap(in, buffer, (MapType)expectedType);
    break;
  case TType.SET:
    hasFieldsIgnored = readOneSet(in, buffer, (SetType)expectedType);
    break;
  case TType.STRUCT:
    hasFieldsIgnored = readOneStruct(in, buffer, (StructType)expectedType);
    break;
  case TType.STOP:
    break;
  case TType.BOOL:
    final boolean bool = in.readBool();
    writeBoolAction(buffer, bool);
    break;
  case TType.BYTE:
    final byte b = in.readByte();
    writeByteAction(buffer, b);
    break;
  case TType.DOUBLE:
    final double d = in.readDouble();
    writeDoubleAction(buffer, d);
    break;
  case TType.I16:
    final short s = in.readI16();
    writeShortAction(buffer, s);
    break;
  case TType.ENUM: // same as i32 => actually never seen in the protocol layer as enums are written as a i32 field
  case TType.I32:
    final int i = in.readI32();
    checkEnum(expectedType,i);
    writeIntAction(buffer, i);
    break;
  case TType.I64:
    final long l = in.readI64();
    writeLongAction(buffer, l);
    break;
  case TType.STRING:
    final ByteBuffer bin = in.readBinary();
    writeStringAction(buffer, bin);
    break;
  case TType.VOID:
    break;
  default:
    throw new TException("Unknown type: " + type);
  }
  return hasFieldsIgnored;
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:61,代码来源:BufferedProtocolReadToWrite.java


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