I. Eventencoder and Eventdecoder
The event encoder receives an event object and transforms it into a Channelbuffer object. The encoder first reads the event type and acts as the opcode (the first byte of the buffer), then reads the event body and transforms it into a Channelbuffer object as the body of the message.
/*** A Simple Event encoder would receive an incoming event, and convert it to A * {@linkChannelbuffer}.  It would read the event type and put it as the * opcode (i.e first byte of the buffer), then it would read the event body and * Put convert to channelbuffer if necessary and put it as the body of the * message. *  * @authorAbraham Menacherry **/@Sharable Public classEventencoderextendsonetooneencoder{Private Static FinalLogger LOG =loggerfactory. GetLogger (Eventdecoder.class); @OverrideprotectedObject Encode (Channelhandlercontext CTX, channel Channel, Object msg)throwsException {if(NULL==msg) {Log.error ("Received null message in Eventencoder"); returnmsg; } Event Event=(Event) msg; Channelbuffer opcode= Channelbuffers.buffer (1);        Opcode.writebyte (Event.gettype ()); Channelbuffer Buffer=NULL; if(NULL!=Event.getsource ()) {Channelbuffer Data=(Channelbuffer) Event.getsource (); Buffer=channelbuffers.wrappedbuffer (opcode, data); }        Else{buffer=opcode; }        returnbuffer; }}
Jetserver Open Source Project Learning (eight)--Decoding encoder usage