示例#1
0
        public void TestArray()
        {
            var reader = new Amf3Reader();
            var writer = new Amf3Writer();

            var arr = new Amf3Array();

            arr["a"] = (uint)1;
            arr["b"] = 2.1;
            arr["d"] = null;

            arr.DensePart.Add(1);
            arr.DensePart.Add(1.2);

            using (var sc = new SerializationContext())
            {
                writer.WriteBytes(arr, sc);

                var buffer = new byte[sc.MessageLength];
                sc.GetMessage(buffer);

                Assert.IsTrue(reader.TryGetArray(buffer, out var readVal, out var consumed));
                Assert.AreEqual(arr["a"], readVal["a"]);
                Assert.AreEqual(arr["b"], readVal["b"]);
                Assert.AreEqual(arr["d"], readVal["d"]);
                Assert.AreEqual(1.0, readVal[0]);
                Assert.AreEqual(buffer.Length, consumed);
            }
        }
        private static XNode Amf3ArrayVisualizer(object o, XElement surrogate)
        {
            Amf3Array arr = (Amf3Array)o;

            XElement dense = null;
            XElement assoc = null;

            if (arr.DenseArray.Count > 0)
            {
                dense = new XElement("DenseArray");
                ListVisualizer(arr.DenseArray, dense);
            }

            if (arr.AssociativeArray.Count > 0)
            {
                assoc = new XElement("AssociativeArray");
                DictionaryVisualizer(arr.AssociativeArray, assoc);
            }

            return(new XElement("Amf3Array", dense, assoc));
        }