You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by oscar 12321 <os...@hotmail.com> on 2006/09/29 01:15:30 UTC
Protocol filters
I have a complex protocol to implement and I have started modifying the
sumup example.
My protocol consists of messages all of then sent in and envelope like
this:
4 bytes: size of data
N bytes: the data
1 byte: tail mark.
Then each message inside the envelope (the data), contains a header byte
with the type of message flllowed by the rest of fields of the message.
My question is: should i implement a stack of two protocol filters, one for
the envelope (like the TextLineCodec), and other for the message data itself
(perhaps a DemuxingProtocolCodec)?
Thanks in advance.
_________________________________________________________________
Grandes éxitos, superhéroes, imitaciones, cine y TV...
http://es.msn.kiwee.com/ Lo mejor para tu móvil.
Re: Protocol filters
Posted by Trustin Lee <tr...@gmail.com>.
On 9/29/06, oscar 12321 <os...@hotmail.com> wrote:
>
> I have a complex protocol to implement and I have started modifying the
> sumup example.
>
> My protocol consists of messages all of then sent in and envelope like
> this:
>
> 4 bytes: size of data
> N bytes: the data
> 1 byte: tail mark.
>
> Then each message inside the envelope (the data), contains a header byte
> with the type of message flllowed by the rest of fields of the message.
>
> My question is: should i implement a stack of two protocol filters, one
> for
> the envelope (like the TextLineCodec), and other for the message data
> itself
> (perhaps a DemuxingProtocolCodec)?
You just need one codec and one custom filter instead of two codecs:
1. Codec translates the message into an intermediary message.
2. Your filter translates the intermediary message (the data, envelope) into
the final message object.
Implementing a filter is very easy, so you will be able to implement the
translator shortly.
...
void messageReceived(NextFilter next, IoSession session, Object message) {
IntermediaryMessage m = (IntermediaryMessage) message;
ByteBuffer buf = m.getContent();
... do something with the buf ...
next.messageReceived(session, newMessage);
}
...
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6