Exemple #1
0
 internal void SendMessage(In data)
 {
     sender.SendMessage(packer.Pack(DictionarySerializer.AsDictionary(new Message <In>()
     {
         cmd  = cmd,
         data = data
     })));
 }
Exemple #2
0
        public void PackBoolean(bool value, byte expected)
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack((object)value);

            Assert.AreEqual(1, actual.Length, value + ": length");
            Assert.AreEqual(expected, actual[0], value + ": value");
        }
Exemple #3
0
        public void PackNull()
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack(null);

            Assert.AreEqual(1, actual.Length, "length");
            Assert.AreEqual(0xc0, actual[0], "value");
        }
Exemple #4
0
        public void PackKnownObject()
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack(new MyClass());

            Assert.AreEqual(2, actual.Length);
            Assert.AreEqual(0xa1, actual[0]);
            Assert.AreEqual(0x61, actual[1]);
        }
Exemple #5
0
    public string Serialize()
    {
        Dictionary <string, object> tMessage = new Dictionary <string, object>();

        tMessage.Add("S", m_SendName);
        tMessage.Add("C", m_Content);
        var c = m_MsgPacker.Pack(tMessage);

        return("N:" + System.Convert.ToBase64String(c));
    }
Exemple #6
0
        public void PackShortValue(int value, byte[] expected)
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack((object)(short)value);

            Assert.AreEqual(expected.Length, actual.Length, "length");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], "byte: " + i);
            }
        }
Exemple #7
0
        public void PackArray(object[] array, byte[] expected, string message)
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack(array);

            Assert.AreEqual(expected.Length, actual.Length, message + ": length");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], message + ": [" + i + "]");
            }
        }
Exemple #8
0
        public void PackString(string value, byte[] expected)
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack(value);

            Assert.AreEqual(expected.Length, actual.Length, value + ": length");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], value + ": [" + i + "]");
            }
        }
Exemple #9
0
        public void PackMap(string[] keys, object[] values, byte[] expected, string message)
        {
            var packer = new MiniMessagePacker();
            var dict   = new SortedDictionary <string, object> ();

            for (int i = 0; i < keys.Length; i++)
            {
                dict.Add(keys [i], values [i]);
            }
            var actual = packer.Pack(dict);

            Assert.AreEqual(expected.Length, actual.Length, message + ": length");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], message + ": [" + i + "]");
            }
        }
Exemple #10
0
        public void PackString255()
        {
            var str = new StringBuilder();

            for (int i = 0; i < 255; i++)
            {
                str.Append("a");
            }

            var packer = new MiniMessagePacker();
            var actual = packer.Pack(str.ToString());

            Assert.AreEqual(str.Length + 2, actual.Length);
            Assert.AreEqual(0xd9, actual [0]);
            Assert.AreEqual(0xff, actual [1]);
            for (int i = 0; i < str.Length; i++)
            {
                Assert.AreEqual(0x61, actual [i + 2]);
            }
        }
Exemple #11
0
        public void PackLongArray()
        {
            var array = new int[65535];

            for (int i = 0; i < array.Length; i++)
            {
                array [i] = 0x00;
            }

            var packer = new MiniMessagePacker();
            var actual = packer.Pack(array);

            Assert.AreEqual(array.Length + 1 + 2, actual.Length);
            Assert.AreEqual(0xdc, actual [0]);
            Assert.AreEqual(0xff, actual [1]);
            Assert.AreEqual(0xff, actual [2]);
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(0x00, actual [i + 1 + 2]);
            }
        }
Exemple #12
0
        public void PackExample()
        {
            var unpacked_data = new SortedDictionary <string, object> {
                { "compact", true },
                { "schema", 0 },
            };

            var packer = new MiniMessagePacker();

            byte[] msgpack = packer.Pack(unpacked_data);

            // it means {"compact":true,"schema":0} in JSON
            var expected = new byte[] {
                0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 0x74, 0xc3,
                0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00
            };

            Assert.AreEqual(expected.Length, msgpack.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], msgpack [i]);
            }
        }
Exemple #13
0
        public void PackString65536()
        {
            var str = new StringBuilder();

            for (int i = 0; i < 65536; i++)
            {
                str.Append("a");
            }

            var packer = new MiniMessagePacker();
            var actual = packer.Pack(str.ToString());

            Assert.AreEqual(str.Length + 1 + 4, actual.Length);
            Assert.AreEqual(0xdb, actual [0]);
            Assert.AreEqual(0x00, actual [1]);
            Assert.AreEqual(0x01, actual [2]);
            Assert.AreEqual(0x00, actual [3]);
            Assert.AreEqual(0x00, actual [4]);
            for (int i = 0; i < str.Length; i++)
            {
                Assert.AreEqual(0x61, actual [i + 1 + 4]);
            }
        }
Exemple #14
0
 private void Pack(int val) => _packer.Pack(_s, val);
 public byte[] MessagePackEncode(Dictionary <string, object> dic)
 {
     return(pakage.Pack(dic));
 }