summaryrefslogtreecommitdiff
path: root/qpid/dotnet/Qpid.Client
diff options
context:
space:
mode:
authorSteven Shaw <steshaw@apache.org>2006-12-12 17:36:17 +0000
committerSteven Shaw <steshaw@apache.org>2006-12-12 17:36:17 +0000
commitad8fa512e788075a4573678738b6f11f1c8cbd59 (patch)
tree69eef3dfec5848f489a9f129237e38ae35b3079c /qpid/dotnet/Qpid.Client
parent4e1735463fdb63f87d03541c33a816a5c7af563f (diff)
downloadqpid-python-ad8fa512e788075a4573678738b6f11f1c8cbd59.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@486248 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/dotnet/Qpid.Client')
-rw-r--r--qpid/dotnet/Qpid.Client/Client/AmqChannel.cs3
-rw-r--r--qpid/dotnet/Qpid.Client/Client/Message/AMQMessageFactory.cs10
-rw-r--r--qpid/dotnet/Qpid.Client/Client/Message/AbstractQmsMessage.cs6
-rw-r--r--qpid/dotnet/Qpid.Client/Client/Message/QpidBytesMessage.cs22
-rw-r--r--qpid/dotnet/Qpid.Client/Client/Message/QpidTextMessage.cs15
5 files changed, 33 insertions, 23 deletions
diff --git a/qpid/dotnet/Qpid.Client/Client/AmqChannel.cs b/qpid/dotnet/Qpid.Client/Client/AmqChannel.cs
index a66e4f8a8a..6e70eb54e0 100644
--- a/qpid/dotnet/Qpid.Client/Client/AmqChannel.cs
+++ b/qpid/dotnet/Qpid.Client/Client/AmqChannel.cs
@@ -819,7 +819,8 @@ namespace Qpid.Client
byte[] payload = null;
if (buf != null)
{
- payload = buf.ToByteArray();
+ payload = new byte[buf.remaining()];
+ buf.get(payload);
}
BasicContentHeaderProperties contentHeaderProperties = message.ContentHeaderProperties;
diff --git a/qpid/dotnet/Qpid.Client/Client/Message/AMQMessageFactory.cs b/qpid/dotnet/Qpid.Client/Client/Message/AMQMessageFactory.cs
index dd9855d675..ad1bc55d87 100644
--- a/qpid/dotnet/Qpid.Client/Client/Message/AMQMessageFactory.cs
+++ b/qpid/dotnet/Qpid.Client/Client/Message/AMQMessageFactory.cs
@@ -62,20 +62,20 @@ namespace Qpid.Client.Message
if (bodies != null && bodies.Count == 1)
{
_logger.Debug("Non-fragmented message body (bodySize=" + contentHeader.BodySize +")");
- data = HeapByteBuffer.wrap(((ContentBody)bodies[0]).Payload);
+ data = ByteBuffer.wrap(((ContentBody)bodies[0]).Payload);
}
else
{
_logger.Debug("Fragmented message body (" + bodies.Count + " frames, bodySize=" + contentHeader.BodySize + ")");
- data = ByteBuffer.Allocate((int)contentHeader.BodySize); // XXX: Is cast a problem?
+ data = ByteBuffer.allocate((int)contentHeader.BodySize); // XXX: Is cast a problem?
foreach (ContentBody body in bodies) {
- data.Put(body.Payload);
+ data.put(body.Payload);
//body.Payload.Release();
}
- data.Flip();
+ data.flip();
}
- _logger.Debug("Creating message from buffer with position=" + data.Position + " and remaining=" + data.Remaining);
+ _logger.Debug("Creating message from buffer with position=" + data.position() + " and remaining=" + data.remaining());
return CreateMessage(messageNbr, data, contentHeader);
}
diff --git a/qpid/dotnet/Qpid.Client/Client/Message/AbstractQmsMessage.cs b/qpid/dotnet/Qpid.Client/Client/Message/AbstractQmsMessage.cs
index 444d00cd04..d6ffcd665c 100644
--- a/qpid/dotnet/Qpid.Client/Client/Message/AbstractQmsMessage.cs
+++ b/qpid/dotnet/Qpid.Client/Client/Message/AbstractQmsMessage.cs
@@ -63,7 +63,7 @@ namespace Qpid.Client.Message
_data = data;
if (_data != null)
{
- _data.Acquire();
+ _data.acquire();
}
_readableMessage = (data != null);
}
@@ -74,7 +74,7 @@ namespace Qpid.Client.Message
_data = data;
if (_data != null)
{
- _data.Acquire();
+ _data.acquire();
}
_readableMessage = data != null;
}
@@ -378,7 +378,7 @@ namespace Qpid.Client.Message
// position beyond the start
if (_data != null)
{
- _data.Rewind();
+ _data.rewind();
}
return _data;
}
diff --git a/qpid/dotnet/Qpid.Client/Client/Message/QpidBytesMessage.cs b/qpid/dotnet/Qpid.Client/Client/Message/QpidBytesMessage.cs
index 866d0d25af..251e7ed57f 100644
--- a/qpid/dotnet/Qpid.Client/Client/Message/QpidBytesMessage.cs
+++ b/qpid/dotnet/Qpid.Client/Client/Message/QpidBytesMessage.cs
@@ -36,7 +36,7 @@ namespace Qpid.Client.Message
/// <summary>
/// The backingstore for the data
/// </summary>
- private MemoryStream _dataStream;
+ private MemoryStream _dataStream; // FIXME: Probably don't need this any more.
private int _bodyLength;
@@ -59,15 +59,17 @@ namespace Qpid.Client.Message
ContentHeaderProperties.ContentType = MIME_TYPE;
if (data == null)
{
- _data = ByteBuffer.Allocate(DEFAULT_BUFFER_INITIAL_SIZE);
+ _data = ByteBuffer.allocate(DEFAULT_BUFFER_INITIAL_SIZE);
//_data.AutoExpand = true;
_dataStream = new MemoryStream();
_writer = new BinaryWriter(_dataStream);
}
else
{
- _dataStream = new MemoryStream(data.ToByteArray());
- _bodyLength = data.ToByteArray().Length;
+ byte[] bytes = new byte[data.remaining()];
+ data.get(bytes);
+ _dataStream = new MemoryStream(bytes);
+ _bodyLength = bytes.Length;
_reader = new BinaryReader(_dataStream);
}
}
@@ -77,15 +79,17 @@ namespace Qpid.Client.Message
: base(messageNbr, (BasicContentHeaderProperties)contentHeader.Properties, data)
{
ContentHeaderProperties.ContentType = MIME_TYPE;
- _dataStream = new MemoryStream(data.ToByteArray());
- _bodyLength = data.ToByteArray().Length;
+ byte[] bytes = new byte[data.remaining()];
+ data.get(bytes);
+ _dataStream = new MemoryStream(bytes);
+ _bodyLength = bytes.Length;
_reader = new BinaryReader(_dataStream);
}
public override void ClearBodyImpl()
{
- _data.Clear();
+ _data.clear();
}
// public override void ClearBody()
@@ -165,7 +169,7 @@ namespace Qpid.Client.Message
get
{
CheckReadable();
- return _data.Limit; // XXX
+ return _data.limit(); // XXX
// return _bodyLength;
}
}
@@ -577,7 +581,7 @@ namespace Qpid.Client.Message
public void Reset()
{
base.Reset();
- _data.Flip();
+ _data.flip();
// CheckWritable();
// try
diff --git a/qpid/dotnet/Qpid.Client/Client/Message/QpidTextMessage.cs b/qpid/dotnet/Qpid.Client/Client/Message/QpidTextMessage.cs
index a9b7d629db..650186a90b 100644
--- a/qpid/dotnet/Qpid.Client/Client/Message/QpidTextMessage.cs
+++ b/qpid/dotnet/Qpid.Client/Client/Message/QpidTextMessage.cs
@@ -90,7 +90,7 @@ namespace Qpid.Client.Message
{
if (_data != null)
{
- _data.Release();
+ _data.release();
}
_data = null;
_decodedValue = null;
@@ -122,15 +122,20 @@ namespace Qpid.Client.Message
return _decodedValue;
}
else
- {
+ {
+ // Read remaining bytes.
+ byte[] bytes = new byte[_data.remaining()];
+ _data.get(bytes);
+
+ // Convert to string based on encoding.
if (ContentHeaderProperties.Encoding != null)
{
// throw ArgumentException if the encoding is not supported
- _decodedValue = Encoding.GetEncoding(ContentHeaderProperties.Encoding).GetString(_data.ToByteArray());
+ _decodedValue = Encoding.GetEncoding(ContentHeaderProperties.Encoding).GetString(bytes);
}
else
{
- _decodedValue = Encoding.Default.GetString(_data.ToByteArray());
+ _decodedValue = Encoding.Default.GetString(bytes);
}
return _decodedValue;
}
@@ -148,7 +153,7 @@ namespace Qpid.Client.Message
// throw ArgumentException if the encoding is not supported
bytes = Encoding.GetEncoding(ContentHeaderProperties.Encoding).GetBytes(value);
}
- _data = HeapByteBuffer.wrap(bytes, bytes.Length);
+ _data = ByteBuffer.wrap(bytes);
_decodedValue = value;
}
}