Package com.alibaba.dubbo.remoting.buffer

Examples of com.alibaba.dubbo.remoting.buffer.ChannelBuffer


        rpcResult.setResult( "Hello, World!" );

        Response response = new Response();
        response.setResult( rpcResult );
        response.setId( request.getId() );
        ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

        ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
                ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" );
        ThriftCodec.cachedRequest.putIfAbsent( request.getId(), rd );
        codec.encode( channel, bos, response );

        byte[] buf = new byte[bos.writerIndex() - 4];
        System.arraycopy( bos.array(), 4, buf, 0, bos.writerIndex() - 4 );

        ByteArrayInputStream bis = new ByteArrayInputStream( buf );

        if ( bis.markSupported() ) {
            bis.mark( 0 );
        }

        TIOStreamTransport transport = new TIOStreamTransport( bis );
        TBinaryProtocol protocol = new TBinaryProtocol( transport );

        Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() );
        Assert.assertEquals( protocol.readI32() + 4, bos.writerIndex() );
        int headerLength = protocol.readI16();

        Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() );
        Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() );
        Assert.assertEquals( request.getId(), protocol.readI64() );
View Full Code Here


        rpcResult.setException( new RuntimeException( exceptionMessage ) );

        Response response = new Response();
        response.setResult( rpcResult );
        response.setId( request.getId() );
        ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

        ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
                ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" );
        ThriftCodec.cachedRequest.put( request.getId(), rd );
        codec.encode( channel, bos, response );

        byte[] buf = new byte[bos.writerIndex() - 4];
        System.arraycopy( bos.array(), 4, buf, 0, bos.writerIndex() - 4 );
        ByteArrayInputStream bis = new ByteArrayInputStream( buf);

        if ( bis.markSupported() ) {
            bis.mark( 0 );
        }

        TIOStreamTransport transport = new TIOStreamTransport( bis );
        TBinaryProtocol protocol = new TBinaryProtocol( transport );

        Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() );
        Assert.assertEquals( protocol.readI32() + 4, bos.writerIndex() );
        int headerLength = protocol.readI16();

        Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() );
        Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() );
        Assert.assertEquals( request.getId(), protocol.readI64() );
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.remoting.buffer.ChannelBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.