Beispiel #1
0
        public static Table2D TryParseValid(System.IO.Stream stream)
        {
            s_tableInfo2D.Reset();

            s_tableInfo2D.location = (int)stream.Position;

            s_tableInfo2D.countX = stream.ReadInt16BigEndian();

            // First byte matters, residual byte probably just zero for alignment.
            // By reading as little endian word we read and verify all two bytes in one go.
            s_tableInfo2D.tableType = (TableType)stream.ReadInt16LittleEndian();

            s_tableInfo2D.rangeX.Pos = stream.ReadInt32BigEndian();
            s_tableInfo2D.rangeY.Pos = stream.ReadInt32BigEndian();

            // most but not all non-float tables have MAC floats:
            s_tableInfo2D.multiplier = stream.ReadSingleBigEndian();
            s_tableInfo2D.offset     = stream.ReadSingleBigEndian();

            long afterRecord = stream.Position;

            if (s_tableInfo2D.IsRecordValid())
            {
                if (!s_tableInfo2D.hasMAC)
                {
                    // must back off stream position for next possible struct
                    afterRecord -= 2 * FloatSize;
                }

                bool valuesOk = s_tableInfo2D.ReadValidateValues(stream);
//				if (!valuesOk) {
//					Console.Error.WriteLine ("2D: Error in values");
//				}

                stream.Position = afterRecord;

                return(valuesOk ? s_tableInfo2D.Copy() : null);
            }
            else
            {
                return(null);
            }
        }