Exemple #1
0
        /// <summary>
        ///     Reads the header from the specified decoder.
        /// </summary>
        /// <param name="decoder">The decoder.</param>
        /// <exception cref="System.Runtime.Serialization.SerializationException">Thrown when the object in the stream is not a valid Avro object container.</exception>
        /// <returns>The header.</returns>
        public static ObjectContainerHeader Read(IDecoder decoder)
        {
            if (decoder == null)
            {
                throw new ArgumentNullException("decoder");
            }

            byte[] magic = decoder.DecodeFixed(Magic.Length);
            if (!Magic.SequenceEqual(magic))
            {
                throw new SerializationException("Invalid Avro object container in a stream. The header cannot be recognized.");
            }

            var metadata = new Dictionary <string, byte[]>();

            for (long currentChunkSize = decoder.DecodeMapChunk(); currentChunkSize != 0; currentChunkSize = decoder.DecodeMapChunk())
            {
                for (int i = 0; i < currentChunkSize; ++i)
                {
                    string key   = decoder.DecodeString();
                    byte[] value = decoder.DecodeByteArray();
                    metadata.Add(key, value);
                }
            }

            byte[] syncMarker = decoder.DecodeFixed(16);
            return(new ObjectContainerHeader(metadata, syncMarker));
        }
        protected override object DeserializeSafe(IDecoder decoder)
        {
            int length = decoder.DecodeMapChunk();
            var result = new Dictionary <string, object>();

            while (length != 0)
            {
                for (int i = 0; i < length; ++i)
                {
                    result.Add(decoder.DecodeString(), this.Schema.ValueSchema.Serializer.Deserialize(decoder));
                }
                length = decoder.DecodeMapChunk();
            }
            return(result);
        }
Exemple #3
0
 protected override object DeserializeSafe(IDecoder decoder)
 {
     return(decoder.DecodeString());
 }
        /// <summary>
        ///     Reads the header from the specified decoder.
        /// </summary>
        /// <param name="decoder">The decoder.</param>
        /// <exception cref="System.Runtime.Serialization.SerializationException">Thrown when the object in the stream is not a valid Avro object container.</exception>
        /// <returns>The header.</returns>
        public static ObjectContainerHeader Read(IDecoder decoder)
        {
            if (decoder == null)
            {
                throw new ArgumentNullException("decoder");
            }

            byte[] magic = decoder.DecodeFixed(Magic.Length);
            if (!Magic.SequenceEqual(magic))
            {
                throw new SerializationException("Invalid Avro object container in a stream. The header cannot be recognized.");
            }

            var metadata = new Dictionary<string, byte[]>();
            for (long currentChunkSize = decoder.DecodeMapChunk(); currentChunkSize != 0; currentChunkSize = decoder.DecodeMapChunk())
            {
                for (int i = 0; i < currentChunkSize; ++i)
                {
                    string key = decoder.DecodeString();
                    byte[] value = decoder.DecodeByteArray();
                    metadata.Add(key, value);
                }
            }

            byte[] syncMarker = decoder.DecodeFixed(16);
            return new ObjectContainerHeader(metadata, syncMarker);
        }