cvs commit: spice/sandbox/packet/src/java/org/realityforge/packet/encoder BasicEncoder.java
Peter Donald <[email protected]> Tue, 11 Nov 2003 04:12:43 -0800
| Newsgroups | gmane.comp.java.spice.cvs |
|---|---|
| Message-ID | <[email protected]> |
donaldp 03/11/11 04:12:43
Modified: sandbox/packet/src/java/org/realityforge/packet/encoder
BasicEncoder.java
Log:
Fix up setting of limit of input buffer
Revision Changes Path
1.6 +9 -5 spice/sandbox/packet/src/java/org/realityforge/packet/encoder/BasicEncoder.java
Index: BasicEncoder.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/packet/src/java/org/realityforge/packet/encoder/BasicEncoder.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BasicEncoder.java 11 Nov 2003 11:50:53 -0000 1.5
+++ BasicEncoder.java 11 Nov 2003 12:12:43 -0000 1.6
@@ -14,7 +14,7 @@
* A basic encoder that writes packet using simple mechanisms.
*
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
- * @version $Revision: 1.5 $ $Date: 2003/11/11 11:50:53 $
+ * @version $Revision: 1.6 $ $Date: 2003/11/11 12:12:43 $
*/
public class BasicEncoder
implements Encoder
@@ -48,25 +48,29 @@
*/
public Packet decode( final ByteBuffer input )
{
- final int index = input.position();
- input.position( 0 );
- if( input.remaining() < SIZEOF_HEADER )
+ final int size = input.limit();
+ if( size < SIZEOF_HEADER )
{
- input.position( index );
return null;
}
+ final int index = input.position();
+ input.position( 0 );
final short messageSize = input.getShort();
final short sequence = input.getShort();
final int available = input.remaining();
if( available >= messageSize )
{
final ByteBuffer byteBuffer = ByteBuffer.allocate( messageSize );
+ byteBuffer.limit( messageSize );
+ byteBuffer.position( 0 );
System.arraycopy( input.array(), SIZEOF_HEADER,
byteBuffer.array(), 0,
messageSize );
final int end = messageSize + SIZEOF_HEADER;
input.position( end );
input.compact();
+ input.position( 0 );
+ input.limit( size - end );
return new Packet( sequence, 0, byteBuffer );
}
else
-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/