public static class NettyDecoder2 extends ByteToMessageDecoder{

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> 
out) throws Exception {

if((in.readableBytes() < 1119) ) {
 return;
}

String msg = in.toString(CharsetUtil.UTF_8);
in.readerIndex(in.readerIndex() + in.readableBytes());


out.add(msg);
}
}

i create this code. but is there any way to know  in.readableBytes() ?
it is very dynamic data. so i could not know the size.. give me a tip pz.

2017년 7월 4일 화요일 오후 6시 40분 54초 UTC+9, Norman Maurer 님의 말:

> There is no guarantee that you will receive all of it with one read 
> operation. 
>
> You will need to account for it in your decoder and that is exactly what 
> ByteToMessageDecoder is for. Please check the javadocs of it for more 
> details.
>
> On 4. Jul 2017, at 11:39, James Kim <[email protected] <javascript:>> 
> wrote:
>
> i made a camel netty4 server program.and client sent 1119 byte message but 
> myu decoder truncated by 1024/95
>
> here is my code.
>
> @ChannelHandler.Sharable
>     public static class BytesDecoder extends 
> MessageToMessageDecoder<ByteBuf> {
>         @Override
>         protected void decode(ChannelHandlerContext ctx, ByteBuf msg, 
> List<Object> out) throws Exception {
>             // it may be empty, then return null
>          System.out.println("BytesDecoder 
> readableBytes:"+msg.readableBytes());
>             if (msg.isReadable()) {
>                 // ByteBuf may not expose array method for accessing the 
> under layer bytes
>                 byte[] bytes = new byte[msg.readableBytes()];
>                 int readerIndex = msg.readerIndex();
>                 msg.getBytes(readerIndex, bytes);
>                 out.add(bytes);
>             }
>         }
>     }
>  
> result 
> BytesDecoder readableBytes:1024
> BytesDecoder readableBytes:95
>
> i want to get a full message byte 1119 byte.
>
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Netty discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/netty/7060c6b2-f193-4da9-a788-7c31269c8d94%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/netty/7060c6b2-f193-4da9-a788-7c31269c8d94%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/a0f3f3bc-9c01-4f39-a9e7-588e54f5b4a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to