summaryrefslogtreecommitdiff
path: root/dotnet/Qpid.Common
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
commitb10ee442673d6d9c8abb46bd7a0606364930130d (patch)
tree07827981760e15f8dcf5f5af892c3a0bad2eba66 /dotnet/Qpid.Common
parent7d0a7581134379324b36d78f8c49dcd793d1ab1e (diff)
downloadqpid-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.Common')
-rw-r--r--dotnet/Qpid.Common/Framing/AMQDataBlockDecoder.cs12
-rw-r--r--dotnet/Qpid.Common/Framing/AMQDataBlockEncoder.cs4
-rw-r--r--dotnet/Qpid.Common/Framing/AMQFrame.cs8
-rw-r--r--dotnet/Qpid.Common/Framing/AMQMethodBody.cs4
-rw-r--r--dotnet/Qpid.Common/Framing/BasicContentHeaderProperties.cs10
-rw-r--r--dotnet/Qpid.Common/Framing/ContentBody.cs4
-rw-r--r--dotnet/Qpid.Common/Framing/ContentHeaderBody.cs8
-rw-r--r--dotnet/Qpid.Common/Framing/EncodingUtils.cs45
-rw-r--r--dotnet/Qpid.Common/Framing/FieldTable.cs22
-rw-r--r--dotnet/Qpid.Common/Framing/HeartbeatBody.cs2
-rw-r--r--dotnet/Qpid.Common/Framing/ProtocolInitiation.cs24
-rw-r--r--dotnet/Qpid.Common/stylesheets/utils.xsl12
12 files changed, 81 insertions, 74 deletions
diff --git a/dotnet/Qpid.Common/Framing/AMQDataBlockDecoder.cs b/dotnet/Qpid.Common/Framing/AMQDataBlockDecoder.cs
index f76ac005e4..30be63013a 100644
--- a/dotnet/Qpid.Common/Framing/AMQDataBlockDecoder.cs
+++ b/dotnet/Qpid.Common/Framing/AMQDataBlockDecoder.cs
@@ -51,11 +51,11 @@ namespace Qpid.Framing
}
// final +1 represents the command end which we know we must require even
// if there is an empty body
- if (input.Remaining < 1)
+ if (input.remaining() < 1)
{
return MessageDecoderResult.NEED_DATA;
}
- byte type = input.Get();
+ byte type = input.get();
// we have to check this isn't a protocol initiation frame here - we can't tell later on and we end up
// waiting for more data. This could be improved if MINA supported some kind of state awareness when decoding
@@ -65,7 +65,7 @@ namespace Qpid.Framing
return MessageDecoderResult.NOT_OK;
}
// zero, channel, body size and end byte
- if (input.Remaining < (1 + 2 + 4 + 1))
+ if (input.remaining() < (1 + 2 + 4 + 1))
{
return MessageDecoderResult.NEED_DATA;
}
@@ -80,7 +80,7 @@ namespace Qpid.Framing
return MessageDecoderResult.NOT_OK;
}
- if (input.Remaining < (bodySize + 1))
+ if (input.remaining() < (bodySize + 1))
{
return MessageDecoderResult.NEED_DATA;
}
@@ -116,7 +116,7 @@ namespace Qpid.Framing
protected Object CreateAndPopulateFrame(ByteBuffer input)
{
- byte type = input.Get();
+ byte type = input.get();
ushort channel = input.GetUnsignedShort();
uint bodySize = input.GetUnsignedInt();
@@ -129,7 +129,7 @@ namespace Qpid.Framing
frame.PopulateFromBuffer(input, channel, bodySize, bodyFactory);
- byte marker = input.Get();
+ byte marker = input.get();
//assert marker == 0xCE;
return frame;
}
diff --git a/dotnet/Qpid.Common/Framing/AMQDataBlockEncoder.cs b/dotnet/Qpid.Common/Framing/AMQDataBlockEncoder.cs
index b180e1ac95..6c30040167 100644
--- a/dotnet/Qpid.Common/Framing/AMQDataBlockEncoder.cs
+++ b/dotnet/Qpid.Common/Framing/AMQDataBlockEncoder.cs
@@ -51,14 +51,14 @@ namespace Qpid.Framing
{
IDataBlock frame = (IDataBlock) message;
int frameSize = (int)frame.Size; // TODO: sort out signed/unsigned
- ByteBuffer buffer = ByteBuffer.Allocate(frameSize);
+ ByteBuffer buffer = ByteBuffer.allocate(frameSize);
frame.WritePayload(buffer);
if (_logger.IsDebugEnabled)
{
_logger.Debug("Encoded frame byte-buffer is '" + ByteBufferHexDumper.GetHexDump(buffer) + "'");
}
- buffer.Flip();
+ buffer.flip();
output.Write(buffer);
}
}
diff --git a/dotnet/Qpid.Common/Framing/AMQFrame.cs b/dotnet/Qpid.Common/Framing/AMQFrame.cs
index 2708c331b3..9652cdfabc 100644
--- a/dotnet/Qpid.Common/Framing/AMQFrame.cs
+++ b/dotnet/Qpid.Common/Framing/AMQFrame.cs
@@ -74,12 +74,12 @@ namespace Qpid.Framing
public void WritePayload(ByteBuffer buffer)
{
- buffer.Put(_bodyFrame.BodyType);
+ buffer.put(_bodyFrame.BodyType);
// TODO: how does channel get populated
- buffer.Put(_channel);
- buffer.Put(_bodyFrame.Size);
+ buffer.put(_channel);
+ buffer.put(_bodyFrame.Size);
_bodyFrame.WritePayload(buffer);
- buffer.Put((byte) 0xCE);
+ buffer.put((byte) 0xCE);
}
#endregion
diff --git a/dotnet/Qpid.Common/Framing/AMQMethodBody.cs b/dotnet/Qpid.Common/Framing/AMQMethodBody.cs
index 804e6a4039..96e8e60be1 100644
--- a/dotnet/Qpid.Common/Framing/AMQMethodBody.cs
+++ b/dotnet/Qpid.Common/Framing/AMQMethodBody.cs
@@ -62,8 +62,8 @@ namespace Qpid.Framing
public void WritePayload(ByteBuffer buffer)
{
- buffer.Put(Clazz);
- buffer.Put(Method);
+ buffer.put(Clazz);
+ buffer.put(Method);
WriteMethodPayload(buffer);
}
diff --git a/dotnet/Qpid.Common/Framing/BasicContentHeaderProperties.cs b/dotnet/Qpid.Common/Framing/BasicContentHeaderProperties.cs
index 10d22b0e30..709db419c4 100644
--- a/dotnet/Qpid.Common/Framing/BasicContentHeaderProperties.cs
+++ b/dotnet/Qpid.Common/Framing/BasicContentHeaderProperties.cs
@@ -102,13 +102,13 @@ namespace Qpid.Framing
EncodingUtils.WriteShortStringBytes(buffer, ContentType);
EncodingUtils.WriteShortStringBytes(buffer, Encoding);
EncodingUtils.WriteFieldTableBytes(buffer, Headers);
- buffer.Put(DeliveryMode);
- buffer.Put(Priority);
+ buffer.put(DeliveryMode);
+ buffer.put(Priority);
EncodingUtils.WriteShortStringBytes(buffer, CorrelationId);
EncodingUtils.WriteShortStringBytes(buffer, ReplyTo);
EncodingUtils.WriteShortStringBytes(buffer, String.Format("{0:D}", Expiration));
EncodingUtils.WriteShortStringBytes(buffer, MessageId);
- buffer.Put(Timestamp);
+ buffer.put(Timestamp);
EncodingUtils.WriteShortStringBytes(buffer, Type);
EncodingUtils.WriteShortStringBytes(buffer, UserId);
EncodingUtils.WriteShortStringBytes(buffer, AppId);
@@ -125,9 +125,9 @@ namespace Qpid.Framing
if ((propertyFlags & (1 << 13)) > 0)
Headers = EncodingUtils.ReadFieldTable(buffer);
if ((propertyFlags & (1 << 12)) > 0)
- DeliveryMode = buffer.Get();
+ DeliveryMode = buffer.get();
if ((propertyFlags & (1 << 11)) > 0)
- Priority = buffer.Get();
+ Priority = buffer.get();
if ((propertyFlags & (1 << 10)) > 0)
CorrelationId = EncodingUtils.ReadShortString(buffer);
if ((propertyFlags & (1 << 9)) > 0)
diff --git a/dotnet/Qpid.Common/Framing/ContentBody.cs b/dotnet/Qpid.Common/Framing/ContentBody.cs
index e8bc003f65..4e7ae2019a 100644
--- a/dotnet/Qpid.Common/Framing/ContentBody.cs
+++ b/dotnet/Qpid.Common/Framing/ContentBody.cs
@@ -54,7 +54,7 @@ namespace Qpid.Framing
{
if (Payload != null)
{
- buffer.Put(Payload);
+ buffer.put(Payload);
}
}
@@ -63,7 +63,7 @@ namespace Qpid.Framing
if (size > 0)
{
Payload = new byte[size];
- buffer.Get(Payload);
+ buffer.get(Payload);
}
}
diff --git a/dotnet/Qpid.Common/Framing/ContentHeaderBody.cs b/dotnet/Qpid.Common/Framing/ContentHeaderBody.cs
index a3f71c41aa..f72f6208bc 100644
--- a/dotnet/Qpid.Common/Framing/ContentHeaderBody.cs
+++ b/dotnet/Qpid.Common/Framing/ContentHeaderBody.cs
@@ -73,10 +73,10 @@ namespace Qpid.Framing
public void WritePayload(ByteBuffer buffer)
{
- buffer.Put(ClassId);
- buffer.Put(Weight);
- buffer.Put(BodySize);
- buffer.Put(Properties.PropertyFlags);
+ buffer.put(ClassId);
+ buffer.put(Weight);
+ buffer.put(BodySize);
+ buffer.put(Properties.PropertyFlags);
Properties.WritePropertyListPayload(buffer);
}
diff --git a/dotnet/Qpid.Common/Framing/EncodingUtils.cs b/dotnet/Qpid.Common/Framing/EncodingUtils.cs
index 748f3c9a0c..bb51f14b18 100644
--- a/dotnet/Qpid.Common/Framing/EncodingUtils.cs
+++ b/dotnet/Qpid.Common/Framing/EncodingUtils.cs
@@ -91,14 +91,14 @@ namespace Qpid.Framing
encodedString = DEFAULT_ENCODER.GetBytes(s);
}
// TODO: check length fits in an unsigned byte
- buffer.Put((byte) encodedString.Length);
- buffer.Put(encodedString);
+ buffer.put((byte) encodedString.Length);
+ buffer.put(encodedString);
}
else
{
// really writing out unsigned byte
- buffer.Put((byte) 0);
+ buffer.put((byte) 0);
}
}
@@ -110,17 +110,17 @@ namespace Qpid.Framing
}
if (s != null)
{
- buffer.Put((uint)s.Length);
+ buffer.put((uint)s.Length);
byte[] encodedString = null;
lock (DEFAULT_ENCODER)
{
encodedString = DEFAULT_ENCODER.GetBytes(s);
}
- buffer.Put(encodedString);
+ buffer.put(encodedString);
}
else
{
- buffer.Put((uint) 0);
+ buffer.put((uint) 0);
}
}
@@ -132,7 +132,7 @@ namespace Qpid.Framing
}
else
{
- buffer.Put((uint) 0);
+ buffer.put((uint) 0);
}
}
@@ -147,25 +147,25 @@ namespace Qpid.Framing
}
}
- buffer.Put(packedValue);
+ buffer.put(packedValue);
}
public static void WriteLongstr(ByteBuffer buffer, byte[] data)
{
if (data != null)
{
- buffer.Put((uint) data.Length);
- buffer.Put(data);
+ buffer.put((uint) data.Length);
+ buffer.put(data);
}
else
{
- buffer.Put((uint) 0);
+ buffer.put((uint) 0);
}
}
public static bool[] ReadBooleans(ByteBuffer buffer)
{
- byte packedValue = buffer.Get();
+ byte packedValue = buffer.get();
bool[] result = new bool[8];
for (int i = 0; i < 8; i++)
@@ -202,39 +202,46 @@ namespace Qpid.Framing
/// <exception cref="AMQFrameDecodingException">if the buffer does not contain a decodable short string</exception>
public static string ReadShortString(ByteBuffer buffer)
{
- byte length = buffer.Get();
+ byte length = buffer.get();
if (length == 0)
{
return null;
}
else
{
+ byte[] data = new byte[length];
+ buffer.get(data);
+
lock (DEFAULT_ENCODER)
{
- return buffer.GetString(length, DEFAULT_ENCODER);
+ return DEFAULT_ENCODER.GetString(data);
+// return buffer.GetString(length, DEFAULT_ENCODER);
}
}
}
public static string ReadLongString(ByteBuffer buffer)
{
- uint length = buffer.GetUnsignedInt();
+ uint length = buffer.getUnsignedInt();
if (length == 0)
{
return null;
}
else
- {
+ {
+ byte[] data = new byte[length];
+ buffer.get(data);
lock (DEFAULT_ENCODER)
{
- return buffer.GetString(length, DEFAULT_ENCODER);
+ return DEFAULT_ENCODER.GetString(data);
+ //return buffer.GetString(length, DEFAULT_ENCODER);
}
}
}
public static byte[] ReadLongstr(ByteBuffer buffer)
{
- uint length = buffer.GetUnsignedInt();
+ uint length = buffer.getUnsignedInt();
if (length == 0)
{
return null;
@@ -242,7 +249,7 @@ namespace Qpid.Framing
else
{
byte[] result = new byte[length];
- buffer.Get(result);
+ buffer.get(result);
return result;
}
}
diff --git a/dotnet/Qpid.Common/Framing/FieldTable.cs b/dotnet/Qpid.Common/Framing/FieldTable.cs
index 4c613aa80d..193d96f6cd 100644
--- a/dotnet/Qpid.Common/Framing/FieldTable.cs
+++ b/dotnet/Qpid.Common/Framing/FieldTable.cs
@@ -60,10 +60,10 @@ namespace Qpid.Framing
int sizeRead = 0;
while (sizeRead < _encodedSize)
{
- int sizeRemaining = buffer.Remaining;
+ int sizeRemaining = buffer.remaining();
string key = EncodingUtils.ReadShortString(buffer);
// TODO: use proper charset decoder
- char type = (char)buffer.Get();
+ char type = (char)buffer.get();
object value;
switch (type)
{
@@ -76,7 +76,7 @@ namespace Qpid.Framing
default:
throw new AMQFrameDecodingException("Unsupported field table type: '" + type + "' charcode" + (int)type);
}
- sizeRead += (sizeRemaining - buffer.Remaining);
+ sizeRead += (sizeRemaining - buffer.remaining());
_hash.Add(key, value);
}
@@ -123,7 +123,7 @@ namespace Qpid.Framing
public void WriteToBuffer(ByteBuffer buffer)
{
// Write out the total length, which we have kept up to date as data is added.
- buffer.Put(_encodedSize);
+ buffer.put(_encodedSize);
WritePayload(buffer);
}
@@ -136,20 +136,20 @@ namespace Qpid.Framing
object value = lde.Value;
if (value is byte[])
{
- buffer.Put((byte) 'S');
+ buffer.put((byte) 'S');
EncodingUtils.WriteLongstr(buffer, (byte[]) value);
}
else if (value is string)
{
// TODO: look at using proper charset encoder
- buffer.Put((byte) 'S');
+ buffer.put((byte) 'S');
EncodingUtils.WriteLongStringBytes(buffer, (string) value);
}
else if (value is uint)
{
// TODO: look at using proper charset encoder
- buffer.Put((byte) 'I');
- buffer.Put((uint) value);
+ buffer.put((byte) 'I');
+ buffer.put((uint) value);
}
else
{
@@ -161,11 +161,11 @@ namespace Qpid.Framing
public byte[] GetDataAsBytes()
{
- ByteBuffer buffer = ByteBuffer.Allocate((int)_encodedSize);
+ ByteBuffer buffer = ByteBuffer.allocate((int)_encodedSize);
WritePayload(buffer);
byte[] result = new byte[_encodedSize];
- buffer.Flip();
- buffer.Get(result);
+ buffer.flip();
+ buffer.get(result);
//buffer.Release();
return result;
}
diff --git a/dotnet/Qpid.Common/Framing/HeartbeatBody.cs b/dotnet/Qpid.Common/Framing/HeartbeatBody.cs
index 3fdaa7e850..07f9f345bb 100644
--- a/dotnet/Qpid.Common/Framing/HeartbeatBody.cs
+++ b/dotnet/Qpid.Common/Framing/HeartbeatBody.cs
@@ -52,7 +52,7 @@ namespace Qpid.Framing
if (size > 0)
{
//allow other implementations to have a payload, but ignore it:
- buffer.Skip((int) size);
+ buffer.skip((int) size);
}
}
diff --git a/dotnet/Qpid.Common/Framing/ProtocolInitiation.cs b/dotnet/Qpid.Common/Framing/ProtocolInitiation.cs
index 44c9dafd97..886fbcee09 100644
--- a/dotnet/Qpid.Common/Framing/ProtocolInitiation.cs
+++ b/dotnet/Qpid.Common/Framing/ProtocolInitiation.cs
@@ -72,12 +72,12 @@ namespace Qpid.Framing
{
foreach (char c in Header)
{
- buffer.Put((byte) c);
+ buffer.put((byte) c);
}
- buffer.Put(ProtocolClass);
- buffer.Put(ProtocolInstance);
- buffer.Put(ProtocolMajor);
- buffer.Put(ProtocolMinor);
+ buffer.put(ProtocolClass);
+ buffer.put(ProtocolInstance);
+ buffer.put(ProtocolMajor);
+ buffer.put(ProtocolMinor);
}
/// <summary>
@@ -99,7 +99,7 @@ namespace Qpid.Framing
{
return MessageDecoderResult.NOT_OK;
}
- if (inbuf.Remaining < 8)
+ if (inbuf.remaining() < 8)
{
return MessageDecoderResult.NEED_DATA;
}
@@ -108,7 +108,7 @@ namespace Qpid.Framing
char[] expected = new char[]{'A', 'M', 'Q', 'P'};
for (int i = 0; i < 4; i++)
{
- if (((char) inbuf.Get()) != expected[i])
+ if (((char) inbuf.get()) != expected[i])
{
return MessageDecoderResult.NOT_OK;
}
@@ -128,13 +128,13 @@ namespace Qpid.Framing
public MessageDecoderResult Decode(ByteBuffer inbuf, IProtocolDecoderOutput output)
{
byte[] header = new byte[4];
- inbuf.Get(header);
+ inbuf.get(header);
ProtocolInitiation pi = new ProtocolInitiation();
pi.Header = new char[]{'A','M','Q','P'};
- pi.ProtocolClass = inbuf.Get();
- pi.ProtocolInstance = inbuf.Get();
- pi.ProtocolMajor = inbuf.Get();
- pi.ProtocolMinor = inbuf.Get();
+ pi.ProtocolClass = inbuf.get();
+ pi.ProtocolInstance = inbuf.get();
+ pi.ProtocolMajor = inbuf.get();
+ pi.ProtocolMinor = inbuf.get();
output.Write(pi);
return MessageDecoderResult.OK;
}
diff --git a/dotnet/Qpid.Common/stylesheets/utils.xsl b/dotnet/Qpid.Common/stylesheets/utils.xsl
index 5bcd646aeb..38405ad694 100644
--- a/dotnet/Qpid.Common/stylesheets/utils.xsl
+++ b/dotnet/Qpid.Common/stylesheets/utils.xsl
@@ -67,19 +67,19 @@
<xsl:param name="f"/>
<xsl:choose>
<xsl:when test="$f/@type='char'">
- <xsl:value-of select="concat('buffer.Put(', $f/@name, ')')"/>
+ <xsl:value-of select="concat('buffer.put(', $f/@name, ')')"/>
</xsl:when>
<xsl:when test="$f/@type='octet'">
- <xsl:value-of select="concat('buffer.Put(', $f/@name, ')')"/>
+ <xsl:value-of select="concat('buffer.put(', $f/@name, ')')"/>
</xsl:when>
<xsl:when test="$f/@type='short'">
- <xsl:value-of select="concat('buffer.Put(', $f/@name, ')')"/>
+ <xsl:value-of select="concat('buffer.put(', $f/@name, ')')"/>
</xsl:when>
<xsl:when test="$f/@type='long'">
- <xsl:value-of select="concat('buffer.Put(', $f/@name, ')')"/>
+ <xsl:value-of select="concat('buffer.put(', $f/@name, ')')"/>
</xsl:when>
<xsl:when test="$f/@type='longlong'">
- <xsl:value-of select="concat('buffer.Put(', $f/@name, ')')"/>
+ <xsl:value-of select="concat('buffer.put(', $f/@name, ')')"/>
</xsl:when>
<xsl:when test="$f/@type='shortstr'">
<xsl:value-of select="concat('EncodingUtils.WriteShortStringBytes(buffer, ', $f/@name, ')')"/>
@@ -108,7 +108,7 @@
<xsl:value-of select="concat($f/@name, ' = buffer.GetChar()')"/>
</xsl:when>
<xsl:when test="$f/@type='octet'">
- <xsl:value-of select="concat($f/@name, ' = buffer.Get()')"/>
+ <xsl:value-of select="concat($f/@name, ' = buffer.get()')"/>
</xsl:when>
<xsl:when test="$f/@type='short'">
<xsl:value-of select="concat($f/@name, ' = buffer.GetUnsignedShort()')"/>