예제 #1
0
        /// <summary>
        /// Encode special chars.
        /// </summary>
        private static void EncodeEscaped()
        {
            FOA.Encoder encoder = new FOA.Encoder();

            Console.WriteLine("Escape enabled:");
            encoder.Write("a(b[c]d)e=f");
            Console.Write(encoder.GetString());

            Console.WriteLine("Escape disabled:");
            encoder.SetOption(FOA.Option.EnableEscape, false);
            encoder.Write("a(b[c]d)e=f");
            Console.Write(encoder.GetString());
        }
예제 #2
0
        /// <summary>
        /// Encode the data without using a backing store, that is, the encoded
        /// data is not appended to a stream. Instead only encoded data from the
        /// last Write() is stored in the buffer.
        /// </summary>
        private static void EncodeNoStore()
        {
            FOA.Encoder encoder = new FOA.Encoder();

            encoder.Write("person", FOA.SpecialChars.StartObject);
            Console.Write(encoder.GetString());
            encoder.Write("name", "Adam");
            Console.Write(encoder.GetString());
            encoder.Write("age", 35);
            Console.Write(encoder.GetString());
            encoder.Write("ratio", 8.37);
            Console.Write(encoder.GetString());
            encoder.Write(FOA.SpecialChars.EndObject);
            Console.Write(encoder.GetString());
        }
예제 #3
0
        /// <summary>
        /// Encode data writing the result to a text file.
        /// </summary>
        private static void EncodeFile()
        {
            using (FileStream writer = new FileStream("output.txt", FileMode.Create))
            {
                FOA.Encoder encoder = new FOA.Encoder(writer);

                //
                // Write an object.
                //
                encoder.Write("person", FOA.SpecialChars.StartObject);
                encoder.Write("name", "Adam");
                encoder.Write("age", 35);
                encoder.Write("ratio", 8.37);
                encoder.Write(FOA.SpecialChars.EndObject);
            }
        }
예제 #4
0
        /// <summary>
        /// Encode data writing the result to an memory stream.
        /// </summary>
        private static void EncodeMemory()
        {
            FOA.Encoder encoder = new FOA.Encoder(new MemoryStream());

            //
            // Write an object.
            //
            encoder.Write("person", FOA.SpecialChars.StartObject);
            encoder.Write("name", "Adam");
            encoder.Write("age", 35);
            encoder.Write("ratio", 8.37);
            encoder.Write(FOA.SpecialChars.EndObject);

            //
            // Get memory stream and convert its byte array to an string object.
            //
            MemoryStream stream = (MemoryStream)encoder.GetStream();

            Console.WriteLine(Encoding.Unicode.GetString(stream.GetBuffer()));
        }