Package io.netty.handler.codec

Examples of io.netty.handler.codec.LengthFieldPrepender


              .option(ChannelOption.SO_KEEPALIVE, true)
              .handler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(SocketChannel socketChannel) throws Exception {
                  socketChannel.pipeline().addLast(
                      new LengthFieldPrepender(LENGTH_FIELD_LENGTH, true));
                }
              });
    }
  }
View Full Code Here


        StringDecoder stringDecoder = new StringDecoder();
        registry.bind("length-decoder", lengthDecoder);
        registry.bind("string-decoder", stringDecoder);

        LengthFieldPrepender lengthEncoder = new LengthFieldPrepender(4);
        StringEncoder stringEncoder = new StringEncoder();
        registry.bind("length-encoder", lengthEncoder);
        registry.bind("string-encoder", stringEncoder);

        List<ChannelHandler> decoders = new ArrayList<ChannelHandler>();
View Full Code Here

    RxNetty.createTcpClient(params.getHost(), params.getPort(), new PipelineConfiguratorComposite<RemoteRxEvent, RemoteRxEvent>(
        new PipelineConfigurator<RemoteRxEvent, RemoteRxEvent>(){
          @Override
          public void configureNewPipeline(ChannelPipeline pipeline) {
//            pipeline.addFirst(new LoggingHandler(LogLevel.ERROR)); // uncomment to enable debug logging       
            pipeline.addLast("frameEncoder", new LengthFieldPrepender(4)); // 4 bytes to encode length
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(524288, 0, 4, 0, 4)); // max frame = half MB
          }
        }, new RxEventPipelineConfigurator()))
      .connect()
      // send subscription request, get input stream
View Full Code Here

      = RxNetty.createTcpServer(port, new PipelineConfiguratorComposite<RemoteRxEvent, RemoteRxEvent>(
        new PipelineConfigurator<RemoteRxEvent, RemoteRxEvent>(){
          @Override
          public void configureNewPipeline(ChannelPipeline pipeline) {
//            pipeline.addFirst(new LoggingHandler(LogLevel.ERROR)); // uncomment to enable debug logging 
            pipeline.addLast("frameEncoder", new LengthFieldPrepender(4)); // 4 bytes to encode length
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(524288, 0, 4, 0, 4)); // max frame = half MB
          }
        }, new RxEventPipelineConfigurator()),  
        new RemoteObservableConnectionHandler(configuredObservables, builder.getIngressPolicy(), blockUntilCompleted,
            metrics));
View Full Code Here

        msg = copiedBuffer("A", CharsetUtil.ISO_8859_1);
    }

    @Test
    public void testPrependLength() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4));
        ch.writeOutbound(msg);
        ByteBuf buf = ch.readOutbound();
        assertEquals(4, buf.readableBytes());
        assertEquals(msg.readableBytes(), buf.readInt());
        buf.release();
View Full Code Here

        buf.release();
    }

    @Test
    public void testPrependLengthIncludesLengthFieldLength() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, true));
        ch.writeOutbound(msg);
        ByteBuf buf = ch.readOutbound();
        assertEquals(4, buf.readableBytes());
        assertEquals(5, buf.readInt());
        buf.release();
View Full Code Here

        buf.release();
    }

    @Test
    public void testPrependAdjustedLength() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -1));
        ch.writeOutbound(msg);
        ByteBuf buf = ch.readOutbound();
        assertEquals(4, buf.readableBytes());
        assertEquals(msg.readableBytes() - 1, buf.readInt());
        buf.release();
View Full Code Here

        buf.release();
    }

    @Test
    public void testAdjustedLengthLessThanZero() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -2));
        try {
            ch.writeOutbound(msg);
            fail(EncoderException.class.getSimpleName() + " must be raised.");
        } catch (EncoderException e) {
            // Expected
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.LengthFieldPrepender

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.