本文整理匯總了Java中org.apache.thrift.transport.TTransport.read方法的典型用法代碼示例。如果您正苦於以下問題:Java TTransport.read方法的具體用法?Java TTransport.read怎麽用?Java TTransport.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.thrift.transport.TTransport
的用法示例。
在下文中一共展示了TTransport.read方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEncodeRequest
import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
@Test
public void testEncodeRequest() throws Exception {
Request request = createRequest();
ChannelBuffer output = ChannelBuffers.dynamicBuffer(1024);
codec.encode( channel, output, request );
byte[] bytes = new byte[output.readableBytes()];
output.readBytes(bytes);
ByteArrayInputStream bis = new ByteArrayInputStream( bytes );
TTransport transport = new TIOStreamTransport( bis );
TBinaryProtocol protocol = new TBinaryProtocol( transport );
// frame
byte[] length = new byte[4];
transport.read( length, 0, 4 );
if ( bis.markSupported() ) {
bis.mark( 0 );
}
// magic
Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() );
// message length
int messageLength = protocol.readI32();
Assert.assertEquals( messageLength + 4, bytes.length );
// header length
short headerLength = protocol.readI16();
// version
Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() );
// service name
Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() );
// dubbo request id
Assert.assertEquals( request.getId(), protocol.readI64() );
// test message header length
if ( bis.markSupported() ) {
bis.reset();
bis.skip( headerLength );
}
TMessage message = protocol.readMessageBegin();
Demo.echoString_args args = new Demo.echoString_args();
args.read( protocol );
protocol.readMessageEnd();
Assert.assertEquals( "echoString", message.name );
Assert.assertEquals( TMessageType.CALL, message.type );
Assert.assertEquals( "Hello, World!", args.getArg() );
}