本文整理汇总了Java中org.apache.thrift.protocol.TStruct类的典型用法代码示例。如果您正苦于以下问题:Java TStruct类的具体用法?Java TStruct怎么用?Java TStruct使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TStruct类属于org.apache.thrift.protocol包,在下文中一共展示了TStruct类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeRequest
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
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);
}
}
示例2: writeMessage
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
private void writeMessage(PMessage<?,?> message, TProtocol protocol) throws TException, SerializerException {
PMessageDescriptor<?, ?> type = message.descriptor();
protocol.writeStructBegin(new TStruct(message.descriptor()
.getQualifiedName()));
for (PField field : type.getFields()) {
if (!message.has(field.getId())) {
continue;
}
protocol.writeFieldBegin(new TField(field.getName(),
forType(field.getDescriptor().getType()),
(short) field.getId()));
writeTypedValue(message.get(field.getId()), field.getDescriptor(), protocol);
protocol.writeFieldEnd();
}
protocol.writeFieldStop();
protocol.writeStructEnd();
}
示例3: encodeRequest
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
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);
}
}
示例4: write
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
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();
}
示例5: readStructBegin
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
public TStruct readStructBegin() {
BaseArray prevStruct = structStack.peek();
if (prevStruct != null) {
BaseArray e = prevStruct.getArray();
structStack.push(e);
} else {
structStack.push(msgStruct);
}
return ANONYMOUS_STRUCT;
}
示例6: readStructBegin
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
@Override
public TStruct readStructBegin() throws TException {
if (err != null) {
throw err;
}
return new TStruct();
}
示例7: readStructBegin
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
@Override
public TStruct readStructBegin() throws TException {
if (structLevel == 1) {
if (topLevelStructToBeRecorded == topLevelStruct)
rememberingTransport.startRemeberingReadBytes();
}
structLevel++;
return super.readStructBegin();
}
示例8: main
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
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");
}
示例9: main
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
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);
}
示例10: StructConverter
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
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);
}
}
}
示例11: readOneStruct
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
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();
}
示例12: readStructBegin
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
public TStruct readStructBegin() throws TException {
try {
DBObject dbObject = null;
Object thriftObject = null;
if(!isContextEmpty()) {
Context currentContext = peekContext();
if (currentContext instanceof ListContext) {
dbObject = (DBObject) ((ListContext) currentContext).next();
thriftObject = ((ListContext) peekContext()).thriftObject;
} else if (currentContext instanceof MapContext) {
dbObject = (DBObject) ((MapContext) currentContext).next();
thriftObject = ((MapContext) peekContext()).thriftObject;
} else {
return ANONYMOUS_STRUCT;
}
} else {
thriftObject = threadSafeTBase.get();
dbObject = getDBObject();
}
StructContext context = new StructContext(thriftObject.getClass().getSimpleName());
context.setDbObject(dbObject);
context.thriftObject = thriftObject;
pushContext(context);
return ANONYMOUS_STRUCT;
} catch (Exception exp) {
throw new TException("Unexpected readStructBegin", exp);
}
}
示例13: writeStructBegin
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
public void writeStructBegin(TStruct struct) throws TException {
writeContext_.write();
trans_.write(LBRACE);
pushWriteContext(new StructContext());
}
示例14: getTStruct
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
@Override
protected TStruct getTStruct() {
return STRUCT_DESC;
}
示例15: writeStructBegin
import org.apache.thrift.protocol.TStruct; //导入依赖的package包/类
@Override
public void writeStructBegin(TStruct tStruct) throws TException {
oprot.writeStructBegin(tStruct);
}