本文整理汇总了Java中org.apache.thrift.TBase.read方法的典型用法代码示例。如果您正苦于以下问题:Java TBase.read方法的具体用法?Java TBase.read怎么用?Java TBase.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.thrift.TBase
的用法示例。
在下文中一共展示了TBase.read方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.apache.thrift.TBase; //导入方法依赖的package包/类
/**
* Deserialize the Thrift object from a byte array.
*
* @param bytes The array to read from
*/
public TBase<?, ?> deserialize(byte[] bytes) throws TException {
try {
trans.reset(bytes);
Header header = readHeader();
final int validate = validate(header);
if (validate == HeaderUtils.OK) {
TBase<?, ?> base = locator.tBaseLookup(header.getType());
base.read(protocol);
return base;
}
if (validate == HeaderUtils.PASS_L4) {
return new L4Packet(header);
}
throw new IllegalStateException("invalid validate " + validate);
} finally {
trans.clear();
protocol.reset();
}
}
示例2: read
import org.apache.thrift.TBase; //导入方法依赖的package包/类
/**
* Reads the next object from the fileName.
*/
public TBase read() throws IOException {
TBase t = creator.create();
try {
t.read(binaryIn);
} catch (TException e) {
throw new IOException(e);
}
return t;
}
示例3: deserializeThriftToken
import org.apache.thrift.TBase; //导入方法依赖的package包/类
/**
* Deserialize the given byte array into any type of Thrift tokens
* This method avoid an explicit cast on the deserialized token
* @param base The Thrift instance
* @param bytes the serialized thrift token
*/
private void deserializeThriftToken(TBase<?, ?> base, byte[] bytes) throws TException {
// Thrift deserialization
TMemoryInputTransport trans_ = new TMemoryInputTransport();
TProtocol protocol_ = new TCompactProtocol.Factory().getProtocol(trans_);
try {
trans_.reset(bytes);
// TRASH THE 8 fist bytes (SIP HASH)
trans_.consumeBuffer(8);
base.read(protocol_);
} finally {
trans_.clear();
protocol_.reset();
}
}
示例4: deserialize
import org.apache.thrift.TBase; //导入方法依赖的package包/类
private TBase<?, ?> deserialize() throws TException {
final Header header = readHeader();
if (header == null) {
return null;
}
final int validate = validate(header);
if (validate == HeaderUtils.PASS_L4) {
return new L4Packet(header);
}
TBase<?, ?> base = locator.tBaseLookup(header.getType());
base.read(protocol);
return base;
}
示例5: extractAuthToken
import org.apache.thrift.TBase; //导入方法依赖的package包/类
private TBase extractAuthToken(TProtocol protocol, TBase authToken) throws TException {
authToken.read(protocol);
return authToken;
}
示例6: handle
import org.apache.thrift.TBase; //导入方法依赖的package包/类
private void handle(ClientRequestContext ctx, int seqId, DefaultRpcResponse reply,
ThriftFunction func, HttpData content) throws TException {
if (func.isOneWay()) {
handleSuccess(ctx, reply, null, null);
return;
}
if (content.isEmpty()) {
throw new TApplicationException(TApplicationException.MISSING_RESULT);
}
final TMemoryInputTransport inputTransport =
new TMemoryInputTransport(content.array(), content.offset(), content.length());
final TProtocol inputProtocol = protocolFactory.getProtocol(inputTransport);
final TMessage header = inputProtocol.readMessageBegin();
final TApplicationException appEx = readApplicationException(seqId, func, inputProtocol, header);
if (appEx != null) {
handleException(ctx, reply, new ThriftReply(header, appEx), appEx);
return;
}
TBase<?, ?> result = func.newResult();
result.read(inputProtocol);
inputProtocol.readMessageEnd();
final ThriftReply rawResponseContent = new ThriftReply(header, result);
for (TFieldIdEnum fieldIdEnum : func.exceptionFields()) {
if (ThriftFieldAccess.isSet(result, fieldIdEnum)) {
final TException cause = (TException) ThriftFieldAccess.get(result, fieldIdEnum);
handleException(ctx, reply, rawResponseContent, cause);
return;
}
}
final TFieldIdEnum successField = func.successField();
if (successField == null) { // void method
handleSuccess(ctx, reply, null, rawResponseContent);
return;
}
if (ThriftFieldAccess.isSet(result, successField)) {
final Object returnValue = ThriftFieldAccess.get(result, successField);
handleSuccess(ctx, reply, returnValue, rawResponseContent);
return;
}
handleException(
ctx, reply, rawResponseContent,
new TApplicationException(TApplicationException.MISSING_RESULT,
result.getClass().getName() + '.' + successField.getFieldName()));
}