On Tue, Jan 26, 2010 at 7:32 AM, jose vilmar estacio de souza <[email protected]> wrote: > Hi all, > I need to write a codec to encode/decode a message and would not want to > reinvent the wheel. > The message sent by the client connection has the following layout: > 1: Header with a fixed length of 1444 bytes. > 2: Data with a variable length. The length of data is stored in the > position 67 of header with 6 bytes. > > What I'm thinking is to do as follows: > 1: Create a class that extends CumulativeProtocolDecoder. > 2: In the doDecode method implement the following logic: > > if (in.remaining() < SZ_HEADER) { return false;} > int t = sizeOfDataFromHeader(in); > if (in.remaining() < SZ_HEADER+t) { return false;} > out.write(new Message(in)); > return true; > > I would like to ask two questions: > Is there anything ready so I do not have to implement anything?
I am afraid, we just have examples > If not, what I'm doing is correct or should I implement it differently? Its fine just u need to take care of one situation. Since u store bytes in session, you may get OOM, if you have too many client and too much of data. Can use file mapped buffer, if there is a need. Rest is good to go.. Good Luck! > Thanks > > - > []S José Vilmar Estácio de Souza > http://www.informal.com.br > Msn:[email protected] Skype:jvilmar > Twitter: http://www.twitter.com/jvesouza > Phone: +55 21-2555-2650 Cel: +55 21-8868-0859 > > -- thanks ashish Blog: http://www.ashishpaliwal.com/blog My Photo Galleries: http://www.pbase.com/ashishpaliwal
