public static Map<String, Object> thriftToMap( org.apache.thrift.TBase thriftObj) { Map<String, Object> ret = new HashMap<>(); int i = 1; TFieldIdEnum field = thriftObj.fieldForId(i); while (field != null) { if (thriftObj.isSet(field)) { Object obj = thriftObj.getFieldValue(field); ret.put(field.getFieldName(), thriftToObject(obj)); } field = thriftObj.fieldForId(++i); } return ret; }
public ThriftRecordReader(File dataFile, Schema schema, ThriftRecordReaderConfig recordReaderConfig) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { this._schema = schema; this._dataFile = dataFile; this._recordReaderConfig = recordReaderConfig; this._thriftClass = initThriftInstanceCreator(); this._bufferIn = RecordReaderUtils.getFileBufferStream(dataFile); this._binaryIn = new TBinaryProtocol(new TIOStreamTransport(_bufferIn)); this._fieldNameToIndexMap = new HashMap(); TBase t = this._thriftClass.newInstance(); int index = 1; TFieldIdEnum fieldIdEnum = null; do { fieldIdEnum = t.fieldForId(index); if (fieldIdEnum != null) { _fieldNameToIndexMap.put(fieldIdEnum.getFieldName(), index); } index = index + 1; } while (fieldIdEnum != null); }
if (_fieldNameToIndexMap.containsKey(fieldName)) { int tFieldId = _fieldNameToIndexMap.get(fieldName); TFieldIdEnum tFieldIdEnum = t.fieldForId(tFieldId); Object thriftValue = t.getFieldValue(tFieldIdEnum); Object value = null;
TFieldIdEnum fieldIdEnum = args.fieldForId(index++); TFieldIdEnum fieldIdEnum = result.fieldForId(index++);
boolean found = false; while (true) { TFieldIdEnum fieldIdEnum = resultObj.fieldForId(index++); if (fieldIdEnum == null) { break; Object realResult = result.getResult(); String fieldName = resultObj.fieldForId(0).getFieldName(); String setMethodName = ThriftUtils.generateSetMethodName(fieldName); String getMethodName = ThriftUtils.generateGetMethodName(fieldName);
boolean found = false; while (true) { TFieldIdEnum fieldIdEnum = resultObj.fieldForId(index++); if (fieldIdEnum == null) { break; Object realResult = result.getResult(); String fieldName = resultObj.fieldForId(0).getFieldName(); String setMethodName = ThriftUtils.generateSetMethodName(fieldName); String getMethodName = ThriftUtils.generateGetMethodName(fieldName);
TFieldIdEnum fieldIdEnum = args.fieldForId(index++); TFieldIdEnum fieldIdEnum = result.fieldForId(index++);
TFieldIdEnum field = args.fieldForId(i + 1);
TFieldIdEnum field = args.fieldForId(i + 1);
int index = 1; while (true) { TFieldIdEnum fieldIdEnum = args.fieldForId(index++); if (fieldIdEnum == null) { break;
TFieldIdEnum fieldIdEnum = resultObj.fieldForId(index++); if (fieldIdEnum == null) { break; Object realResult = (response.getResult()).getReturnVal(); if (realResult != null) { resultObj.setFieldValue(resultObj.fieldForId(0), realResult);
boolean found = false; while (true) { TFieldIdEnum fieldIdEnum = resultObj.fieldForId(index++); if (fieldIdEnum == null) { break; Object realResult = result.getResult(); String fieldName = resultObj.fieldForId(0).getFieldName(); String setMethodName = ThriftUtils.generateSetMethodName(fieldName); String getMethodName = ThriftUtils.generateGetMethodName(fieldName);
TFieldIdEnum field = args.fieldForId( i + 1 );
TFieldIdEnum field = args.fieldForId( i + 1 );
Object realResult = null; while (true) { TFieldIdEnum fieldIdEnum = result.fieldForId(index++); if (fieldIdEnum == null) { if (index == 1) {
private byte[] doSerializeRequest(DefaultRequest request) throws Exception { RpcInvocation rpcInvocation = request.getData(); TMessage message = new TMessage(rpcInvocation.getMethod().getName(), TMessageType.CALL, request.getSeqToInt()); String argsClassName = ThriftUtil.generateArgsClassName( request.getServiceInterface().getName(), rpcInvocation.getMethod().getName()); TBase args = getClazzInstance(argsClassName); Object[] arguments = rpcInvocation.getArguments(); if (arguments != null) { for (int i = 0; i < arguments.length; i++) { if (arguments[i] != null) { args.setFieldValue(args.fieldForId(i + 1), arguments[i]); } } } TMemoryBuffer transport = new TMemoryBuffer(1024); TBinaryProtocol protocol = new TBinaryProtocol(transport); protocol.writeMessageBegin(message); if (!request.isOctoProtocol()) { // 不影响原生thrift解码 RequestHeader requestHeader = MetaUtil.convertRequestToOldProtocolHeader(request); protocol.writeFieldBegin(MTRACE_FIELD_DESC); requestHeader.write(protocol); protocol.writeFieldEnd(); } args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush(); return transport.getArray(); }
TFieldIdEnum field = args.fieldForId(i + 1);
TFieldIdEnum field = args.fieldForId(i + 1);
TFieldIdEnum field = args.fieldForId(i + 1);
TFieldIdEnum field = args.fieldForId(i + 1);