org.apache.thrift.protocol.TStruct Java Examples

The following examples show how to use org.apache.thrift.protocol.TStruct. 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: ThriftNativeCodec.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
    throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
            invocation.getMethodName(), TMessageType.CALL, 
            thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for(int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example #2
Source File: ThriftNativeCodec.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
    throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
            invocation.getMethodName(), TMessageType.CALL, 
            thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for(int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example #3
Source File: ThriftNativeCodec.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
        throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
                invocation.getMethodName(), TMessageType.CALL,
                thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for (int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example #4
Source File: ThriftNativeCodec.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
    throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
            invocation.getMethodName(), TMessageType.CALL, 
            thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for(int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example #5
Source File: ThriftNativeCodec.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
    throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
            invocation.getMethodName(), TMessageType.CALL, 
            thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for(int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example #6
Source File: MockResult.java    From thrift-mock with Apache License 2.0 6 votes vote down vote up
public MockResult(String methodName, TBase value) {
  this.methodName = methodName;
  this.success = value;
  this.structDesc = new TStruct(methodName+"_result");

  //init metaDatMap
  Map<_Fields, FieldMetaData> tmpMap = new EnumMap<>(_Fields.class);
  tmpMap.put(_Fields.SUCCESS,
             new FieldMetaData(SUCCESS_NAME, TFieldRequirementType.DEFAULT,
                               new FieldValueMetaData(TType.STRUCT          , value.getClass().getCanonicalName())));
  metaDataMap = Collections.unmodifiableMap(tmpMap);
  FieldMetaData.addStructMetaDataMap(MockResult.class, metaDataMap);

  schemes.put(StandardScheme.class, new MockResultStandardSchemeFactory(structDesc));
  schemes.put(TupleScheme.class, new MockResultTupleSchemeFactory());

}
 
Example #7
Source File: ThriftRecordConverter.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private StructConverter(List<TProtocol> events, GroupType parquetSchema, ThriftField field) {
  this.events = events;
  this.name = field.getName();
  this.tStruct = new TStruct(name);
  this.thriftType = (StructType)field.getType();
  this.schemaSize = parquetSchema.getFieldCount();
  this.converters = new Converter[this.schemaSize];
  List<ThriftField> thriftChildren = thriftType.getChildren();
  for (int i = 0; i < schemaSize; i++) {
    Type schemaType = parquetSchema.getType(i);
    String fieldName = schemaType.getName();
    ThriftField matchingThrift = null;
    for (ThriftField childField: thriftChildren) {
      String thriftChildName = childField.getName();
      if (thriftChildName != null && thriftChildName.equalsIgnoreCase(fieldName)) {
        matchingThrift = childField;
        break;
      }
    }
    if (matchingThrift == null) {
    	// this means the file did not contain that field
      // it will never be populated in this instance
      // other files might populate it
    	continue;
    }
    if (schemaType.isPrimitive()) {
    	converters[i] = new PrimitiveFieldHandler(newConverter(events, schemaType, matchingThrift).asPrimitiveConverter(), matchingThrift, events);
    } else {
    	converters[i] = new GroupFieldhandler(newConverter(events, schemaType, matchingThrift).asGroupConverter(), matchingThrift, events);
    }
  }
}
 
Example #8
Source File: CompFileWrite.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.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");
}
 
Example #9
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();
}
 
Example #10
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 #11
Source File: TSimpleJSONProtocol.java    From nettythrift with Apache License 2.0 5 votes vote down vote up
public TStruct readStructBegin() {
	BaseArray prevStruct = structStack.peek();
	if (prevStruct != null) {
		BaseArray e = prevStruct.getArray();
		structStack.push(e);
	} else {
		structStack.push(msgStruct);
	}
	return ANONYMOUS_STRUCT;
}
 
Example #12
Source File: MappedFileTBinaryProtocol.java    From singer with Apache License 2.0 5 votes vote down vote up
public TStruct readStructBegin() {
  try {
    // since data is framed, each message read is preceded by a 4 byte size
    readI32();
  } catch (TException e) {
    logger.log(Level.SEVERE, "Failed to read frame", e);
  }
  return ANONYMOUS_STRUCT;
}
 
Example #13
Source File: ParquetWriteProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * @see org.apache.parquet.thrift.ParquetProtocol#writeStructBegin(org.apache.thrift.protocol.TStruct)
 */
@Override
public void writeStructBegin(TStruct struct) throws TException {
  if (LOG.isDebugEnabled()) LOG.debug("writeStructBegin("+toString(struct)+")");
  currentProtocol.writeStructBegin(struct);
}
 
Example #14
Source File: ParquetWriteProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
private String toString(TStruct struct) {
  return "<TStruct name:" + struct.name + ">";
}
 
Example #15
Source File: ParquetWriteProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void writeStructBegin(TStruct struct) throws TException {
  recordConsumer.startMessage();
}
 
Example #16
Source File: ParquetWriteProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void writeStructBegin(TStruct struct) throws TException {
  start();
  recordConsumer.startGroup();
}
 
Example #17
Source File: BufferedProtocolReadToWrite.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void writeStructBegin(TStruct tStruct) throws TException {
}
 
Example #18
Source File: InterningProtocol.java    From parquet-format with Apache License 2.0 4 votes vote down vote up
public void writeStructBegin(TStruct struct) throws TException {
  delegate.writeStructBegin(struct);
}
 
Example #19
Source File: BufferedProtocolReadToWrite.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public TStruct readStructBegin() throws TException {
  return null;
}
 
Example #20
Source File: ParquetProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void writeStructBegin(TStruct struct) throws TException {
  throw exception();
}
 
Example #21
Source File: ParquetProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public TStruct readStructBegin() throws TException {
  throw exception();
}
 
Example #22
Source File: ParquetReadProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
public TStruct readStructBegin() throws TException {
  LOG.debug("readStructBegin()");
  return next().readStructBegin();
}
 
Example #23
Source File: TReplaceListProtocol.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public void writeStructBegin(TStruct struct) throws TException {
    if (!writeFieldBegin) {
        protocol.writeStructBegin(struct);
    }
}
 
Example #24
Source File: TReplaceListProtocol.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public TStruct readStructBegin() throws TException {
    throw new TException("unsupported operation");
}
 
Example #25
Source File: ThriftRecordConverter.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public TStruct readStructBegin() throws TException {
  return tStruct;
}
 
Example #26
Source File: DefaultEventsVisitor.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public TStruct readStructBegin() throws TException {
  return new TStruct(structName);
}
 
Example #27
Source File: InterningProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
public TStruct readStructBegin() throws TException {
  return delegate.readStructBegin();
}
 
Example #28
Source File: InterningProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
public void writeStructBegin(TStruct struct) throws TException {
  delegate.writeStructBegin(struct);
}
 
Example #29
Source File: InterningProtocol.java    From parquet-format with Apache License 2.0 4 votes vote down vote up
public TStruct readStructBegin() throws TException {
  return delegate.readStructBegin();
}
 
Example #30
Source File: TTextProtocol.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public void writeStructBegin(TStruct struct) throws TException {
    writeJsonObjectBegin(new StructContext(null));
}