Yes, JUnits are surely needed. Since all the needed bytes to construct the final object are already read from the buffer in the decodable method of the MessageDecoder, I am thinking it would be a better to construct the object and add it to the session in the decodable method, so that the decode method then just gets the object from the session and returns it.
Thanks, Amit. On Thu, Jul 29, 2010 at 3:05 AM, Emmanuel Lecharny <[email protected]>wrote: > On 7/28/10 11:25 PM, Emmanuel Lécharny wrote: > >> Forwarded to the mailing list >> >> Ok I get your point. Thanks. >> To be sure that I understand it correct, in the decodable method of the >> MessageDecoder, I would have to make sure that the IoBuffer received is >> complete by checking if buffer.remaining() contains the required number of >> bytes. This would have to be done by implementing something as below >> >> public MessageDecoderResult decodable(IoSession session, IoBuffer in) { >> if(in.remaining()> 4) { //Check if the buffer contains bytes to >> hold the initial size of the map. 4 bytes for an int. >> int mapSize = in.getInt(); >> for(int i=0; i<mapSize; i++) { >> if(in.remaining()> 4) { //Check if the buffer contains >> bytes to hold the key string size >> int keyStringSize = in.getInt(); >> if(in.remaining()> keyStringSize) { //Check if the >> buffer contains bytes to hold the key >> in.get(new byte[keyStringSize]); >> if(in.remaining()> 4 ) { //Check if the buffer >> contains bytes to hold the value string size >> int valueSize = in.getInt(); >> if(in.remaining()>= valueSize) { //Check if >> the buffer contains bytes to hold the value string >> in.get(new byte[valueSize]); >> } else { >> return MessageDecoderResult.NEED_DATA; >> } >> } else { >> return MessageDecoderResult.NEED_DATA; >> } >> } else { >> return MessageDecoderResult.NEED_DATA; >> } >> >> } else { >> return MessageDecoderResult.NEED_DATA; >> } >> } >> >> return MessageDecoderResult.OK; >> } >> return MessageDecoderResult.NOT_OK; >> } >> >> I understand that its difficult to read out the code, but I wanted to sure >> I >> understand this correctly. >> > > Sounds good to me. It has to be tested though :) > > > -- > Regards, > Cordialement, > Emmanuel Lécharny > www.iktek.com > >
