Beispiel #1
0
        public static void TestOne()
        {
            Console.WriteLine("Hello World!");
            var serviceProvider = new ServiceCollection()
                                  .AddHagar()
                                  .AddSerializers(typeof(SomeClassWithSerialzers).Assembly)
                                  .AddHagar(options =>
            {
                options.PartialSerializers.Add(typeof(SubTypeSerializer));
                options.PartialSerializers.Add(typeof(BaseTypeSerializer));
            })
                                  .BuildServiceProvider();

            var c = serviceProvider.GetRequiredService <IPartialSerializer <SubType> >();

            c.Serialize(new Writer(), serviceProvider.GetRequiredService <SessionPool>().GetSession(), new SubType());
            var codecs = serviceProvider.GetRequiredService <ITypedCodecProvider>();

            var codec       = codecs.GetCodec <SomeClassWithSerialzers>();
            var sessionPool = serviceProvider.GetRequiredService <SessionPool>();

            var writeSession = sessionPool.GetSession();
            var writer       = new Writer();

            codec.WriteField(writer,
                             writeSession,
                             0,
                             typeof(SomeClassWithSerialzers),
                             new SomeClassWithSerialzers {
                IntField = 2, IntProperty = 30
            });

            using (var readerSession = sessionPool.GetSession())
            {
                var reader = new Reader(writer.ToBytes());
                Console.WriteLine(string.Join(" ", TokenStreamParser.Parse(reader, readerSession)));
            }

            using (var readerSession = sessionPool.GetSession())
            {
                var reader        = new Reader(writer.ToBytes());
                var initialHeader = reader.ReadFieldHeader(readerSession);
                var result        = codec.ReadValue(reader, readerSession, initialHeader);
                Console.WriteLine(result);
            }
        }
Beispiel #2
0
        static public FHXObject FromString(string s)
        {
            BuildingPercent = 0;
            State           = Properties.Resources.ParsingParsing;

            Stopwatch sw = new Stopwatch();

            sw.Restart();
            TokenStream ts = new TokenStream(s);

            sw.Restart();
            mParser = new TokenStreamParser(ts);
            FHXObject root = mParser.ParseAll();

            sw.Stop();
            Console.WriteLine("Parsing file took {0} ms", sw.ElapsedMilliseconds);

            mParser.mTokenStream.Input.Clear();

            return(root);
        }