On Feb 19, 2008 3:39 PM, Christian Migowski <[EMAIL PROTECTED]> wrote:

> I am curious, how would that ByteArrayCodecFactory help?


It would just be convenient for people that need to send/receive
a byte[] with a length prefix.

>
>
> I had to deal with a protocol that hasn't neither a fixed length nor a
> fixed
> delimiter (it is XML fragments sent directly on the wire, without any
> header, so the Msg was complete when i found a matching end tag to a list
> of
> start tags).


Is it a custom protocol ? I think the protocol smells a bit.
Is the character encoding used in the XML fragments always the same ?

You're gonna have a hard time decoding when clients are allowed to send XML
using the encoding of their choice (eg. both UTF-8 and UTF-16)

Maarten


> The reason may be that i am still inexperienced with the Java
> way of doing things, but the solution i found was to read up to a certain
> amount of bytes (using the method below), check if the message was
> complete,
> if not rewind the buffer to the start position and wait for the next
> invocation.
>
> christian!
>
>
> On 2/19/08, Maarten Bosteels <[EMAIL PROTECTED]> wrote:
> >
> > Have a look at
> >
> >
> http://www.nabble.com/Re%3A-sending-receiving-a-byte---p14220485s16868.html
> >
> > Is your array of bytes prefixed with a length indicator ?
> > If not, how do you know the end of the message ?
> >
> > Maybe we should add a ByteArrayCodecFactory to MINA.
> >
> > Maarten
> >
> > On Feb 19, 2008 3:19 PM, Christian Migowski <[EMAIL PROTECTED]>
> wrote:
> >
> > > Hi,
> > >
> > > i stumbled over this as well some time ago. The Javadoc says this
> > > exception
> > > happens when the ByteBuffer isn't backed by an accessible array, my
> > > finding
> > > was it isn't guaranteed in any way it is - better do not rely on that
> > > method.
> > > Fortunately you can easily rewrite your code to
> > >
> > >     int len = in.remaining();
> > > //(i do think your usage of limit() is not what you intend to do)
> > >     byte[] stream = new byte[len];
> > >     in.get(stream , 0, in.remaining());
> > >
> > >
> > > hope that helps.
> > > regards,
> > > christian!
> > >
> > >
> > > On 2/19/08, Brenno Hayden <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Hi,
> > > >
> > > > I am having a difficulty in mke this cast? Can I do something? Some
> > tip
> > > ?
> > > >
> > > > *code*
> > > >
> > > > ByteArrayDecoder extends CumulativeProtocolDecoder {
> > > >
> > > > protected boolean doDecode(IoSession session, ByteBuffer in,
> > > > ProtocolDecoderOutput out) throws Exception {
> > > >     if (in instanceof ByteBuffer) {
> > > >      int len = in.limit();
> > > >      byte[] stream = new byte[len];
> > > >      //TODO
> > > >      stream = in.array(); // Why ?
> > > >      out.write(stream);
> > > >      return true;
> > > >     }else {
> > > >       return false.
> > > >     }
> > > > }
> > > >
> > > > *console*:
> > > >
> > > > org.apache.mina.filter.codec.ProtocolDecoderException:
> > > > java.lang.UnsupportedOperationException
> > > >
> > > >
> > > >
> > > > Thanks
> > > >
> > > >
> > > > --
> > > > ________________________
> > > > Brenno Hayden F. Dantas
> > > >
> > >
> >
>

Reply via email to