Ejemplo n.º 1
0
        public IndexDefinitionRecord(RandomAccess rx)
        {
            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            ExternalFile = rx.ZeroTerminatedString();

            if (ExternalFile.Length == 0)
            {
                int read = rx.Byte();

                if (read != 0x01)
                {
                    throw new ArgumentException($"Bad index definition: missing 0x01 after zero string ({read:X2})");
                }
            }

            Name        = rx.ZeroTerminatedString();
            Flags       = rx.Byte();
            FieldsInKey = rx.ShortLE();

            KeyField     = new int[FieldsInKey];
            KeyFieldFlag = new int[FieldsInKey];

            for (int i = 0; i < FieldsInKey; i++)
            {
                KeyField[i]     = rx.ShortLE();
                KeyFieldFlag[i] = rx.ShortLE();
            }
        }
Ejemplo n.º 2
0
        public FieldDefinitionRecord(RandomAccess rx)
        {
            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            Type         = (TpsTypeCode)rx.Byte();
            Offset       = rx.ShortLE();
            FullName     = rx.ZeroTerminatedString();
            ElementCount = rx.ShortLE();
            Length       = rx.ShortLE();
            Flags        = rx.ShortLE();
            Index        = rx.ShortLE();

            switch (Type)
            {
            case TpsTypeCode.Decimal:
                BcdDigitsAfterDecimalPoint = rx.Byte();
                BcdElementLength           = rx.Byte();
                break;

            case TpsTypeCode.String:
            case TpsTypeCode.CString:
            case TpsTypeCode.PString:
                StringLength = rx.ShortLE();
                StringMask   = rx.ZeroTerminatedString();
                if (StringMask.Length == 0)
                {
                    rx.Byte();
                }
                break;
            }
        }
Ejemplo n.º 3
0
        public void ShouldReuseBuffer()
        {
            var ra = new RandomAccess(new byte[] { 1, 2, 3, 4 });

            ra.Byte();
            var read = ra.Read(3);

            Assert.AreEqual(3, read.Length);
            Assert.AreEqual(0, read.Position);
            Assert.AreEqual(2, read.Byte());
            Assert.AreEqual(3, read.Byte());
            Assert.AreEqual(4, read.Byte());

            read.JumpAbsolute(0);
            Assert.AreEqual(2, read.Byte());

            read.JumpRelative(1);
            Assert.AreEqual(4, read.Byte());

            read.JumpAbsolute(1);

            var read2 = read.Read(2);

            Assert.AreEqual(2, read2.Length);
            Assert.AreEqual(0, read2.Position);
            Assert.AreEqual(3, read2.Byte());
            Assert.AreEqual(4, read2.Byte());
        }
Ejemplo n.º 4
0
        public MetadataHeader(RandomAccess rx)
            : base(rx)
        {
            AssertIsType(0xF6);

            AboutType = rx.Byte();
        }
Ejemplo n.º 5
0
        public void ShouldParseByte(byte value, byte[] data)
        {
            var  rx     = new RandomAccess(data);
            byte parsed = rx.Byte();

            Assert.AreEqual(value, parsed);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Instantiates a new header.
        /// </summary>
        /// <param name="rx"></param>
        public MemoHeader(RandomAccess rx)
            : base(rx)
        {
            AssertIsType(0xFC);

            OwningRecord   = rx.LongBE();
            MemoIndex      = rx.Byte();
            SequenceNumber = rx.ShortBE();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Instantiates a new BYTE from the given binary reader.
        /// </summary>
        /// <param name="rx"></param>
        public TpsByte(RandomAccess rx)
        {
            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            Value = rx.Byte();
        }
Ejemplo n.º 8
0
        public void ShouldFailBeyondBuffer()
        {
            var ra = new RandomAccess(new byte[] { 1, 2, 3, 4 });

            ra.Byte();
            var read = ra.Read(3);

            Assert.Throws <IndexOutOfRangeException>(() => read.LongLE());
        }
Ejemplo n.º 9
0
        public void ShouldFailBeforeBuffer()
        {
            var ra = new RandomAccess(new byte[] { 1, 2, 3, 4 });

            ra.Byte();
            var read = ra.Read(3);

            read.JumpAbsolute(-1);

            Assert.Throws <IndexOutOfRangeException>(() => read.Byte());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Instantiates a new header.
        /// </summary>
        /// <param name="rx"></param>
        /// <param name="readTable"></param>
        public Header(RandomAccess rx, bool readTable)
        {
            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            if (readTable)
            {
                TableNumber = rx.LongBE();
            }

            TableType = rx.Byte();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new <see cref="TpsRecord"/> by partially copying the previous one.
        /// </summary>
        /// <param name="previous">The previous record.</param>
        /// <param name="rx">The data to read from.</param>
        public TpsRecord(TpsRecord previous, RandomAccess rx)
        {
            if (previous == null)
            {
                throw new ArgumentNullException(nameof(previous));
            }

            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            Flags = rx.Byte();

            if ((Flags & 0x80) != 0)
            {
                RecordLength = rx.ShortLE();
            }
            else
            {
                RecordLength = previous.RecordLength;
            }

            if ((Flags & 0x40) != 0)
            {
                HeaderLength = rx.ShortLE();
            }
            else
            {
                HeaderLength = previous.HeaderLength;
            }

            int copy = Flags & 0x3F;

            var newData = new List <byte>(RecordLength);

            newData.AddRange(previous.Data.GetData().Take(copy));
            newData.AddRange(rx.ReadBytes(RecordLength - copy));

            Data = new RandomAccess(newData.ToArray());

            if (Data.Length != RecordLength)
            {
                throw new ArgumentException("Data and record length mismatch.");
            }

            BuildHeader();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a new <see cref="TpsRecord"/>. This is typically done on the first of a list.
        /// </summary>
        /// <param name="rx">The data to read from.</param>
        public TpsRecord(RandomAccess rx)
        {
            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            Flags = rx.Byte();

            if ((Flags & 0xC0) != 0xC0)
            {
                throw new ArgumentException($"Cannot construct a TpsRecord without record lengths (0x{rx.ToHex2(Flags)})");
            }

            RecordLength = rx.ShortLE();
            HeaderLength = rx.ShortLE();

            Data = rx.Read(RecordLength);

            BuildHeader();
        }
Ejemplo n.º 13
0
        public MemoDefinitionRecord(RandomAccess rx)
        {
            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            ExternalFile = rx.ZeroTerminatedString();

            if (ExternalFile.Length == 0)
            {
                byte memoMarker = rx.Byte();

                if (memoMarker != 1)
                {
                    throw new ArgumentException($"Bad memo definition: missing 0x01 after zero string. Was 0x{memoMarker:x2}.");
                }
            }

            FullName = rx.ZeroTerminatedString();
            Length   = rx.ShortLE();
            Flags    = rx.ShortLE();
        }