internal void SendMessage(In data) { sender.SendMessage(packer.Pack(DictionarySerializer.AsDictionary(new Message <In>() { cmd = cmd, data = data }))); }
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"); }
public void PackNull() { var packer = new MiniMessagePacker(); var actual = packer.Pack(null); Assert.AreEqual(1, actual.Length, "length"); Assert.AreEqual(0xc0, actual[0], "value"); }
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]); }
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)); }
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); } }
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 + "]"); } }
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 + "]"); } }
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 + "]"); } }
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]); } }
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]); } }
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]); } }
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]); } }
private void Pack(int val) => _packer.Pack(_s, val);
public byte[] MessagePackEncode(Dictionary <string, object> dic) { return(pakage.Pack(dic)); }