예제 #1
0
        public void TestEcmaArray()
        {
            var writer = new Amf0Writer();
            var reader = new Amf0Reader();

            var array = new Dictionary <string, object>()
            {
                ["1"] = 1.0,
                ["2"] = 2.0,
                ["3"] = "a",
                ["4"] = "a"
            };

            using (var sc = new SerializationContext())
            {
                writer.WriteBytes(array, sc);
                var buffer = new byte[sc.MessageLength];
                sc.GetMessage(buffer);
                // EcmaMarker:byte + ElementCount: uint +
                // StringLength: ushort + StringContent: byte * 1 + NumberMarker: byte + Number: double +
                // StringLength: ushort + StringContent: byte * 1 + NumberMarker: byte + Number: double
                // StringLength: ushort + StringContent: byte * 1 + StringMarker: byte + StringLength: ushort + StringContent: byte * 1 +
                // StringLength: ushort + StringContent: byte * 1 + ReferenceMarker: byte + ReferenceIndex: ushort +
                // StringLength: ushort + StringConent: byte * 0 + ObjectEndMarker: byte
                Assert.AreEqual(buffer.Length, 45);
                Assert.IsTrue(reader.TryGetEcmaArray(buffer, out var readData, out var consumed));

                Assert.IsTrue(readData.SequenceEqual(array));
            }
        }
예제 #2
0
        public void TestReadEcmaArray()
        {
            var reader = new Amf0Reader();

            // pyamf has a bug about element count of ecma array
            // https://github.com/hydralabs/pyamf/blob/master/pyamf/amf0.py#L567
            reader.StrictMode = false;

            using (var f = new FileStream("../../../../samples/amf0/misc/ecmaarray.amf0", FileMode.Open))
            {
                var data = new byte[f.Length];
                f.Read(data);

                Assert.IsTrue(reader.TryGetEcmaArray(data, out var dataRead, out var consumed));
                Assert.IsTrue(dataRead.SequenceEqual(new Dictionary <string, object>()
                {
                    ["a"] = 1.0d, ["b"] = "a", ["c"] = "a"
                }));
                Assert.AreEqual(consumed, data.Length);
            }
        }