Package muduo.rpc

Examples of muduo.rpc.RpcEncoder


public class RpcTest {

    @Test
    public void testEncoder() throws Exception {
        RpcEncoder encoder = new RpcEncoder();
        RpcMessage message = RpcMessage.newBuilder().setType(MessageType.REQUEST).setId(1).build();
        encoder.encode(null, null, message);
    }
View Full Code Here


        encoder.encode(null, null, message);
    }

    @Test
    public void testEncoder2() throws Exception {
        RpcEncoder encoder = new RpcEncoder();
        EchoRequest request = EchoRequest.newBuilder().setPayload("Hello").build();
        RpcMessage message = RpcMessage.newBuilder().setType(MessageType.REQUEST).setId(1)
                .setService(EchoService.getDescriptor().getFullName())
                .setMethod(EchoService.getDescriptor().getMethods().get(0).getName())
                .setRequest(request.toByteString()).build();
        encoder.encode(null, null, message);
    }
View Full Code Here

        encoder.encode(null, null, message);
    }

    @Test
    public void testDecoder() throws Exception {
        RpcEncoder encoder = new RpcEncoder();
        SudokuRequest request = SudokuRequest.newBuilder().setCheckerboard("001010").build();
        RpcMessage message = RpcMessage.newBuilder().setType(MessageType.REQUEST).setId(1)
                .setService(SudokuService.getDescriptor().getFullName())
                .setMethod(SudokuService.getDescriptor().getMethods().get(0).getName())
                .setRequest(request.toByteString()).build();
        ChannelBuffer buffer = (ChannelBuffer) encoder.encode(null, null, message);

        RpcDecoder decoder = new RpcDecoder();
        RpcMessage decodedMessage = (RpcMessage) decoder.decode(null, null, buffer);
        assertEquals(1, decodedMessage.getId());
    }
View Full Code Here

        assertEquals(1, decodedMessage.getId());
    }

    @Test
    public void testDecoder2() throws Exception {
        RpcEncoder encoder = new RpcEncoder();
        RpcMessage message = RpcMessage.newBuilder().setType(MessageType.REQUEST).setId(2).build();
        ChannelBuffer buffer = (ChannelBuffer) encoder.encode(null, null, message);
        ChannelBuffer buf2 = new BigEndianHeapChannelBuffer(buffer.readableBytes() + 8);
        buf2.writeInt(123);
        buf2.writeBytes(buffer);

        buf2.readInt();
View Full Code Here

TOP

Related Classes of muduo.rpc.RpcEncoder

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.