45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using MessagePack;
|
|
|
|
namespace CommonTools
|
|
{
|
|
public class MyMessagePacker
|
|
{
|
|
public static byte[] FastSerialize<T>(T t)
|
|
{
|
|
byte[] bytes = MessagePackSerializer.Serialize(t);
|
|
return bytes;
|
|
}
|
|
public static T FastDeserialize<T>(byte[] bytes)
|
|
{
|
|
T mc2 = MessagePackSerializer.Deserialize<T>(bytes);
|
|
return mc2;
|
|
}
|
|
}
|
|
|
|
|
|
[MessagePackObject]
|
|
public class MyClass
|
|
{
|
|
// Key attributes take a serialization index (or string name)
|
|
// The values must be unique and versioning has to be considered as well.
|
|
// Keys are described in later sections in more detail.
|
|
[Key(0)]
|
|
public int Age { get; set; }
|
|
|
|
[Key(1)]
|
|
public string FirstName { get; set; }
|
|
|
|
[Key(2)]
|
|
public string LastName { get; set; }
|
|
|
|
// All fields or properties that should not be serialized must be annotated with [IgnoreMember].
|
|
[IgnoreMember]
|
|
public string FullName { get { return FirstName + LastName; } }
|
|
}
|
|
}
|