本文整理汇总了Java中org.apache.thrift.protocol.TType.MAP属性的典型用法代码示例。如果您正苦于以下问题:Java TType.MAP属性的具体用法?Java TType.MAP怎么用?Java TType.MAP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.thrift.protocol.TType
的用法示例。
在下文中一共展示了TType.MAP属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
示例2: 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);
}
}
示例3: getTType
@Override
public byte getTType() {
return TType.MAP;
}
示例4: isContainer
public boolean isContainer() {
return type == TType.LIST || type == TType.MAP || type == TType.SET;
}
示例5: 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);
}
}
示例6: 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;
}
示例7: secureThriftFields
public void secureThriftFields(Class<? extends TBase> tbase, boolean hash, TFieldIdEnum... fields) throws Exception {
Map<Short, ThriftSecuredField> classSecuredFields = securedFields.get(tbase);
if(classSecuredFields==null) {
classSecuredFields = new ConcurrentHashMap<>();
}
// get the Field class
Class<?> fieldClass = null;
Class<?>[] innerClasses = tbase.getClasses();
for (Class<?> innerClass : innerClasses) {
if ("_Fields".equals(innerClass.getSimpleName())) {
fieldClass = innerClass;
break;
}
}
// extract _Fields
Class[] findByNameArgs = new Class[1];
findByNameArgs[0] = String.class;
Method findByNameMethod = fieldClass.getMethod("findByName", findByNameArgs);
// extract metadataMap
Field metafaField = tbase.getField("metaDataMap");
Map<?, FieldMetaData> metaDataMap = (Map<?, org.apache.thrift.meta_data.FieldMetaData>) metafaField.get(tbase);
for(TFieldIdEnum field : fields) {
// get the _Field instance
org.apache.thrift.TFieldIdEnum tfieldEnum = (TFieldIdEnum) findByNameMethod.invoke(null, field.getFieldName());
// get the matadata
FieldMetaData fieldMetaData = metaDataMap.get(tfieldEnum);
// only string are supported
switch(fieldMetaData.valueMetaData.type) {
case TType.STRING:
break;
case TType.MAP:
MapMetaData mapMetaData = (MapMetaData) fieldMetaData.valueMetaData;
if (mapMetaData.valueMetaData.type != TType.STRING) {
throw new UnsupportedTTypeException("Unsupported secured type - FIELD:" + field.getFieldName() + " TYPE:" + mapMetaData.valueMetaData.type);
}
break;
default:
throw new UnsupportedTTypeException("Unsupported secured type - FIELD:" + field.getFieldName() + " TYPE:" + fieldMetaData.valueMetaData.type);
}
classSecuredFields.put(field.getThriftFieldId(), new ThriftSecuredField(true, hash));
}
securedFields.put(tbase,classSecuredFields);
}