예제 #1
0
파일: BFast.cs 프로젝트: vimaec/bfast
        /// <summary>
        /// Checks that the header values are sensible, and throws an exception otherwise.
        /// </summary>
        public static BFastPreamble Validate(this BFastPreamble preamble)
        {
            if (preamble.Magic != Constants.SameEndian && preamble.Magic != Constants.SwappedEndian)
            {
                throw new Exception($"Invalid magic number {preamble.Magic}");
            }

            if (preamble.DataStart < BFastPreamble.Size)
            {
                throw new Exception($"Data start {preamble.DataStart} cannot be before the file header size {BFastPreamble.Size}");
            }

            if (preamble.DataStart > preamble.DataEnd)
            {
                throw new Exception($"Data start {preamble.DataStart} cannot be after the data end {preamble.DataEnd}");
            }

            if (!IsAligned(preamble.DataEnd))
            {
                throw new Exception($"Data end {preamble.DataEnd} should be aligned");
            }

            if (preamble.NumArrays < 0)
            {
                throw new Exception($"Number of arrays {preamble.NumArrays} is not a positive number");
            }

            if (preamble.NumArrays > preamble.DataEnd)
            {
                throw new Exception($"Number of arrays {preamble.NumArrays} can't be more than the total size");
            }

            if (preamble.RangesEnd > preamble.DataStart)
            {
                throw new Exception($"End of range {preamble.RangesEnd} can't be after data-start {preamble.DataStart}");
            }

            return(preamble);
        }
예제 #2
0
 public bool Equals(BFastPreamble other)
 => Magic == other.Magic && DataStart == other.DataStart && DataEnd == other.DataEnd && NumArrays == other.NumArrays;