本文整理汇总了Java中org.apache.thrift.protocol.TType.I32属性的典型用法代码示例。如果您正苦于以下问题:Java TType.I32属性的具体用法?Java TType.I32怎么用?Java TType.I32使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.thrift.protocol.TType
的用法示例。
在下文中一共展示了TType.I32属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTField
private TField getTField(Object thriftObject, String fieldName) throws TException {
try {
Map<String, ThriftField> classFields = getClassFields(thriftObject);
ThriftField thriftField = classFields.get(fieldName);
if(thriftField==null) {
// Empty field -> skip
return new TField();
}
byte type = thriftField.fieldMetaData.valueMetaData.type;
short id = thriftField.tfieldIdEnum.getThriftFieldId();
// An enum type is deserialized as an I32
if (TType.ENUM == type) {
type = TType.I32;
}
return new TField("", type, id);
} catch (Exception exp) {
throw new TException("Unexpected getTField fieldName=" + fieldName, exp);
}
}
示例2: write
public void write(TProtocol oprot) throws TException {
TStruct struct = new TStruct("TApplicationException");
TField field = new TField();
oprot.writeStructBegin(struct);
if (getMessage() != null) {
field.name = "message";
field.type = TType.STRING;
field.id = 1;
oprot.writeFieldBegin(field);
oprot.writeString(getMessage());
oprot.writeFieldEnd();
}
field.name = "type";
field.type = TType.I32;
field.id = 2;
oprot.writeFieldBegin(field);
oprot.writeI32(type_);
oprot.writeFieldEnd();
oprot.writeFieldStop();
oprot.writeStructEnd();
}
示例3: read
public static TApplicationException read(TProtocol iprot) throws TException {
TField field;
iprot.readStructBegin();
String message = null;
int type = UNKNOWN;
while (true) {
field = iprot.readFieldBegin();
if (field.type == TType.STOP) {
break;
}
switch (field.id) {
case 1:
if (field.type == TType.STRING) {
message = iprot.readString();
} else {
TProtocolUtil.skip(iprot, field.type);
}
break;
case 2:
if (field.type == TType.I32) {
type = iprot.readI32();
} else {
TProtocolUtil.skip(iprot, field.type);
}
break;
default:
TProtocolUtil.skip(iprot, field.type);
break;
}
iprot.readFieldEnd();
}
iprot.readStructEnd();
return new TApplicationException(type, message);
}
示例4: 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));
}
}
示例5: read
/**
* Reads a {@link TApplicationException} from the specified {@link TProtocol}.
*
* <p>Note: This has been copied from {@link TApplicationException#read(TProtocol)} due to API differences
* between libthrift 0.9.x and 0.10.x.
*/
public static TApplicationException read(TProtocol iprot) throws TException {
TField field;
iprot.readStructBegin();
String message = null;
int type = TApplicationException.UNKNOWN;
while (true) {
field = iprot.readFieldBegin();
if (field.type == TType.STOP) {
break;
}
switch (field.id) {
case 1:
if (field.type == TType.STRING) {
message = iprot.readString();
} else {
TProtocolUtil.skip(iprot, field.type);
}
break;
case 2:
if (field.type == TType.I32) {
type = iprot.readI32();
} else {
TProtocolUtil.skip(iprot, field.type);
}
break;
default:
TProtocolUtil.skip(iprot, field.type);
break;
}
iprot.readFieldEnd();
}
iprot.readStructEnd();
return new TApplicationException(type, message);
}
示例6: getCurrentFieldValue
private Object getCurrentFieldValue(byte ttype) {
Context context = peekContext();
if( context instanceof StructContext && ((StructContext)context).fieldsStack.isEmpty() == false ) {
String fieldName = ((StructContext)context).fieldsStack.peek();
// Extracts the dbobject
Object fieldReaded = context.dbObject.get(fieldName);
return fieldReaded;
} else if(context instanceof ListContext) {
return ((ListContext)context).next();
} else if(context instanceof MapContext) {
// IF YOU READ A KEY YOU MUST CONVERT THE STRING INTO NUMBER
if( ((MapContext)context).isNextKey()) {
switch( ttype ) {
case TType.BYTE:
return Byte.parseByte((String)((MapContext)context).next());
case TType.I32:
case TType.I16:
return Integer.parseInt((String)((MapContext)context).next());
case TType.I64:
return Long.parseLong((String)((MapContext)context).next());
case TType.DOUBLE:
return Double.parseDouble((String)((MapContext)context).next());
}
}
return ((MapContext)context).next();
}
return null;
}
示例7: getTType
@Override
public byte getTType() {
return TType.I32;
}
示例8: partialDeserializeField
private Object partialDeserializeField(byte ttype, byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum ... fieldIdPathRest) throws TException {
try {
TField field = locateField(bytes, fieldIdPathFirst, fieldIdPathRest);
if (field != null) {
// if this point is reached, iprot will be positioned at the start of the field.
switch(ttype){
case TType.BOOL:
if (field.type == TType.BOOL){
return protocol_.readBool();
}
break;
case TType.BYTE:
if (field.type == TType.BYTE) {
return protocol_.readByte();
}
break;
case TType.DOUBLE:
if (field.type == TType.DOUBLE) {
return protocol_.readDouble();
}
break;
case TType.I16:
if (field.type == TType.I16) {
return protocol_.readI16();
}
break;
case TType.I32:
if (field.type == TType.I32) {
return protocol_.readI32();
}
break;
case TType.I64:
if (field.type == TType.I64) {
return protocol_.readI64();
}
break;
case TType.STRING:
if (field.type == TType.STRING) {
return protocol_.readString();
}
break;
case 100: // hack to differentiate between string and binary
if (field.type == TType.STRING) {
return protocol_.readBinary();
}
break;
}
}
return null;
} catch (Exception e) {
throw new TException(e);
} finally {
trans_.clear();
protocol_.reset();
}
}
示例9: toTypeSignature
@VisibleForTesting
static TypeSignature toTypeSignature(FieldValueMetaData fieldValueMetaData) {
if (fieldValueMetaData instanceof StructMetaData) {
return TypeSignature.ofNamed(((StructMetaData) fieldValueMetaData).structClass);
}
if (fieldValueMetaData instanceof EnumMetaData) {
return TypeSignature.ofNamed(((EnumMetaData) fieldValueMetaData).enumClass);
}
if (fieldValueMetaData instanceof ListMetaData) {
return TypeSignature.ofList(toTypeSignature(((ListMetaData) fieldValueMetaData).elemMetaData));
}
if (fieldValueMetaData instanceof SetMetaData) {
return TypeSignature.ofSet(toTypeSignature(((SetMetaData) fieldValueMetaData).elemMetaData));
}
if (fieldValueMetaData instanceof MapMetaData) {
return TypeSignature.ofMap(toTypeSignature(((MapMetaData) fieldValueMetaData).keyMetaData),
toTypeSignature(((MapMetaData) fieldValueMetaData).valueMetaData));
}
if (fieldValueMetaData.isBinary()) {
return BINARY;
}
switch (fieldValueMetaData.type) {
case TType.VOID:
return VOID;
case TType.BOOL:
return BOOL;
case TType.BYTE:
return I8;
case TType.DOUBLE:
return DOUBLE;
case TType.I16:
return I16;
case TType.I32:
return I32;
case TType.I64:
return I64;
case TType.STRING:
return STRING;
}
final String unresolvedName;
if (fieldValueMetaData.isTypedef()) {
unresolvedName = fieldValueMetaData.getTypedefName();
} else {
unresolvedName = null;
}
return TypeSignature.ofUnresolved(firstNonNull(unresolvedName, "unknown"));
}
示例10: computeFieldNameMap
/**
* Compute a new field name map for the current thrift message
* we are parsing.
*/
private Map<String, TField> computeFieldNameMap(Class<?> clazz) {
Map<String, TField> map = new HashMap<>();
if (isTBase(clazz)) {
// Get the metaDataMap for this Thrift class
@SuppressWarnings("unchecked")
Map<? extends TFieldIdEnum, FieldMetaData> metaDataMap =
FieldMetaData.getStructMetaDataMap((Class<? extends TBase<?, ?>>) clazz);
for (Entry<? extends TFieldIdEnum, FieldMetaData> e : metaDataMap.entrySet()) {
final String fieldName = e.getKey().getFieldName();
final FieldMetaData metaData = e.getValue();
final FieldValueMetaData elementMetaData;
if (metaData.valueMetaData.isContainer()) {
if (metaData.valueMetaData instanceof SetMetaData) {
elementMetaData = ((SetMetaData) metaData.valueMetaData).elemMetaData;
} else if (metaData.valueMetaData instanceof ListMetaData) {
elementMetaData = ((ListMetaData) metaData.valueMetaData).elemMetaData;
} else if (metaData.valueMetaData instanceof MapMetaData) {
elementMetaData = ((MapMetaData) metaData.valueMetaData).valueMetaData;
} else {
// Unrecognized container type, but let's still continue processing without
// special enum support.
elementMetaData = metaData.valueMetaData;
}
} else {
elementMetaData = metaData.valueMetaData;
}
if (elementMetaData instanceof EnumMetaData) {
classMap.put(fieldName, ((EnumMetaData) elementMetaData).enumClass);
} else if (elementMetaData instanceof StructMetaData) {
classMap.put(fieldName, ((StructMetaData) elementMetaData).structClass);
}
// 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,
e.getKey().getThriftFieldId()));
}
} else { // TApplicationException
map.put("message", new TField("message", (byte)11, (short)1));
map.put("type", new TField("type", (byte)8, (short)2));
}
return map;
}
示例11: 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);
}
}
示例12: 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;
}