public void TestObject() { var writer = new Amf0Writer(); var reader = new Amf0Reader(); object nullVal = null; var refVal = new List <object>() { 1, 2, "test" }; var obj = new AmfObject { { "c", 1.0 }, { "test", false }, { "test2", nullVal }, { "test3", new Undefined() }, { "test4", refVal }, { "test5", "test" }, { "test6", refVal } }; using (var sc = new SerializationContext()) { writer.WriteBytes(obj, sc); var buffer = new byte[sc.MessageLength]; sc.GetMessage(buffer); // test reference table is working Assert.AreEqual(buffer.Length, 97); Assert.IsTrue(reader.TryGetObject(buffer, out var readObj, out var consumed)); Assert.AreEqual(consumed, buffer.Length); } }
public void TestReadNull2() { var reader = new Amf0Reader(); using (var f = new FileStream("../../../../samples/amf0/misc/null.amf0", FileMode.Open)) { var data = new byte[f.Length]; f.Read(data); Assert.IsTrue(reader.TryGetObject(data, out var dataRead, out var consumed)); Assert.AreEqual(null, dataRead); Assert.AreEqual(consumed, f.Length); } }
public void TestReadObject() { 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/object.amf0", FileMode.Open)) { var data = new byte[f.Length]; f.Read(data); Assert.IsTrue(reader.TryGetObject(data, out var dataRead, out var consumed)); Assert.IsTrue(dataRead.Fields.SequenceEqual(new Dictionary <string, object>() { ["a"] = "b", ["c"] = 1.0 })); Assert.AreEqual(consumed, data.Length); } }