Java Code Examples for org.apache.thrift.protocol.TProtocol#readStructBegin()

The following examples show how to use org.apache.thrift.protocol.TProtocol#readStructBegin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractThriftBase.java    From ikasoa with MIT License 6 votes vote down vote up
/**
 * 读取操作
 */
@Override
public void read(TProtocol iprot) throws TException {
	if (!StringUtil.equals("org.apache.thrift.scheme.StandardScheme", iprot.getScheme().getName()))
		throw new TApplicationException("Service scheme must be 'org.apache.thrift.scheme.StandardScheme' !");
	TField schemeField;
	iprot.readStructBegin();
	while (true) {
		schemeField = iprot.readFieldBegin();
		if (ObjectUtil.same(schemeField.type, TType.STOP))
			break;
		if (ObjectUtil.same(schemeField.type, TType.STRING))
			str = iprot.readString();
		else
			throw new TApplicationException("field type must be 'String' !");
		iprot.readFieldEnd();
	}
	iprot.readStructEnd();
}
 
Example 2
Source File: TApplicationExceptions.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: BinFileRead.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: ProtocolReadToWrite.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
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();
}