public static void Serialize(Stream bytes, ICollection <T> instance, Serializer <T> serialization) { UInt16Proxy.Serialize(bytes, (ushort)instance.Count); foreach (T current in instance) { serialization(bytes, current); } }
public static List <T> Deserialize(Stream bytes, Deserializer <T> serialization) { ushort length = UInt16Proxy.Deserialize(bytes); List <T> list = new List <T>(length); for (int i = 0; i < length; i++) { list.Add(serialization(bytes)); } return(list); }
public static string Deserialize(Stream bytes) { ushort length = UInt16Proxy.Deserialize(bytes); if (length > 0) { byte[] buffer = new byte[(length * 2)]; bytes.Read(buffer, 0, buffer.Length); return(Encoding.Unicode.GetString(buffer, 0, buffer.Length)); } return(string.Empty); }
public static void Serialize(Stream bytes, string instance) { if (string.IsNullOrEmpty(instance)) { UInt16Proxy.Serialize(bytes, 0); } else { UInt16Proxy.Serialize(bytes, (ushort)instance.Length); byte[] buffer = Encoding.Unicode.GetBytes(instance); bytes.Write(buffer, 0, buffer.Length); } }