Inheritance: ISpecificRecord
Ejemplo n.º 1
0
        public byte[] SerializeAvro(InheritedEntityAvro thisObj)
        {
            using (var ms = new MemoryStream())
            {
                var enc = new BinaryEncoder(ms);
                var writer = new SpecificDefaultWriter(InheritedEntityAvro._SCHEMA); // Schema comes from pre-compiled, code-gen phase
                writer.Write(thisObj, enc);

                return ms.ToArray();
            }
        }
Ejemplo n.º 2
0
        public InheritedEntityAvro DeserializeAvro(byte[] bytes)
        {
            using (var ms = new MemoryStream(bytes))
            {
                var dec = new BinaryDecoder(ms);
                var reader = new SpecificDefaultReader(InheritedEntityAvro._SCHEMA, InheritedEntityAvro._SCHEMA);
                var regenAvroMsg = new InheritedEntityAvro();
                reader.Read(regenAvroMsg, dec);

                return regenAvroMsg;
            }
        }
Ejemplo n.º 3
0
        private void CompareSchemas()
        {
            var eCodeGenEntity = new InheritedEntityAvro();

            // Extra test for schema compare, save schema to compare later
            string avroSchema = eCodeGenEntity.Schema.ToString();

            // Extra test for schema compare, save schema to compare later
            var serializer = new AvroSerializer(typeof(InheritedEntity));

            string avroMsftSchema = serializer.Schema;

            Console.Write("\nThe Avro MSFT schema and the Avro Apache schema ");
            if (String.IsNullOrEmpty(avroSchema) || (avroSchema != avroMsftSchema))
            {
                Console.WriteLine("do NOT MATCH !!!\n");
                Console.WriteLine("Avro Apache schema: {0}", avroSchema);
                Console.WriteLine("Avro MSFT schema  : {0}", avroMsftSchema);
            }
            else
                Console.WriteLine("match.\n");
        }
Ejemplo n.º 4
0
        private void AvroToAvroMsft()
        {
            // avro ser => avro-msft deser

            var e = new InheritedEntity();
            e.FillDummyData();

            // Avro-Apache serialize
            var eCodeGenEntity = new InheritedEntityAvro();
            eCodeGenEntity.InjectFrom(e);
            var eBytes = SerializeAvro(eCodeGenEntity);

            // Avro MSFT deserialize
            var eAppEntityRegen = DeserializeAvroMsft(eBytes);

            // Compare the object (in JSON, easiest to do so)
            var eJson = JsonConvert.SerializeObject(e);
            var eRegenJson = JsonConvert.SerializeObject(eAppEntityRegen);

            Console.Write("avro ser => avro-msft deser ");
            if (eJson != eRegenJson)
                Console.WriteLine("FAILED !!!");
            else
                Console.WriteLine("passed");
        }