Java 类org.apache.thrift.protocol.TType 实例源码

项目:jigsaw-payment    文件:TProtobufProcessor.java   
@Override
public boolean process(TProtocol in, TProtocol out) throws TException {
    TMessage msg = in.readMessageBegin();
    Controller<?, ?> fn = (Controller<?, ?>) this.beanFactory
            .getBean(msg.name);
    if (fn == null) {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.warn("Invalid request: failed to find interface="
                    + msg.name + ", from: " + getInetAddress(in));
        }

        TProtocolUtil.skip(in, TType.STRUCT);
        in.readMessageEnd();
        TApplicationException x = new TApplicationException(
                TApplicationException.UNKNOWN_METHOD,
                "Invalid method name: '" + msg.name + "'");
        out.writeMessageBegin(new TMessage(msg.name,
                TMessageType.EXCEPTION, msg.seqid));
        x.write(out);
        out.writeMessageEnd();
        out.getTransport().flush();
        return true;
    }
    process(msg.seqid, msg.name, in, out, fn);
    return true;
}
项目:gemfirexd-oss    文件:LocatorServiceImpl.java   
@Override
public final boolean process(final TProtocol in, final TProtocol out)
    throws TException {
  final TMessage msg = in.readMessageBegin();
  final ProcessFunction<LocatorServiceImpl, ?> fn = this.fnMap
      .get(msg.name);
  if (fn != null) {
    fn.process(msg.seqid, in, out, this.inst);
    // terminate connection on receiving closeConnection
    // direct class comparison should be the fastest way
    return fn.getClass() != LocatorService.Processor.closeConnection.class;
  }
  else {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(
        TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
            + msg.name + "'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
        msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
}
项目:ikasoa    文件:AbstractThriftBase.java   
/**
 * 读取操作
 */
@Override
public void read(TProtocol iprot) throws TException {
    if (!"org.apache.thrift.scheme.StandardScheme".equals(iprot.getScheme().getName()))
        throw new TApplicationException("Service scheme must be 'org.apache.thrift.scheme.StandardScheme' !");
    TField schemeField;
    iprot.readStructBegin();
    while (Boolean.TRUE) {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == TType.STOP)
            break;
        if (schemeField.type == TType.STRING)
            str = iprot.readString();
        else
            throw new TApplicationException("field type must be 'String' !");
        iprot.readFieldEnd();
    }
    iprot.readStructEnd();
}
项目:gemfirexd-oss    文件:LocatorServiceImpl.java   
@Override
public final boolean process(final TProtocol in, final TProtocol out)
    throws TException {
  final TMessage msg = in.readMessageBegin();
  final ProcessFunction<LocatorServiceImpl, ?> fn = this.fnMap
      .get(msg.name);
  if (fn != null) {
    fn.process(msg.seqid, in, out, this.inst);
    // terminate connection on receiving closeConnection
    // direct class comparison should be the fastest way
    return fn.getClass() != LocatorService.Processor.closeConnection.class;
  }
  else {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(
        TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
            + msg.name + "'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
        msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
}
项目:internet_of_things_simulator    文件:TBaseProcessor.java   
@Override
public boolean process(TProtocol in, TProtocol out) throws TException {
  TMessage msg = in.readMessageBegin();
  ProcessFunction fn = processMap.get(msg.name);
  if (fn == null) {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
  fn.process(msg.seqid, in, out, iface);
  return true;
}
项目:human_readable_json_protocol    文件:HumanReadableJsonProtocol.java   
public void parseStruct(JSONArray fieldsList,
                        Object request) throws TProtocolException, JSONException {
    if (!(request instanceof JSONObject)) {
        raiseExpected("JSON Object", request);
    }
    JSONObject jsonObject = (JSONObject) request;

    Iterator<String> it = jsonObject.keys();
    while (it.hasNext()) {
        String key = it.next();
        Object value = jsonObject.get(key);
        JSONObject fieldInfo = findInJsonArray(fieldsList, NAME_KEY, key);
        if (fieldInfo == null) {
            throw new TProtocolException(TProtocolException.INVALID_DATA,
                    new Exception("Unexpected key " + key));
        }

        byte fieldType = stringToTypeId(fieldInfo.getString(TYPE_ID_KEY));
        add(key, fieldType, (short) fieldInfo.optInt(KEY_KEY, 0));
        parse(fieldInfo, value, TYPE_ID_KEY, TYPE_KEY);
    }
    add("", TType.STOP, (short) -1);
}
项目:NeverwinterDP-Commons    文件:scribe.java   
public void write(org.apache.thrift.protocol.TProtocol oprot, Log_args struct) throws org.apache.thrift.TException {
  struct.validate();

  oprot.writeStructBegin(STRUCT_DESC);
  if (struct.messages != null) {
    oprot.writeFieldBegin(MESSAGES_FIELD_DESC);
    {
      oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.messages.size()));
      for (LogEntry _iter3 : struct.messages)
      {
        _iter3.write(oprot);
      }
      oprot.writeListEnd();
    }
    oprot.writeFieldEnd();
  }
  oprot.writeFieldStop();
  oprot.writeStructEnd();
}
项目:NeverwinterDP-Commons    文件:scribe.java   
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, Log_args struct) throws org.apache.thrift.TException {
  TTupleProtocol iprot = (TTupleProtocol) prot;
  BitSet incoming = iprot.readBitSet(1);
  if (incoming.get(0)) {
    {
      org.apache.thrift.protocol.TList _list5 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
      struct.messages = new ArrayList<LogEntry>(_list5.size);
      for (int _i6 = 0; _i6 < _list5.size; ++_i6)
      {
        LogEntry _elem7; // required
        _elem7 = new LogEntry();
        _elem7.read(iprot);
        struct.messages.add(_elem7);
      }
    }
    struct.setMessagesIsSet(true);
  }
}
项目:parquet-mr    文件:ParquetWriteProtocol.java   
@Override
public void writeFieldBegin(TField field) throws TException {
  if (field.type == TType.STOP) {
    return;
  }
  try {
    currentType = thriftFieldIdToParquetField[field.id];
    if (currentType == null) {
      throw new ParquetEncodingException("field " + field.id + " was not found in " + thriftType + " and " + schema.getType());
    }
    final int index = currentType.getIndex();
    recordConsumer.startField(currentType.getName(), index);
    currentProtocol = children[index];
  } catch (ArrayIndexOutOfBoundsException e) {
    throw new ParquetEncodingException("field " + field.id + " was not found in " + thriftType + " and " + schema.getType());
  }
}
项目:pinpoint    文件:ThriftRequestProperty.java   
public void setTraceHeader(ThriftHeader headerKey, Object value) throws TException {
    byte headerType = headerKey.getType();
    if (headerType == TType.STRING) {
        // skipped Strings are read as byte buffer.
        // see org.apache.thrift.protocol.TProtocolUtil.skip(TProtocol, byte, int)
        this.thriftHeaders.put(headerKey, byteBufferToString((ByteBuffer)value));
    } else if (headerType == TType.I64) {
        this.thriftHeaders.put(headerKey, (Long)value);
    } else if (headerType == TType.I16) {
        this.thriftHeaders.put(headerKey, (Short)value);
    } else if (headerType == TType.BOOL) {
        this.thriftHeaders.put(headerKey, (Boolean)value);
    } else {
        throw new TProtocolException("Invalid pinpoint header type - " + headerType);
    }
}
项目:pinpoint    文件:ThriftRequestProperty.java   
public void writeTraceHeader(ThriftHeader headerKey, TProtocol oprot) throws TException {
    Object headerValue = this.thriftHeaders.get(headerKey);
    if (headerValue == null) {
        return;
    }
    byte headerType = headerKey.getType();
    TField traceField = new TField(headerKey.name(), headerKey.getType(), headerKey.getId());
    oprot.writeFieldBegin(traceField);
    try {
        if (headerType == TType.STRING) {
            // these will be read as byte buffer although it's probably safe to just use writeString here.
            // see org.apache.thrift.protocol.TProtocolUtil.skip(TProtocol, byte, int)
            oprot.writeBinary(stringToByteBuffer((String)headerValue));
        } else if (headerType == TType.I64) {
            oprot.writeI64((Long)headerValue);
        } else if (headerType == TType.I16) {
            oprot.writeI16((Short)headerValue);
        } else if (headerType == TType.BOOL) {
            oprot.writeBool((Boolean)headerValue);
        } else {
            throw new TProtocolException("Invalid pinpoint header type - " + headerType);
        }
    } finally {
        oprot.writeFieldEnd();
    }
}
项目:ThriftMongoBridge    文件:TBSONProtocol.java   
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);
    }
}
项目:CadalWorkspace    文件:TBaseProcessor.java   
@Override
public boolean process(TProtocol in, TProtocol out) throws TException {
  TMessage msg = in.readMessageBegin();
  ProcessFunction fn = processMap.get(msg.name);
  if (fn == null) {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
  fn.process(msg.seqid, in, out, iface);
  return true;
}
项目:CadalWorkspace    文件:TApplicationException.java   
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();

}
项目:CadalWorkspace    文件:TBaseProcessor.java   
public boolean process(TProtocol in, TProtocol out) throws TException {
  TMessage msg = in.readMessageBegin();
  ProcessFunction fn = processMap.get(msg.name);
  if (fn == null) {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
  fn.process(msg.seqid, in, out, iface);
  return true;
}
项目:gemfirexd-oss    文件:GFXDServiceImpl.java   
@Override
public final boolean process(final TProtocol in, final TProtocol out)
    throws TException {
  final TMessage msg = in.readMessageBegin();
  final ProcessFunction<GFXDServiceImpl, ?> fn = this.fnMap.get(msg.name);
  if (fn != null) {
    fn.process(msg.seqid, in, out, this.inst);
    // terminate connection on receiving closeConnection
    // direct class comparison should be the fastest way
    // TODO: SW: also need to clean up connection artifacts in the case of
    // client connection failure (ConnectionListener does get a notification
    // but how to tie the socket/connectionNumber to the connectionID?)
    return fn.getClass() != GFXDService.Processor.closeConnection.class;
  }
  else {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(
        TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
            + msg.name + "'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
        msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
}
项目:ikasoa    文件:AbstractThriftBase.java   
/**
 * 写入操作
 */
@Override
public void write(TProtocol oprot) throws TException {
    if (!"org.apache.thrift.scheme.StandardScheme".equals(oprot.getScheme().getName()))
        throw new TApplicationException("Service scheme must be 'org.apache.thrift.scheme.StandardScheme' !");
    oprot.writeStructBegin(getTStruct());
    if (str != null) {
        oprot.writeFieldBegin(new TField("value", TType.STRING, (short) 0));
        oprot.writeString(str);
        oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
}
项目:gemfirexd-oss    文件:GFXDServiceImpl.java   
@Override
public final boolean process(final TProtocol in, final TProtocol out)
    throws TException {
  final TMessage msg = in.readMessageBegin();
  final ProcessFunction<GFXDServiceImpl, ?> fn = this.fnMap.get(msg.name);
  if (fn != null) {
    fn.process(msg.seqid, in, out, this.inst);
    // terminate connection on receiving closeConnection
    // direct class comparison should be the fastest way
    // TODO: SW: also need to clean up connection artifacts in the case of
    // client connection failure (ConnectionListener does get a notification
    // but how to tie the socket/connectionNumber to the connectionID?)
    return fn.getClass() != GFXDService.Processor.closeConnection.class;
  }
  else {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(
        TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
            + msg.name + "'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
        msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
}
项目:internet_of_things_simulator    文件:TDeserializer.java   
private TField locateField(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum ... fieldIdPathRest) throws TException {
  trans_.reset(bytes);

  TFieldIdEnum[] fieldIdPath= new TFieldIdEnum[fieldIdPathRest.length + 1];
  fieldIdPath[0] = fieldIdPathFirst;
  for (int i = 0; i < fieldIdPathRest.length; i++){
    fieldIdPath[i + 1] = fieldIdPathRest[i];
  }

  // index into field ID path being currently searched for
  int curPathIndex = 0;

  // this will be the located field, or null if it is not located
  TField field = null;

  protocol_.readStructBegin();

  while (curPathIndex < fieldIdPath.length) {
    field = protocol_.readFieldBegin();
    // we can stop searching if we either see a stop or we go past the field
    // id we're looking for (since fields should now be serialized in asc
    // order).
    if (field.type == TType.STOP || field.id > fieldIdPath[curPathIndex].getThriftFieldId()) {
      return null;
    }

    if (field.id != fieldIdPath[curPathIndex].getThriftFieldId()) {
      // Not the field we're looking for. Skip field.
      TProtocolUtil.skip(protocol_, field.type);
      protocol_.readFieldEnd();
    } else {
      // This field is the next step in the path. Step into field.
      curPathIndex++;
      if (curPathIndex < fieldIdPath.length) {
        protocol_.readStructBegin();
      }
    }
  }
  return field;
}
项目:internet_of_things_simulator    文件:TApplicationException.java   
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);
}
项目:human_readable_json_protocol    文件:HumanReadableJsonProtocol.java   
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));
    }
}
项目:armeria    文件:TApplicationExceptions.java   
/**
 * 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);
}
项目:armeria    文件:ThriftDocServicePluginTest.java   
@Test
public void testNewExceptionInfo() throws Exception {
    final ExceptionInfo exception = newExceptionInfo(FooServiceException.class);

    assertThat(exception).isEqualTo(new ExceptionInfo(
            FooServiceException.class.getName(),
            ImmutableList.of(newFieldInfo(
                    FooServiceException.class,
                    new FieldMetaData("stringVal", TFieldRequirementType.DEFAULT,
                                      new FieldValueMetaData(TType.STRING, false))))));
}
项目:NettyThrift    文件:ThriftFrameDecoder.java   
private TTransport tryDecodeUnframedMessage(ChannelHandlerContext ctx, ByteBuf buffer) throws TException {
    // Perform a trial decode, skipping through
    // the fields, to see whether we have an entire message available.

    int messageLength = 0;
    int messageStartReaderIndex = buffer.readerIndex();

    try {
        TNiftyTransport decodeAttemptTransport = new TNiftyTransport(ctx.channel(), buffer);
        TProtocol inputProtocol = this.inputProtocolFactory.getProtocol(decodeAttemptTransport);

        // Skip through the message
        inputProtocol.readMessageBegin();
        TProtocolUtil.skip(inputProtocol, TType.STRUCT);
        inputProtocol.readMessageEnd();

        messageLength = buffer.readerIndex() - messageStartReaderIndex;
    } catch (IndexOutOfBoundsException e) {
        // No complete message was decoded: ran out of bytes
        return null;
    } finally {
        if (buffer.readerIndex() - messageStartReaderIndex > maxFrameSize) {
            ctx.fireExceptionCaught(new TooLongFrameException("Maximum frame size of " + maxFrameSize + " exceeded"));
        }

        buffer.readerIndex(messageStartReaderIndex);
    }

    if (messageLength <= 0) {
        return null;
    }

    // We have a full message in the read buffer, slice it off
    ByteBuf messageBuffer = extractFrame(buffer, messageStartReaderIndex, messageLength);
    ThriftMessage message = new ThriftMessage(messageBuffer, ThriftTransportType.UNFRAMED);
    buffer.readerIndex(messageStartReaderIndex + messageLength);
    return new TNiftyTransport(ctx.channel(), message);
}
项目:ThriftBook    文件:CompFileWrite.java   
public static void main(String[] args) throws TException {
    TTransport trans = new TSimpleFileTransport("data.comp", false, true);
    TProtocol proto = new TCompactProtocol(trans);          

    Trade trade = new Trade();
    trade.symbol = "F";
    trade.price = 13.10;
    trade.size = 2500;

    proto.writeStructBegin(new TStruct());

    proto.writeFieldBegin(new TField("symbol", 
                                     TType.STRING, 
                                     (short) 1));
    proto.writeString(trade.symbol);
    proto.writeFieldEnd();

    proto.writeFieldBegin(new TField("price", 
                                     TType.DOUBLE, 
                                     (short) 2));
    proto.writeDouble(trade.price);
    proto.writeFieldEnd();

    proto.writeFieldBegin(new TField("size", 
                                     TType.I32, 
                                     (short) 3));
    proto.writeI32(trade.size);
    proto.writeFieldEnd();

    proto.writeFieldStop();
    proto.writeStructEnd();

    System.out.println("Wrote trade to file");
}
项目:ThriftBook    文件:BinFileRead.java   
public static void main(String[] args) throws TException {
    TTransport trans = new TSimpleFileTransport("data", true, false);
    TProtocol proto = new TBinaryProtocol(trans);       

    Trade trade_read = new Trade();
    TField field = new TField();

    TStruct struct_obj = proto.readStructBegin();       
    while(true) {                       
        field = proto.readFieldBegin();         
        if (field.id == TType.STOP) {               
            break;
        }
        switch(field.id) {                  
        case 1:
            trade_read.symbol = proto.readString(); 
            break;
        case 2:
            trade_read.price = proto.readDouble();
            break;
        case 3:
            trade_read.size = proto.readI32();
            break;
        default:
            TProtocolUtil.skip(proto,field.type);   
            break;
        }
        proto.readFieldEnd();               
    }
    proto.readStructEnd();              

    System.out.println("Trade: " + trade_read.symbol + " " +
                       trade_read.size + " @ " + trade_read.price);
}
项目:parquet-format    文件:EventBasedThriftReader.java   
/**
 * reads the content of a struct (fields) from the underlying protocol and passes the events to c
 * @param c the field consumer
 * @throws TException
 */
public void readStructContent(FieldConsumer c) throws TException {
  TField field;
  while (true) {
    field = protocol.readFieldBegin();
    if (field.type == TType.STOP) {
      break;
    }
    c.consumeField(protocol, this, field.id, field.type);
  }
}
项目:NeverwinterDP-Commons    文件:scribe.java   
public void read(org.apache.thrift.protocol.TProtocol iprot, Log_args struct) throws org.apache.thrift.TException {
  org.apache.thrift.protocol.TField schemeField;
  iprot.readStructBegin();
  while (true)
  {
    schemeField = iprot.readFieldBegin();
    if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
      break;
    }
    switch (schemeField.id) {
      case 1: // MESSAGES
        if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
          {
            org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
            struct.messages = new ArrayList<LogEntry>(_list0.size);
            for (int _i1 = 0; _i1 < _list0.size; ++_i1)
            {
              LogEntry _elem2; // required
              _elem2 = new LogEntry();
              _elem2.read(iprot);
              struct.messages.add(_elem2);
            }
            iprot.readListEnd();
          }
          struct.setMessagesIsSet(true);
        } else { 
          org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        break;
      default:
        org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
    }
    iprot.readFieldEnd();
  }
  iprot.readStructEnd();

  // check for required fields of primitive type, which can't be checked in the validate method
  struct.validate();
}
项目:NeverwinterDP-Commons    文件:scribe.java   
public void read(TProtocol iprot, Log_result struct) throws TException {
  org.apache.thrift.protocol.TField schemeField;
  iprot.readStructBegin();
  while (true)
  {
    schemeField = iprot.readFieldBegin();
    if (schemeField.type == TType.STOP) { 
      break;
    }
    switch (schemeField.id) {
      case 0: // SUCCESS
        if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
          struct.success = ResultCode.findByValue(iprot.readI32());
          struct.setSuccessIsSet(true);
        } else { 
          TProtocolUtil.skip(iprot, schemeField.type);
        }
        break;
      default:
        TProtocolUtil.skip(iprot, schemeField.type);
    }
    iprot.readFieldEnd();
  }
  iprot.readStructEnd();

  // check for required fields of primitive type, which can't be checked in the validate method
  struct.validate();
}
项目:parquet-mr    文件:ProtocolReadToWrite.java   
private void readOneStruct(TProtocol in, TProtocol out) throws TException {
  final TStruct struct = in.readStructBegin();
  out.writeStructBegin(struct);
  TField field;
  while ((field = in.readFieldBegin()).type != TType.STOP) {
    out.writeFieldBegin(field);
    readOneValue(in, out, field.type);
    in.readFieldEnd();
    out.writeFieldEnd();
  }
  out.writeFieldStop();
  in.readStructEnd();
  out.writeStructEnd();
}
项目:ThriftMongoBridge    文件:TBSONProtocol.java   
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;
}
项目:ThriftMongoBridge    文件:TBSONProtocol.java   
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);
    }
}
项目:ThriftMongoBridge    文件:TBSONProtocol.java   
public TMap readMapBegin() throws TException {
    StructContext context = (StructContext) peekContext();
    if(context.fieldsStack.isEmpty()) {
     return EMPTY_MAP;
   }
   String fieldName = context.fieldsStack.peek();

   MapContext mapContext = new MapContext(TType.VOID);
   BasicDBObject dbMap = (BasicDBObject) context.dbObject.get(fieldName);

   mapContext.setDbMap(dbMap);
   mapContext.thriftObject = getThriftObject(context.thriftObject, fieldName);
   pushContext(mapContext);
   return new TMap(TType.STRING, TType.STRING,dbMap.size());
}
项目:ThriftMongoBridge    文件:TBSONProtocol.java   
public TList readListBegin() throws TException {
    StructContext context = (StructContext) peekContext();
    if(context.fieldsStack.isEmpty()) {
     return EMPTY_LIST;
   }
   String fieldName = context.fieldsStack.peek();

   ListContext listContext = new ListContext();
   BasicDBList dbList = (BasicDBList) context.dbObject.get(fieldName);

   listContext.dbList = dbList;
   listContext.thriftObject = getThriftObject(context.thriftObject, fieldName);
   pushContext(listContext);
   return new TList(TType.LIST, dbList.size());
}
项目:ThriftMongoBridge    文件:TBSONProtocol.java   
public TSet readSetBegin() throws TException {
    StructContext context = (StructContext) peekContext();
    if(context.fieldsStack.isEmpty()) {
     return EMPTY_SET;
   }
   String fieldName = context.fieldsStack.peek();

   ListContext listContext = new ListContext();
   BasicDBList dbList = (BasicDBList) context.dbObject.get(fieldName);

   listContext.dbList = dbList;
   listContext.thriftObject = getThriftObject(context.thriftObject, fieldName);
   pushContext(listContext);
   return new TSet(TType.SET, dbList.size());
}
项目:ThriftMongoBridge    文件:TBSONProtocol.java   
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;
}
项目:CadalWorkspace    文件:TDeserializer.java   
private TField locateField(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum ... fieldIdPathRest) throws TException {
  trans_.reset(bytes);

  TFieldIdEnum[] fieldIdPath= new TFieldIdEnum[fieldIdPathRest.length + 1];
  fieldIdPath[0] = fieldIdPathFirst;
  for (int i = 0; i < fieldIdPathRest.length; i++){
    fieldIdPath[i + 1] = fieldIdPathRest[i];
  }

  // index into field ID path being currently searched for
  int curPathIndex = 0;

  // this will be the located field, or null if it is not located
  TField field = null;

  protocol_.readStructBegin();

  while (curPathIndex < fieldIdPath.length) {
    field = protocol_.readFieldBegin();
    // we can stop searching if we either see a stop or we go past the field
    // id we're looking for (since fields should now be serialized in asc
    // order).
    if (field.type == TType.STOP || field.id > fieldIdPath[curPathIndex].getThriftFieldId()) {
      return null;
    }

    if (field.id != fieldIdPath[curPathIndex].getThriftFieldId()) {
      // Not the field we're looking for. Skip field.
      TProtocolUtil.skip(protocol_, field.type);
      protocol_.readFieldEnd();
    } else {
      // This field is the next step in the path. Step into field.
      curPathIndex++;
      if (curPathIndex < fieldIdPath.length) {
        protocol_.readStructBegin();
      }
    }
  }
  return field;
}
项目:CadalWorkspace    文件:TApplicationException.java   
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);
}
项目:CadalWorkspace    文件:TApplicationException.java   
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);
}
项目:CadalWorkspace    文件:TDeserializer.java   
private TField locateField(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum ... fieldIdPathRest) throws TException {
  trans_.reset(bytes);

  TFieldIdEnum[] fieldIdPath= new TFieldIdEnum[fieldIdPathRest.length + 1];
  fieldIdPath[0] = fieldIdPathFirst;
  for (int i = 0; i < fieldIdPathRest.length; i++){
    fieldIdPath[i + 1] = fieldIdPathRest[i];
  }

  // index into field ID path being currently searched for
  int curPathIndex = 0;

  // this will be the located field, or null if it is not located
  TField field = null;

  protocol_.readStructBegin();

  while (curPathIndex < fieldIdPath.length) {
    field = protocol_.readFieldBegin();
    // we can stop searching if we either see a stop or we go past the field
    // id we're looking for (since fields should now be serialized in asc
    // order).
    if (field.type == TType.STOP || field.id > fieldIdPath[curPathIndex].getThriftFieldId()) {
      return null;
    }

    if (field.id != fieldIdPath[curPathIndex].getThriftFieldId()) {
      // Not the field we're looking for. Skip field.
      TProtocolUtil.skip(protocol_, field.type);
      protocol_.readFieldEnd();
    } else {
      // This field is the next step in the path. Step into field.
      curPathIndex++;
      if (curPathIndex < fieldIdPath.length) {
        protocol_.readStructBegin();
      }
    }
  }
  return field;
}