public void TestQpidJmsTypes()
        {
            IDictionary <string, object> t = new Dictionary <string, object>
            {
                ["B"] = (byte)255,
                ["b"] = (sbyte)-128,
                ["d"] = (double)123,
                ["f"] = (float)123,
                ["l"] = (long)123,
                ["s"] = (short)123,
                ["t"] = true
            };

            byte[] xbytes = new byte[] { 0xaa, 0x55 };
            t["x"] = new BinaryTableValue(xbytes);
            t["V"] = null;
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];
            WireFormatting.WriteTable(bytes, t);
            IDictionary nt = (IDictionary)WireFormatting.ReadTable(bytes, out int bytesRead);

            Assert.AreEqual(bytesNeeded, bytesRead);
            Assert.AreEqual(typeof(byte), nt["B"].GetType()); Assert.AreEqual((byte)255, nt["B"]);
            Assert.AreEqual(typeof(sbyte), nt["b"].GetType()); Assert.AreEqual((sbyte)-128, nt["b"]);
            Assert.AreEqual(typeof(double), nt["d"].GetType()); Assert.AreEqual((double)123, nt["d"]);
            Assert.AreEqual(typeof(float), nt["f"].GetType()); Assert.AreEqual((float)123, nt["f"]);
            Assert.AreEqual(typeof(long), nt["l"].GetType()); Assert.AreEqual((long)123, nt["l"]);
            Assert.AreEqual(typeof(short), nt["s"].GetType()); Assert.AreEqual((short)123, nt["s"]);
            Assert.AreEqual(true, nt["t"]);
            Assert.AreEqual(xbytes, ((BinaryTableValue)nt["x"]).Bytes);
            Assert.AreEqual(null, nt["V"]);
        }
        public void TestQpidJmsTypes()
        {
            Hashtable t = new Hashtable // 4
            {
                ["B"] = (byte)255,      // 2+2
                ["b"] = (sbyte)-128,    // 2+2
                ["d"] = (double)123,    // 2+9
                ["f"] = (float)123,     // 2+5
                ["l"] = (long)123,      // 2+9
                ["s"] = (short)123,     // 2+2
                ["t"] = true            // 2+2
            };

            byte[] xbytes = { 0xaa, 0x55 };
            t["x"] = new BinaryTableValue(xbytes); // 2+5+2
            t["V"] = null;                         // 2+1
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];
            WireFormatting.WriteTable(ref bytes.GetStart(), t);
            int bytesRead = WireFormatting.ReadDictionary(bytes, out var nt);

            Assert.Equal(bytesNeeded, bytesRead);
            Assert.Equal(typeof(byte), nt["B"].GetType()); Assert.Equal((byte)255, nt["B"]);
            Assert.Equal(typeof(sbyte), nt["b"].GetType()); Assert.Equal((sbyte)-128, nt["b"]);
            Assert.Equal(typeof(double), nt["d"].GetType()); Assert.Equal((double)123, nt["d"]);
            Assert.Equal(typeof(float), nt["f"].GetType()); Assert.Equal((float)123, nt["f"]);
            Assert.Equal(typeof(long), nt["l"].GetType()); Assert.Equal((long)123, nt["l"]);
            Assert.Equal(typeof(short), nt["s"].GetType()); Assert.Equal((short)123, nt["s"]);
            Assert.Equal(true, nt["t"]);
            Assert.Equal(xbytes, ((BinaryTableValue)nt["x"]).Bytes);
            Assert.Null(nt["V"]);
        }
示例#3
0
        public override int GetRequiredBufferSize()
        {
            int bufferSize = 2 + 1 + 1;                                 // bytes for _reserved1, length of _queue, bit fields

            bufferSize += WireFormatting.GetByteCount(_queue);          // _queue in bytes
            bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes
            return(bufferSize);
        }
示例#4
0
        public override int GetRequiredBufferSize()
        {
            int bufferSize = 1 + 1 + 4 + 4;                                    // bytes for _versionMajor, _versionMinor, length of _mechanisms, length of _locales

            bufferSize += WireFormatting.GetTableByteCount(_serverProperties); // _serverProperties in bytes
            bufferSize += _mechanisms.Length;                                  // _mechanisms in bytes
            bufferSize += _locales.Length;                                     // _locales in bytes
            return(bufferSize);
        }
示例#5
0
        public override int GetRequiredBufferSize()
        {
            int bufferSize = 2 + 1 + 1 + 1;                             // bytes for _reserved1, length of _exchange, length of _type, bit fields

            bufferSize += Encoding.UTF8.GetByteCount(_exchange);        // _exchange in bytes
            bufferSize += Encoding.UTF8.GetByteCount(_type);            // _type in bytes
            bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes
            return(bufferSize);
        }
        public override int GetRequiredBufferSize()
        {
            int bufferSize = 2 + 1 + 1 + 1 + 1;                         // bytes for _reserved1, length of _destination, length of _source, length of _routingKey, bit fields

            bufferSize += WireFormatting.GetByteCount(_destination);    // _destination in bytes
            bufferSize += WireFormatting.GetByteCount(_source);         // _source in bytes
            bufferSize += WireFormatting.GetByteCount(_routingKey);     // _routingKey in bytes
            bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes
            return(bufferSize);
        }
示例#7
0
        public override int GetRequiredBufferSize()
        {
            int bufferSize = 2 + 1 + 1 + 1;                             // bytes for _reserved1, length of _queue, length of _exchange, length of _routingKey

            bufferSize += Encoding.UTF8.GetByteCount(_queue);           // _queue in bytes
            bufferSize += Encoding.UTF8.GetByteCount(_exchange);        // _exchange in bytes
            bufferSize += Encoding.UTF8.GetByteCount(_routingKey);      // _routingKey in bytes
            bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes
            return(bufferSize);
        }
        public int GetRequiredBufferSize()
        {
            int bufferSize = 1 + 4 + 1;                                        // bytes for length of _mechanism, length of _response, length of _locale

            bufferSize += WireFormatting.GetTableByteCount(_clientProperties); // _clientProperties in bytes
            bufferSize += WireFormatting.GetByteCount(_mechanism);             // _mechanism in bytes
            bufferSize += _response.Length;                                    // _response in bytes
            bufferSize += WireFormatting.GetByteCount(_locale);                // _locale in bytes
            return(bufferSize);
        }
        public void TestTableEncoding_LongKey()
        {
            const int TooLarge = 256;
            Hashtable t        = new Hashtable
            {
                [new string ('A', TooLarge)] = null
            };
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];

            Assert.Throws <ArgumentException>(() => WireFormatting.WriteTable(ref bytes.GetStart(), t));
        }
示例#10
0
        public void TestTableLengthWrite()
        {
            var t = new Hashtable
            {
                ["abc"] = "def"
            };

            int bytesNeeded = WireFormatting.GetTableByteCount(t);
            var writer      = new MethodArgumentWriter(new byte[bytesNeeded]);

            writer.WriteTable(t);
            Assert.AreEqual(bytesNeeded, writer.Offset);
            Check(writer, new byte[] { 0x00, 0x00, 0x00, 0x0C,
                                       0x03, 0x61, 0x62, 0x63,
                                       0x53, 0x00, 0x00, 0x00,
                                       0x03, 0x64, 0x65, 0x66 });
        }
        public void TestTableLengthWrite()
        {
            var t = new Hashtable
            {
                ["abc"] = "def"
            };

            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] memory = new byte[bytesNeeded];
            int    offset = WireFormatting.WriteTable(memory.AsSpan(), t);

            Assert.Equal(bytesNeeded, offset);
            Check(memory, new byte[] { 0x00, 0x00, 0x00, 0x0C,
                                       0x03, 0x61, 0x62, 0x63,
                                       0x53, 0x00, 0x00, 0x00,
                                       0x03, 0x64, 0x65, 0x66 });
        }
        public void TestTableEncoding_x()
        {
            Hashtable t = new Hashtable
            {
                ["a"] = new BinaryTableValue(new byte[] { 0xaa, 0x55 })
            };
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];
            WireFormatting.WriteTable(bytes, t);
            WireFormatting.ReadTable(bytes, out int bytesRead);
            Assert.AreEqual(bytesNeeded, bytesRead);
            Check(bytes, new byte[] {
                0, 0, 0, 9,            // table length
                1, (byte)'a',          // key
                (byte)'x',             // type
                0, 0, 0, 2, 0xaa, 0x55 // value
            });
        }
        public void TestTableEncoding_S()
        {
            IDictionary <string, object> t = new Dictionary <string, object>
            {
                ["a"] = "bc"
            };
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];
            WireFormatting.WriteTable(bytes, t);
            WireFormatting.ReadTable(bytes, out int bytesRead);
            Assert.AreEqual(bytesNeeded, bytesRead);
            Check(bytes, new byte[] {
                0, 0, 0, 9,                      // table length
                1, (byte)'a',                    // key
                (byte)'S',                       // type
                0, 0, 0, 2, (byte)'b', (byte)'c' // value
            });
        }
示例#14
0
        public void TestTableEncoding_x()
        {
            IDictionary <string, object> t = new Dictionary <string, object>
            {
                ["a"] = new BinaryTableValue(new byte[] { 0xaa, 0x55 })
            };
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];
            WireFormatting.WriteTable(bytes, t);
            int bytesRead = WireFormatting.ReadDictionary(bytes, out _);

            Assert.Equal(bytesNeeded, bytesRead);
            Check(bytes, new byte[] {
                0, 0, 0, 9,            // table length
                1, (byte)'a',          // key
                (byte)'x',             // type
                0, 0, 0, 2, 0xaa, 0x55 // value
            });
        }
示例#15
0
        public void TestNestedTableWrite()
        {
            Hashtable t = new Hashtable();
            Hashtable x = new Hashtable
            {
                ["y"] = 0x12345678
            };

            t["x"] = x;
            int bytesNeeded = WireFormatting.GetTableByteCount(t);
            var writer      = new MethodArgumentWriter(new byte[bytesNeeded]);

            writer.WriteTable(t);
            Assert.AreEqual(bytesNeeded, writer.Offset);
            Check(writer, new byte[] { 0x00, 0x00, 0x00, 0x0E,
                                       0x01, 0x78, 0x46, 0x00,
                                       0x00, 0x00, 0x07, 0x01,
                                       0x79, 0x49, 0x12, 0x34,
                                       0x56, 0x78 });
        }
        public void TestTableEncoding_S()
        {
            Hashtable t = new Hashtable
            {
                ["a"] = "bc"
            };
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];
            WireFormatting.WriteTable(ref bytes.GetStart(), t);
            int bytesRead = WireFormatting.ReadDictionary(bytes, out _);

            Assert.Equal(bytesNeeded, bytesRead);
            Check(bytes, new byte[] {
                0, 0, 0, 9,                      // table length
                1, (byte)'a',                    // key
                (byte)'S',                       // type
                0, 0, 0, 2, (byte)'b', (byte)'c' // value
            });
        }
        public void TestStandardTypes()
        {
            Hashtable t = new Hashtable
            {
                ["string"]    = "Hello",
                ["int"]       = 1234,
                ["uint"]      = 1234u,
                ["decimal"]   = 12.34m,
                ["timestamp"] = new AmqpTimestamp(0)
            };
            Hashtable t2 = new Hashtable();

            t["fieldtable"] = t2;
            t2["test"]      = "test";
            IList array = new ArrayList
            {
                "longstring",
                1234
            };

            t["fieldarray"] = array;
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];
            WireFormatting.WriteTable(ref bytes.GetStart(), t);
            int bytesRead = WireFormatting.ReadDictionary(bytes, out var nt);

            Assert.Equal(bytesNeeded, bytesRead);
            Assert.Equal(Encoding.UTF8.GetBytes("Hello"), nt["string"]);
            Assert.Equal(1234, nt["int"]);
            Assert.Equal(1234u, nt["uint"]);
            Assert.Equal(12.34m, nt["decimal"]);
            Assert.Equal(0, ((AmqpTimestamp)nt["timestamp"]).UnixTime);
            IDictionary nt2 = (IDictionary)nt["fieldtable"];

            Assert.Equal(Encoding.UTF8.GetBytes("test"), nt2["test"]);
            IList narray = (IList)nt["fieldarray"];

            Assert.Equal(Encoding.UTF8.GetBytes("longstring"), narray[0]);
            Assert.Equal(1234, narray[1]);
        }
        public void TestStandardTypes()
        {
            IDictionary <string, object> t = new Dictionary <string, object>
            {
                ["string"]    = "Hello",
                ["int"]       = 1234,
                ["uint"]      = 1234u,
                ["decimal"]   = 12.34m,
                ["timestamp"] = new AmqpTimestamp(0)
            };
            IDictionary <string, object> t2 = new Dictionary <string, object>();

            t["fieldtable"] = t2;
            t2["test"]      = "test";
            IList array = new List <object>
            {
                "longstring",
                1234
            };

            t["fieldarray"] = array;
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] bytes = new byte[bytesNeeded];
            WireFormatting.WriteTable(bytes, t);
            IDictionary <string, object> nt = WireFormatting.ReadTable(bytes, out int bytesRead);

            Assert.AreEqual(bytesNeeded, bytesRead);
            Assert.AreEqual(Encoding.UTF8.GetBytes("Hello"), nt["string"]);
            Assert.AreEqual(1234, nt["int"]);
            Assert.AreEqual(1234u, nt["uint"]);
            Assert.AreEqual(12.34m, nt["decimal"]);
            Assert.AreEqual(0, ((AmqpTimestamp)nt["timestamp"]).UnixTime);
            IDictionary <string, object> nt2 = (IDictionary <string, object>)nt["fieldtable"];

            Assert.AreEqual(Encoding.UTF8.GetBytes("test"), nt2["test"]);
            IList <object> narray = (IList <object>)nt["fieldarray"];

            Assert.AreEqual(Encoding.UTF8.GetBytes("longstring"), narray[0]);
            Assert.AreEqual(1234, narray[1]);
        }
        public void TestNestedTableWrite()
        {
            Hashtable t = new Hashtable();
            Hashtable x = new Hashtable
            {
                ["y"] = 0x12345678
            };

            t["x"] = x;
            int bytesNeeded = WireFormatting.GetTableByteCount(t);

            byte[] memory = new byte[bytesNeeded];
            int    offset = WireFormatting.WriteTable(memory.AsSpan(), t);

            Assert.Equal(bytesNeeded, offset);
            Check(memory, new byte[] { 0x00, 0x00, 0x00, 0x0E,
                                       0x01, 0x78, 0x46, 0x00,
                                       0x00, 0x00, 0x07, 0x01,
                                       0x79, 0x49, 0x12, 0x34,
                                       0x56, 0x78 });
        }
        public override void SetUp()
        {
            _populatedDict = new Dictionary <string, object>
            {
                { "string", "Hello" },
                { "int", 1234 },
                { "uint", 1234u },
                { "decimal", 12.34m },
                { "timestamp", _timestamp },
                { "fieldtable", new Dictionary <string, object> {
                      { "test", "test" }
                  } },
                { "fieldarray", new List <object> {
                      "longstring", 1234, 12.34m, _timestamp
                  } }
            };

            _emptyDictionaryBuffer = new byte[WireFormatting.GetTableByteCount(_emptyDict)];
            WireFormatting.WriteTable(ref _emptyDictionaryBuffer.Span.GetStart(), _emptyDict);

            _populatedDictionaryBuffer = new byte[WireFormatting.GetTableByteCount(_populatedDict)];
            WireFormatting.WriteTable(ref _populatedDictionaryBuffer.Span.GetStart(), _populatedDict);
        }
 public int TableGetSizePopulated() => WireFormatting.GetTableByteCount(_populatedDict);
 public int TableGetSizeEmpty() => WireFormatting.GetTableByteCount(_emptyDict);