public void TestIMessagePackSerializerPackTo_ObjectTreeIsOtherType() { IMessagePackSerializer target = CreateTarget <string>(); using (var buffer = new MemoryStream()) using (var packer = Packer.Create(buffer)) { Assert.Throws <ArgumentException>(() => target.PackTo(packer, Int64.MaxValue)); } }
public void TestIMessagePackSerializerPackTo_ObjectTreeIsNull_ValueType_AsNil() { IMessagePackSerializer target = CreateTarget <int>(); using (var buffer = new MemoryStream()) using (var packer = Packer.Create(buffer)) { Assert.Throws <SerializationException>(() => target.PackTo(packer, null)); } }
public void TestIMessagePackSerializerPackTo_Valid_Success() { IMessagePackSerializer target = CreateTarget <int>(); using (var buffer = new MemoryStream()) using (var packer = Packer.Create(buffer)) { target.PackTo(packer, 1); Assert.That(buffer.ToArray(), Is.EqualTo(new byte[] { 0x1 })); } }
public void TestIMessagePackSerializerPackTo_ObjectTreeIsNull_ReferenceType_AsNil() { IMessagePackSerializer target = CreateTarget <string>(); using (var buffer = new MemoryStream()) using (var packer = Packer.Create(buffer)) { target.PackTo(packer, null); Assert.That(buffer.ToArray(), Is.EqualTo(new byte[] { 0xC0 })); } }
private void PackToCore(Packer packer, object target, IMessagePackSerializer underlyingTypeSerializer) { { if (!(bool)_nullableTValueProperty.GetGetMethod().Invoke(target, new object[0])) { packer.PackNull(); return; } underlyingTypeSerializer.PackTo(packer, _nullableTValueProperty.GetGetMethod().Invoke(target, new object[0])); }; }
public static byte[] ObjToBytes(object obj) { if (obj == null) { return(null); } Type type = obj.GetType(); IMessagePackSerializer ser = serDic.GetOrAdd(type, MessagePackSerializer.Create(type)); MemoryStream stream = new MemoryStream(); ser.PackTo(Packer.Create(stream), obj); byte[] data = stream.ToArray(); return(data); }
public static void Pack(this IMessagePackSerializer source, Stream stream, object objectTree, PackerCompatibilityOptions packerCompatibilityOptions) { if (source == null) { throw new ArgumentNullException("source"); } if (stream == null) { throw new ArgumentNullException("stream"); } // Packer does not have finalizer, so just avoiding packer disposing prevents stream closing. source.PackTo(Packer.Create(stream, packerCompatibilityOptions), objectTree); }
public void TestIMessagePackSerializerPackTo_PackerIsNull() { IMessagePackSerializer target = CreateTarget <int>(); Assert.Throws <ArgumentNullException>(() => target.PackTo(null, 0)); }