activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [08/50] [abbrv] activemq-nms-openwire git commit: https://issues.apache.org/jira/browse/AMQNET-495
Date Wed, 08 Mar 2017 23:12:10 GMT
https://issues.apache.org/jira/browse/AMQNET-495

Read compacted long values as unsigned.


Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/commit/c0258fa0
Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/tree/c0258fa0
Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/diff/c0258fa0

Branch: refs/heads/1.6.x
Commit: c0258fa07c2f715b92aceea492c660576a282d5b
Parents: ea082f1
Author: Timothy A. Bish <tabish@apache.org>
Authored: Tue Dec 16 21:10:09 2014 +0000
Committer: Timothy A. Bish <tabish@apache.org>
Committed: Tue Dec 16 21:10:09 2014 +0000

----------------------------------------------------------------------
 .../csharp/OpenWire/BaseDataStreamMarshaller.cs |  57 ++---------
 .../OpenWire/BaseDataStreamMarshallerTest.cs    | 100 +++++++++++++++++++
 2 files changed, 110 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/c0258fa0/src/main/csharp/OpenWire/BaseDataStreamMarshaller.cs
----------------------------------------------------------------------
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 @@ namespace Apache.NMS.ActiveMQ.OpenWire
     /// </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 @@ namespace Apache.NMS.ActiveMQ.OpenWire
         {
             return 0;
         }
+
         public virtual void TightMarshal2(
             OpenWireFormat wireFormat,
             Object o,
@@ -70,8 +70,7 @@ namespace Apache.NMS.ActiveMQ.OpenWire
             BooleanStream bs)
         {
         }
-        
-        
+
         protected virtual DataStructure TightUnmarshalNestedObject(
             OpenWireFormat wireFormat,
             BinaryReader dataIn,
@@ -262,6 +261,7 @@ namespace Apache.NMS.ActiveMQ.OpenWire
                 }
             }
         }
+
         public virtual long TightUnmarshalLong(OpenWireFormat wireFormat, BinaryReader dataIn,
BooleanStream bs)
         {
             if (bs.ReadBoolean())
@@ -272,14 +272,14 @@ namespace Apache.NMS.ActiveMQ.OpenWire
                 }
                 else
                 {
-                    return dataIn.ReadInt32();
+                    return dataIn.ReadUInt32();
                 }
             }
             else
             {
                 if (bs.ReadBoolean())
                 {
-                    return dataIn.ReadInt16();
+                    return dataIn.ReadUInt16();
                 }
                 else
                 {
@@ -287,6 +287,7 @@ namespace Apache.NMS.ActiveMQ.OpenWire
                 }
             }
         }
+
         protected virtual int TightMarshalObjectArray1(
             OpenWireFormat wireFormat,
             DataStructure[] objects,
@@ -326,7 +327,6 @@ namespace Apache.NMS.ActiveMQ.OpenWire
             }
         }
         
-        
         protected virtual BrokerError TightUnmarshalBrokerError(
             OpenWireFormat wireFormat,
             BinaryReader dataIn,
@@ -422,7 +422,6 @@ namespace Apache.NMS.ActiveMQ.OpenWire
             }
         }
 
-        
         public virtual void LooseMarshal(
             OpenWireFormat wireFormat,
             Object o,
@@ -437,7 +436,6 @@ namespace Apache.NMS.ActiveMQ.OpenWire
         {
         }
         
-        
         protected virtual DataStructure LooseUnmarshalNestedObject(
             OpenWireFormat wireFormat,
             BinaryReader dataIn)
@@ -457,48 +455,17 @@ namespace Apache.NMS.ActiveMQ.OpenWire
             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 @@ namespace Apache.NMS.ActiveMQ.OpenWire
                 return null;
             }
         }
-        
-        
+
         public static void LooseMarshalString(String value, BinaryWriter dataOut)
         {
             dataOut.Write(value != null);
@@ -655,8 +621,6 @@ namespace Apache.NMS.ActiveMQ.OpenWire
             return new String(text);
         }
         
-        
-                
         /// <summary>
         /// Converts the object to a String
         /// </summary>
@@ -664,6 +628,7 @@ namespace Apache.NMS.ActiveMQ.OpenWire
         {
             return ToString(id.ProducerId) + ":" + id.ProducerSequenceId;
         }
+
         /// <summary>
         /// Converts the object to a String
         /// </summary>
@@ -672,7 +637,6 @@ namespace Apache.NMS.ActiveMQ.OpenWire
             return id.ConnectionId + ":" + id.SessionId + ":" + id.Value;
         }
         
-        
         /// <summary>
         /// Converts the given transaction ID into a String
         /// </summary>
@@ -703,7 +667,6 @@ namespace Apache.NMS.ActiveMQ.OpenWire
             }
             return buffer.ToString();
         }
-        
     }
 }
 

http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/c0258fa0/src/test/csharp/OpenWire/BaseDataStreamMarshallerTest.cs
----------------------------------------------------------------------
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;
+            }
+        }
+    }
+}
+


Mime
View raw message