コード例 #1
0
        public T Deserialize(BinaryReader reader)
        {
            var magicByte = reader.ReadByte();

            if (magicByte != MagicByte)
            {
                throw new SerializationException("Magic byte is not found at the beginning or the schema-aware message. Make sure the message is in AVRO format, and is written with Confluent-compatible driver. Probably someone written JSON message in your AVRO topic?");
            }

            var schemaId = IPAddress.NetworkToHostOrder(reader.ReadInt32());

            var deserializer = (Func <Stream, T>)DeserializersCache.GetOrAdd(Tuple.Create(schemaId, _environment), _ =>
            {
                var writerSchema  = _registryApi.GetById(schemaId).Result.Schema;
                var newSerializer = _serializerFactory.BuildDeserializer(writerSchema);
                return(newSerializer);
            });

            var result = deserializer(reader.BaseStream);

            return(result);
        }