Ejemplo n.º 1
0
        /// <summary>
        /// Deserializes a meta-collection from the given stream.
        /// </summary>
        public static MetaCollection Deserialize(Stream stream, ArrayProfile profile)
        {
            var version = stream.ReadByte();

            if (version != 1)
            {
                throw new Exception(string.Format("Cannot deserialize meta-data collection: Invalid version #: {0}, upgrade Itinero.", version));
            }

            var byteHeader = stream.ReadByte();
            var type       = MetaCollection.GetTypeForHeader(byteHeader);

            var bytes = new byte[8];

            stream.Read(bytes, 0, 8);
            var length = BitConverter.ToInt64(bytes, 0);

            if (type == typeof(int))
            {
                return(new MetaCollection <int>(MetaCollection.DeserializeArray <int>(
                                                    stream, profile, length, 4)));
            }
            if (type == typeof(uint))
            {
                return(new MetaCollection <uint>(MetaCollection.DeserializeArray <uint>(
                                                     stream, profile, length, 4)));
            }
            if (type == typeof(long))
            {
                return(new MetaCollection <long>(MetaCollection.DeserializeArray <long>(
                                                     stream, profile, length, 8)));
            }
            if (type == typeof(ulong))
            {
                return(new MetaCollection <ulong>(MetaCollection.DeserializeArray <ulong>(
                                                      stream, profile, length, 8)));
            }
            if (type == typeof(float))
            {
                return(new MetaCollection <float>(MetaCollection.DeserializeArray <float>(
                                                      stream, profile, length, 4)));
            }
            if (type == typeof(double))
            {
                return(new MetaCollection <double>(MetaCollection.DeserializeArray <double>(
                                                       stream, profile, length, 8)));
            }
            throw new Exception(string.Format(
                                    "Meta collection not supported for type {0}: MetaCollection can only handle integer types or float and double.",
                                    type));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Copies an element from the other collection to this one. Collections must have the same type.
 /// </summary>
 public abstract void CopyFrom(MetaCollection other, uint idx, uint otherIdx);