Beispiel #1
0
 static void TwitterAvroTest()
 {
     using (var r = new ChoAvroReader("twitter.avro")
                    .Configure(c => c.UseAvroSerializer = false)
                    .ErrorMode(ChoErrorMode.IgnoreAndContinue)
            )
     {
         foreach (var rec in r)
         {
             rec.Print();
         }
     }
 }
Beispiel #2
0
 static void TwitterSnappyAvroTest()
 {
     using (var r = new ChoAvroReader("twitter.snappy.avro")
                    .Configure(c => c.UseAvroSerializer = false)
                    .Configure(c => c.Codec = new CodecFactory().Create(AvroCompressionCodec.Snappy))
                    .ErrorMode(ChoErrorMode.IgnoreAndContinue)
            )
     {
         foreach (var rec in r)
         {
             rec.Print();
         }
     }
 }
Beispiel #3
0
        static void SerializeAndDeserializeDynamicTest()
        {
            string path = "AvroSampleReflection.avro";
            //SerializeDynamicSampleFile(path);

            var dict = new Dictionary <string, object>();

            dict.Add("1", 3);
            dict.Add("2", new Location {
                Room = 243, Floor = 1
            });

            ChoAvroRecordConfiguration config = null;
            AvroSerializerSettings     sett1  = null;

            using (var w = new ChoAvroWriter(path)
                           .WithAvroSerializer(AvroSerializer.Create <Dictionary <string, object> >(new AvroSerializerSettings()
            {
                Resolver = new ChoAvroPublicMemberContractResolver()
            }))
                           .Configure(c => c.KnownTypes = new List <Type> {
                typeof(Location), typeof(string), typeof(int)
            })
                           //.Configure(c => c.UseAvroSerializer = true)
                           //.Configure(c => c.AvroSerializerSettings.Resolver = new AvroDataContractResolverEx())
                   )
            {
                sett1  = w.Configuration.AvroSerializerSettings;
                config = w.Configuration;

                w.Write(dict);
                w.Write(dict);
                w.Write(dict);
            }
            //var sett = new AvroSerializerSettings();
            //sett.Resolver = new ChoAvroPublicMemberContractResolver(); // false) { Configuration = config };
            //sett.KnownTypes = new List<Type> { typeof(Location), typeof(string), typeof(int) };
            //var avroSerializer = AvroSerializer.Create<Dictionary<string, object>>(sett1);
            //using (var r = new StreamReader(path))
            //{
            //    var rec = avroSerializer.Deserialize(r.BaseStream);
            //    var rec2 = avroSerializer.Deserialize(r.BaseStream);
            //    var rec3 = avroSerializer.Deserialize(r.BaseStream);
            //    Console.WriteLine(rec.Dump());
            //    Console.WriteLine(rec2.Dump());
            //    Console.WriteLine(rec3.Dump());
            //    //var rec4 = avroSerializer.Deserialize(r);
            //}

            StringBuilder json = new StringBuilder();

            using (var r = new ChoAvroReader(path)
                           .Configure(c => c.KnownTypes = new List <Type> {
                typeof(Location), typeof(string), typeof(int)
            })
                           .Configure(c => c.UseAvroSerializer = true)
                           //.Configure(c => c.AvroSerializerSettings = sett1)
                           .Configure(c => c.NestedColumnSeparator = '_')
                   )
            {
                //var dt = r.AsDataTable();
                //Console.WriteLine(dt.Dump());
                //return;
                //foreach (var rec in r)
                //{
                //    Console.WriteLine(rec.Dump());
                //}
                //return;
                using (var w = new ChoJSONWriter(json)
                               .Configure(c => c.TurnOnAutoDiscoverJsonConverters = true)
                       )
                {
                    w.Write(r);
                }
            }
            Console.WriteLine(json.ToString());
        }
Beispiel #4
0
        static void POCOTest()
        {
            string path = "AvroPOCOSample1.avro";

            //SerializePOCOSampleFile(path);

            //var sett = new AvroSerializerSettings();
            //sett.Resolver = new ChoAvroPublicMemberContractResolver();
            //sett.KnownTypes = new List<Type> { typeof(Location), typeof(string) };
            //var avroSerializer = AvroSerializer.Create<SensorData>(sett);

            //using (var buffer = new StreamReader(File.OpenRead(path)))
            //{
            //    var actual1 = avroSerializer.Deserialize(buffer.BaseStream);
            //    var actual2 = avroSerializer.Deserialize(buffer.BaseStream);

            //    Console.WriteLine(actual1.Dump());
            //}
            //return;
            var testData = new List <SensorData>
            {
                new SensorData {
                    Value = new byte[] { 1, 2, 3, 4, 5 }, Position = new Location {
                        Room = 243, Floor = 1
                    }
                },
                new SensorData {
                    Value = new byte[] { 6, 7, 8, 9 }, Position = new Location {
                        Room = 244, Floor = 1
                    }
                }
            };

            using (var w = new ChoAvroWriter <SensorData>(path)
                   )
            {
                //w.Write(testData);
                w.Write(new SensorData {
                    Value = new byte[] { 1, 2, 3, 4, 5 }, Position = new Location {
                        Room = 243, Floor = 1
                    }
                });
                w.Write(new SensorData {
                    Value = new byte[] { 6, 7, 8, 9 }, Position = new Location {
                        Room = 244, Floor = 1
                    }
                });
            }

            StringBuilder json = new StringBuilder();

            using (var r = new ChoAvroReader <SensorData>(path)
                           //.WithAvroSerializer(AvroSerializer.Create<Dictionary<string, object>>(new AvroSerializerSettings()))
                   )
            {
                foreach (var rec in r)
                {
                    Console.WriteLine(rec.Dump());
                }
                return;

                using (var w = new ChoJSONWriter(json)
                               .Configure(c => c.TurnOnAutoDiscoverJsonConverters = true)
                       )
                {
                    w.Write(r);
                }
            }
            Console.WriteLine(json.ToString());
        }