You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Sungwon Jung <th...@gmail.com> on 2007/09/12 15:03:33 UTC

doDecode() can't return true when buffer is not consumed.

Hello. I'm using MINA 1.1.2.

I have a question. what's the mean below message?

--
EXCEPTION: org.apache.mina.filter.codec.ProtocolDecoderException:
java.lang.IllegalStateException: doDecode() can't return true when
buffer is not consumed. (Hexdump: empty)
--

it's minor problem in my program?

Re: doDecode() can't return true when buffer is not consumed.

Posted by Sungwon Jung <th...@gmail.com>.
I replaced absolute position with in.get().

Thank you.


On 9/13/07, Maarten Bosteels <mb...@gmail.com> wrote:
> In other words: try replacing  in.get(0) with in.get()
>
> Maarten
>
> On 9/13/07, Trustin Lee <tr...@gmail.com> wrote:
> >
> > On 9/12/07, Sungwon Jung <th...@gmail.com> wrote:
> > > thank you reply.
> > >
> > > doDecode() implementation is below.
> > >
> > > --
> > > public class ACUPacketReqAnalysis extends CumulativeProtocolDecoder
> > > {
> > >         Logger logger = Logger.getLogger( this.getClass() );
> > >
> > >         private int     device = Constants.DEVICE_NONE;
> > >
> > >         protected boolean doDecode(IoSession session, ByteBuffer in,
> > > ProtocolDecoderOutput out) throws Exception {
> > >                 int start = in.get( 0 ) & 0xFF;
> > >
> > >                 if( start == PacketDefineACU.START ) {
> > >                         session.setAttribute( Constants.SESSION_DEVICE,
> > Constants.DEVICE_ACU );
> > >
> > >                         ACUMessageReq acu_request = new ACUMessageReq(
> > session, in, out, start );
> > >                         out.write( acu_request );
> > >
> > >                         return true;
> > >                 } else {
> > >                         return false;
> > >                 }
> > >         }
> > > }
> >
> > It seems like you don't move the position of the input buffer after
> > decoding a message.  Please more the buffer position to the end of the
> > message (note that it's not the end of the buffer).
> >
> > And you shall not use absolute addressing (e.g. in.get(0)) because you
> > cannot assume that the offset (position) of the first byte is always
> > zero.
> >
> > HTH,
> > Trustin
> > --
> > what we call human nature is actually human habit
> > --
> > http://gleamynode.net/
> > --
> > PGP Key ID: 0x0255ECA6

Re: doDecode() can't return true when buffer is not consumed.

Posted by Maarten Bosteels <mb...@gmail.com>.
In other words: try replacing  in.get(0) with in.get()

Maarten

On 9/13/07, Trustin Lee <tr...@gmail.com> wrote:
>
> On 9/12/07, Sungwon Jung <th...@gmail.com> wrote:
> > thank you reply.
> >
> > doDecode() implementation is below.
> >
> > --
> > public class ACUPacketReqAnalysis extends CumulativeProtocolDecoder
> > {
> >         Logger logger = Logger.getLogger( this.getClass() );
> >
> >         private int     device = Constants.DEVICE_NONE;
> >
> >         protected boolean doDecode(IoSession session, ByteBuffer in,
> > ProtocolDecoderOutput out) throws Exception {
> >                 int start = in.get( 0 ) & 0xFF;
> >
> >                 if( start == PacketDefineACU.START ) {
> >                         session.setAttribute( Constants.SESSION_DEVICE,
> Constants.DEVICE_ACU );
> >
> >                         ACUMessageReq acu_request = new ACUMessageReq(
> session, in, out, start );
> >                         out.write( acu_request );
> >
> >                         return true;
> >                 } else {
> >                         return false;
> >                 }
> >         }
> > }
>
> It seems like you don't move the position of the input buffer after
> decoding a message.  Please more the buffer position to the end of the
> message (note that it's not the end of the buffer).
>
> And you shall not use absolute addressing (e.g. in.get(0)) because you
> cannot assume that the offset (position) of the first byte is always
> zero.
>
> HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>

Re: doDecode() can't return true when buffer is not consumed.

Posted by Trustin Lee <tr...@gmail.com>.
On 9/12/07, Sungwon Jung <th...@gmail.com> wrote:
> thank you reply.
>
> doDecode() implementation is below.
>
> --
> public class ACUPacketReqAnalysis extends CumulativeProtocolDecoder
> {
>         Logger logger = Logger.getLogger( this.getClass() );
>
>         private int     device = Constants.DEVICE_NONE;
>
>         protected boolean doDecode(IoSession session, ByteBuffer in,
> ProtocolDecoderOutput out) throws Exception {
>                 int start = in.get( 0 ) & 0xFF;
>
>                 if( start == PacketDefineACU.START ) {
>                         session.setAttribute( Constants.SESSION_DEVICE, Constants.DEVICE_ACU );
>
>                         ACUMessageReq acu_request = new ACUMessageReq( session, in, out, start );
>                         out.write( acu_request );
>
>                         return true;
>                 } else {
>                         return false;
>                 }
>         }
> }

It seems like you don't move the position of the input buffer after
decoding a message.  Please more the buffer position to the end of the
message (note that it's not the end of the buffer).

And you shall not use absolute addressing (e.g. in.get(0)) because you
cannot assume that the offset (position) of the first byte is always
zero.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: doDecode() can't return true when buffer is not consumed.

Posted by Sungwon Jung <th...@gmail.com>.
thank you reply.

doDecode() implementation is below.

--
public class ACUPacketReqAnalysis extends CumulativeProtocolDecoder
{
	Logger logger = Logger.getLogger( this.getClass() );

	private int	device = Constants.DEVICE_NONE;
	
	protected boolean doDecode(IoSession session, ByteBuffer in,
ProtocolDecoderOutput out) throws Exception {
		int start = in.get( 0 ) & 0xFF;

		if( start == PacketDefineACU.START ) {
			session.setAttribute( Constants.SESSION_DEVICE, Constants.DEVICE_ACU );

			ACUMessageReq acu_request = new ACUMessageReq( session, in, out, start );
			out.write( acu_request );

			return true;
		} else {
			return false;
		}
	}
}


On 9/12/07, Maarten Bosteels <mb...@gmail.com> wrote:
> It means that your doDecode() implementation returned true but didn't alter
> the position of the ByteBuffer.
>
> see
> http://mina.apache.org/report/1.1/xref/org/apache/mina/filter/codec/CumulativeProtocolDecoder.html#136
>
> Could you show us your doDecode() implementation ?
>
> Maarten
>
>
> On 9/12/07, Sungwon Jung <th...@gmail.com> wrote:
> >
> > Hello. I'm using MINA 1.1.2.
> >
> > I have a question. what's the mean below message?
> >
> > --
> > EXCEPTION: org.apache.mina.filter.codec.ProtocolDecoderException:
> > java.lang.IllegalStateException: doDecode() can't return true when
> > buffer is not consumed. (Hexdump: empty)
> > --
> >
> > it's minor problem in my program?

Re: doDecode() can't return true when buffer is not consumed.

Posted by Maarten Bosteels <mb...@gmail.com>.
It means that your doDecode() implementation returned true but didn't alter
the position of the ByteBuffer.

see
http://mina.apache.org/report/1.1/xref/org/apache/mina/filter/codec/CumulativeProtocolDecoder.html#136

Could you show us your doDecode() implementation ?

Maarten


On 9/12/07, Sungwon Jung <th...@gmail.com> wrote:
>
> Hello. I'm using MINA 1.1.2.
>
> I have a question. what's the mean below message?
>
> --
> EXCEPTION: org.apache.mina.filter.codec.ProtocolDecoderException:
> java.lang.IllegalStateException: doDecode() can't return true when
> buffer is not consumed. (Hexdump: empty)
> --
>
> it's minor problem in my program?
>