Example #1
0
        // Utilities for reading.

        /// <summary>
        /// Read the model header, strings, etc from reader. Also validates the header (throws if bad).
        /// Leaves the reader position at the beginning of the model blob.
        /// </summary>
        public static void BeginRead(out long fpMin, out ModelHeader header, out string[] strings, out string loaderAssemblyName, BinaryReader reader)
        {
            fpMin = reader.FpCur();

            byte[] headerBytes = reader.ReadBytes(ModelHeader.Size);
            Contracts.CheckDecode(headerBytes.Length == ModelHeader.Size);
            ModelHeader.MarshalFromBytes(out header, headerBytes);

            Exception ex;

            if (!ModelHeader.TryValidate(ref header, reader, fpMin, out strings, out loaderAssemblyName, out ex))
            {
                throw ex;
            }

            reader.Seek(header.FpModel + fpMin);
        }