diff options
author | Steven Shaw <steshaw@apache.org> | 2006-12-12 17:36:17 +0000 |
---|---|---|
committer | Steven Shaw <steshaw@apache.org> | 2006-12-12 17:36:17 +0000 |
commit | b10ee442673d6d9c8abb46bd7a0606364930130d (patch) | |
tree | 07827981760e15f8dcf5f5af892c3a0bad2eba66 /dotnet/Qpid.Codec/CumulativeProtocolDecoder.cs | |
parent | 7d0a7581134379324b36d78f8c49dcd793d1ab1e (diff) | |
download | qpid-python-b10ee442673d6d9c8abb46bd7a0606364930130d.tar.gz |
QPID-139. Initial (re)port of MINA's bytebuffer abstraction. Now includes the autoexpand feature. References to java.nio.Buffer were replaced with FixedByteBuffer and necessary methods added and implemented. FixedByteBuffer delegates to our existing HeapByteBuffer.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@486248 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'dotnet/Qpid.Codec/CumulativeProtocolDecoder.cs')
-rw-r--r-- | dotnet/Qpid.Codec/CumulativeProtocolDecoder.cs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/dotnet/Qpid.Codec/CumulativeProtocolDecoder.cs b/dotnet/Qpid.Codec/CumulativeProtocolDecoder.cs index 70b4940c7b..21614cf108 100644 --- a/dotnet/Qpid.Codec/CumulativeProtocolDecoder.cs +++ b/dotnet/Qpid.Codec/CumulativeProtocolDecoder.cs @@ -28,14 +28,13 @@ namespace Qpid.Codec ByteBuffer _remaining; /// <summary> - /// Creates a new instance with the 65535 bytes initial capacity of + /// Creates a new instance with the 4096 bytes initial capacity of /// cumulative buffer. - /// Note that capacity is currently fixed as the .NET ByteBuffers does not implement auto-expansion. /// </summary> protected CumulativeProtocolDecoder() { - // Needs to be as large as the largest frame to be decoded. - _remaining = ByteBuffer.Allocate(65535); // FIXME: Probably should not be fixed. + _remaining = ByteBuffer.allocate(4096); + _remaining.setAutoExpand(true); } /// <summary> @@ -49,7 +48,7 @@ namespace Qpid.Codec /// </exception> public void Decode(ByteBuffer input, IProtocolDecoderOutput output) { - if (_remaining.Position != 0) // If there were remaining undecoded bytes + if (_remaining.position() != 0) // If there were remaining undecoded bytes { DecodeRemainingAndInput(input, output); } @@ -68,9 +67,9 @@ namespace Qpid.Codec } finally { - if (input.HasRemaining()) + if (input.hasRemaining()) { - _remaining.Put(input); + _remaining.put(input); } } } @@ -78,8 +77,8 @@ namespace Qpid.Codec private void DecodeRemainingAndInput(ByteBuffer input, IProtocolDecoderOutput output) { // Concatenate input buffer with left-over bytes. - _remaining.Put(input); - _remaining.Flip(); + _remaining.put(input); + _remaining.flip(); try { @@ -87,7 +86,7 @@ namespace Qpid.Codec } finally { - _remaining.Compact(); + _remaining.compact(); } } @@ -95,17 +94,17 @@ namespace Qpid.Codec { for (;;) { - int oldPos = buf.Position; + int oldPos = buf.position(); bool decoded = DoDecode(buf, output); if (decoded) { - if (buf.Position == oldPos) + if (buf.position() == oldPos) { throw new Exception( "doDecode() can't return true when buffer is not consumed."); } - if (!buf.HasRemaining()) + if (!buf.hasRemaining()) { break; } |