private static Encoding Get_Encoder(String_Encoding string_encoding, bool swap_endianness) { //get the right encoder, also keeping byte ordering into account. //this way there would be no need to individually flip characters as the encoder will take care of that return(string_encoding == String_Encoding.UTF8 ? Encoding.UTF8 : swap_endianness?Encoding.BigEndianUnicode : Encoding.Unicode); }
public void Deserialize_String(out string text, String_Encoding encoding) { byte[] buffer; Deserialize(out buffer); if (buffer != null) { var string_encoder = Get_Encoder(encoding, swap_endianness); text = string_encoder.GetString(buffer); } else { text = null; } }
public void Serialize_String(string text, String_Encoding encoding) { var string_encoder = Get_Encoder(encoding, swap_endianness); if (text != null) { //NOTE: encoder handling byte ordering var buffer = string_encoder.GetBytes(text); Serialize(buffer); } else { stream.WriteByte(0); } }