Exemple #1
0
        public void TestUTF8Serialization()
        {
            // Create a string with multi-bytes character.
            String surrogate = "abc" + Char.ConvertFromUtf32(Int32.Parse("2A601", NumberStyles.HexNumber)) + "def";

            // Safe UTF-8 encoding & decoding of string.
            Stream     stream = new MemoryStream();
            DataWriter writer = new DataWriter(stream);

            byte[] bytes = writer.FormatUTF(surrogate);

            Console.WriteLine("Safe UTF-8-encoded code units:");
            foreach (var utf8Byte in bytes)
            {
                Console.Write("{0:X2} ", utf8Byte);
            }
            Console.WriteLine();
            string s = SerializationHelper.ConvertUTF(bytes, 0, bytes.Length);

            Assert.AreEqual(s, surrogate);
        }