https://issues.apache.org/jira/browse/AMQNET-495
Read compacted long values as unsigned.
diff --git a/src/main/csharp/OpenWire/BaseDataStreamMarshaller.cs b/src/main/csharp/OpenWire/BaseDataStreamMarshaller.cs
index 6493331..8dbc084 100755
--- a/src/main/csharp/OpenWire/BaseDataStreamMarshaller.cs
+++ b/src/main/csharp/OpenWire/BaseDataStreamMarshaller.cs
@@ -28,7 +28,6 @@
/// </summary>
public abstract class BaseDataStreamMarshaller
{
-
private static readonly String[] HEX_TABLE = new String[]{
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f",
@@ -55,6 +54,7 @@
{
return 0;
}
+
public virtual void TightMarshal2(
OpenWireFormat wireFormat,
Object o,
@@ -70,8 +70,7 @@
BooleanStream bs)
{
}
-
-
+
protected virtual DataStructure TightUnmarshalNestedObject(
OpenWireFormat wireFormat,
BinaryReader dataIn,
@@ -262,6 +261,7 @@
}
}
}
+
public virtual long TightUnmarshalLong(OpenWireFormat wireFormat, BinaryReader dataIn, BooleanStream bs)
{
if (bs.ReadBoolean())
@@ -272,14 +272,14 @@
}
else
{
- return dataIn.ReadInt32();
+ return dataIn.ReadUInt32();
}
}
else
{
if (bs.ReadBoolean())
{
- return dataIn.ReadInt16();
+ return dataIn.ReadUInt16();
}
else
{
@@ -287,6 +287,7 @@
}
}
}
+
protected virtual int TightMarshalObjectArray1(
OpenWireFormat wireFormat,
DataStructure[] objects,
@@ -326,7 +327,6 @@
}
}
-
protected virtual BrokerError TightUnmarshalBrokerError(
OpenWireFormat wireFormat,
BinaryReader dataIn,
@@ -422,7 +422,6 @@
}
}
-
public virtual void LooseMarshal(
OpenWireFormat wireFormat,
Object o,
@@ -437,7 +436,6 @@
{
}
-
protected virtual DataStructure LooseUnmarshalNestedObject(
OpenWireFormat wireFormat,
BinaryReader dataIn)
@@ -457,48 +455,17 @@
OpenWireFormat wireFormat,
BinaryReader dataIn)
{
- /*
- if (wireFormat.isCacheEnabled()) {
- if (bs.ReadBoolean()) {
- short index = dataIndataIn.ReadInt16()Int16();
- DataStructure value = wireFormat.UnmarshalNestedObject(dataIn, bs);
- wireFormat.setInUnmarshallCache(index, value);
- return value;
- } else {
- short index = dataIn.ReadInt16();
- return wireFormat.getFromUnmarshallCache(index);
- }
- } else {
- return wireFormat.UnmarshalNestedObject(dataIn, bs);
- }
- */
return wireFormat.LooseUnmarshalNestedObject(dataIn);
}
-
-
+
protected virtual void LooseMarshalCachedObject(
OpenWireFormat wireFormat,
DataStructure o,
BinaryWriter dataOut)
{
- /*
- if (wireFormat.isCacheEnabled()) {
- Short index = wireFormat.getMarshallCacheIndex(o);
- if (bs.ReadBoolean()) {
- dataOut.Write(index.shortValue(), dataOut);
- wireFormat.Marshal2NestedObject(o, dataOut, bs);
- } else {
- dataOut.Write(index.shortValue(), dataOut);
- }
- } else {
- wireFormat.Marshal2NestedObject(o, dataOut, bs);
- }
- */
wireFormat.LooseMarshalNestedObject(o, dataOut);
}
-
-
-
+
protected virtual String LooseUnmarshalString(BinaryReader dataIn)
{
if (dataIn.ReadBoolean())
@@ -510,8 +477,7 @@
return null;
}
}
-
-
+
public static void LooseMarshalString(String value, BinaryWriter dataOut)
{
dataOut.Write(value != null);
@@ -655,8 +621,6 @@
return new String(text);
}
-
-
/// <summary>
/// Converts the object to a String
/// </summary>
@@ -664,6 +628,7 @@
{
return ToString(id.ProducerId) + ":" + id.ProducerSequenceId;
}
+
/// <summary>
/// Converts the object to a String
/// </summary>
@@ -672,7 +637,6 @@
return id.ConnectionId + ":" + id.SessionId + ":" + id.Value;
}
-
/// <summary>
/// Converts the given transaction ID into a String
/// </summary>
@@ -703,7 +667,6 @@
}
return buffer.ToString();
}
-
}
}
diff --git a/src/test/csharp/OpenWire/BaseDataStreamMarshallerTest.cs b/src/test/csharp/OpenWire/BaseDataStreamMarshallerTest.cs
new file mode 100644
index 0000000..dfd3cab
--- /dev/null
+++ b/src/test/csharp/OpenWire/BaseDataStreamMarshallerTest.cs
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.IO;
+using Apache.NMS.ActiveMQ.OpenWire;
+using Apache.NMS.ActiveMQ.Commands;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+ [TestFixture]
+ public class BaseDataStreamMarshalerTest
+ {
+ OpenWireFormat wireFormat;
+ TestDataStreamMarshaller testMarshaller;
+
+ [SetUp]
+ public void SetUp()
+ {
+ wireFormat = new OpenWireFormat();
+ testMarshaller = new TestDataStreamMarshaller();
+ }
+
+ [Test]
+ public void TestCompactedLongToIntegerTightUnmarshal()
+ {
+ long inputValue = 2147483667;
+
+ BooleanStream stream = new BooleanStream();
+ stream.WriteBoolean(true);
+ stream.WriteBoolean(false);
+
+ stream.Clear();
+
+ MemoryStream buffer = new MemoryStream();
+ BinaryWriter ds = new EndianBinaryWriter(buffer);
+
+ ds.Write((int) inputValue);
+
+ MemoryStream ins = new MemoryStream(buffer.ToArray());
+ BinaryReader dis = new EndianBinaryReader(ins);
+
+ long outputValue = testMarshaller.TightUnmarshalLong(wireFormat, dis, stream);
+ Assert.AreEqual(inputValue, outputValue);
+ }
+
+ [Test]
+ public void TestCompactedLongToShortTightUnmarshal()
+ {
+ long inputValue = 33000;
+
+ BooleanStream stream = new BooleanStream();
+ stream.WriteBoolean(false);
+ stream.WriteBoolean(true);
+
+ stream.Clear();
+
+ MemoryStream buffer = new MemoryStream();
+ BinaryWriter ds = new EndianBinaryWriter(buffer);
+
+ ds.Write((short) inputValue);
+
+ MemoryStream ins = new MemoryStream(buffer.ToArray());
+ BinaryReader dis = new EndianBinaryReader(ins);
+
+ long outputValue = testMarshaller.TightUnmarshalLong(wireFormat, dis, stream);
+ Assert.AreEqual(inputValue, outputValue);
+ }
+
+ private class TestDataStreamMarshaller : BaseDataStreamMarshaller
+ {
+ public override DataStructure CreateObject()
+ {
+ return null;
+ }
+
+ public override byte GetDataStructureType()
+ {
+ return 0;
+ }
+ }
+ }
+}
+