Beispiel #1
0
 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);
 }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        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);
            }
        }