Example #1
0
        /// <summary>
        /// Deserializes an <see cref="IEnumerable{T}"/> of type <see cref="NnSerializationContext"/> from a file.
        /// </summary>
        /// <returns>A list of serialization contexts.</returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="NullReferenceException"></exception>
        public IEnumerable <NnSerializationContext> Deserialize()
        {
            int count = DeserializeContextCount();

            Contracts.ValueGreaterThanZero(count, nameof(count));

            var contexts = new List <NnSerializationContext>();
            var contextInfoDictionary = new Dictionary <int, NnSerializationContextInfo>();

            for (var i = 0; i < count; i++)
            {
                NnSerializationContextInfo contextInfo = DeserializeContextInfo();

                contextInfoDictionary.Add(i, contextInfo);
            }

            for (var i = 0; i < count; i++)
            {
                if (!contextInfoDictionary.TryGetValue(i, out NnSerializationContextInfo contextInfo))
                {
                    throw new NullReferenceException("No context info with was found for the given key.");
                }

                double[] contextData = DeserializeContextData(contextInfo.DataSizeInBytes);

                var context = new NnSerializationContext(contextData, contextInfo);

                contexts.Add(context);
            }

            return(contexts);
        }
Example #2
0
        /// <summary>
        /// Deserializes a <see cref="NnSerializationContext"/> from a file.
        /// </summary>
        /// <returns>A serialization context.</returns>
        /// <exception cref="NotSupportedException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public NnSerializationContext DeserializeSingle()
        {
            int count = DeserializeContextCount();

            Contracts.ValueGreaterThanZero(count, nameof(count));

            if (count > 1)
            {
                throw new NotSupportedException("Can not deserialize a single context, from a file that stores multiple contexts.");
            }

            NnSerializationContextInfo contextInfo = DeserializeContextInfo();

            double[] contextData = DeserializeContextData(contextInfo.DataSizeInBytes);

            var context = new NnSerializationContext(contextData, contextInfo);

            return(context);
        }
 /// <summary>
 /// Serializes the specified <see cref="NnSerializationContext"/> to a file.
 /// </summary>
 /// <param name="serializationContext">The serialization context.</param>
 public void Serialize(NnSerializationContext serializationContext)
 {
     SerializeContextCount(1);
     SerializeContextInfo(serializationContext.SerializationContextInfo);
     SerializeContextData(serializationContext.FileData);
 }