Text Protocol -- Variable length, variable number of lines
Trustin Lee (이희승)
trustin at gmail.com
Thu Nov 19 22:47:27 EST 2009
Hi,
I would simply extend DelimiterBasedFrameDecoder and override its
decode(...) method like the following:
private final StringBuilder buf = new StringBuilder();
private int lineCount;
@Override
protected Object decode(...) {
String frame = super.decode(...);
if (frame == null) {
return null;
}
lineCount ++;
buf.append(frame);
buf.append("\r\n");
if (lineCount == N) {
lineCount = 0;
String realFrame = buf.toString();
buf.delete(0, buf.length());
return realFrame;
}
return null;
}
HTH
— Trustin Lee, http://gleamynode.net/
On Sun, Nov 8, 2009 at 7:54 AM, venky10 <vsayyagari at gmail.com> wrote:
>
> Hi,
>
> In the telnet/server case each newline would trigger a MessageEvent. In my
> case it would be inefficient, I intend to handle MessageEvent after an X
> number (which is variable) of lines have been available for upstream
> processing to the StreamDecoder. If I simple call --
>
> public void messageReceived(
> ChannelHandlerContext ctx, MessageEvent e) {
> // Cast to a String first.
> // We know it is a String because we put some codec in
> TelnetPipelineFactory.
> String several_lines_protocol_msg= (String) e.getMessage();
> :::::
> }
>
> there is no guarantee that all the lines of the protocol packet have been
> captured in
> "several_lines_protocol_msg". Or is it the case that if FrameDecoder is not
> supplied the message received will be all the bytes available in the stream
> ?
>
> Thanks a lot.
> Venkay
>
>
> Trustin Lee wrote:
>>
>> Hi Venky,
>>
>> DelimiterBasedFrameDecoder is perhaps what you are looking for. Also,
>> please refer to the telnet client/server example.
>>
>> HTH
>>
>> — Trustin Lee, http://gleamynode.net/
>>
>>
>>
>> On Sat, Nov 7, 2009 at 7:11 AM, venky10 <vsayyagari at gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I am a newbie to Netty.
>>> I have text protocol to decode. It has variable number of lines, all
>>> delimited by 'newline'.
>>> There is no other end-of-frame delimiter. I am assuming it would be most
>>> efficient to read the entire frame till there are no more lines to be
>>> read
>>> on single MessageEvent.
>>>
>>> What is the best approach ?
>>>
>>> Thanks,
>>> Venky
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/Text-Protocol-Variable-length-variable-number-of-lines-tp3961650p3961650.html
>>> Sent from the Netty User Group mailing list archive at Nabble.com.
>>> _______________________________________________
>>> netty-users mailing list
>>> netty-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/netty-users
>>>
>>
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
>>
>>
>
> --
> View this message in context: http://n2.nabble.com/Text-Protocol-Variable-length-variable-number-of-lines-tp3961650p3966051.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
More information about the netty-users
mailing list