示例#1
0
 public static byte[] SerializeDictionary <TK, TV>(this IDictionary <TK, TV> dictionary)
     where TK : struct where TV : struct
 {
     using var writer = new PoolByteWriter();
     writer.WriteInt(dictionary.Count);
     foreach ((TK key, TV value) in dictionary)
     {
         writer.Write <TK>(key);
         writer.Write <TV>(value);
     }
     return(writer.ToArray());
 }
示例#2
0
 public static byte[] Serialize <T>(this T value) where T : IByteSerializable
 {
     using var writer = new PoolByteWriter();
     writer.WriteClass <T>(value);
     return(writer.ToArray());
 }
示例#3
0
 public static byte[] SerializeCollection <T>(this ICollection <T> collection) where T : struct
 {
     using var writer = new PoolByteWriter();
     writer.WriteCollection(collection);
     return(writer.ToArray());
 }