Example #1
0
        public TableCell(Types type, BinaryReader reader, MDTables helper)
        {
            _type = type;

            try
            {
                // Fixed
                if (type == Types.UInt16)
                {
                    _rawData = reader.ReadUInt16();
                }
                if (type == Types.UInt32)
                {
                    _rawData = reader.ReadUInt32();
                }

                // Heap
                if (type == Types.String)
                {
                    _rawData = ((helper.GetStringIndexSize() == 2) ? (uint)reader.ReadUInt16() : reader.ReadUInt32());
                }
                if (type == Types.Guid)
                {
                    _rawData = ((helper.GetGuidIndexSize() == 2) ? (uint)reader.ReadUInt16() : reader.ReadUInt32());
                }
                if (type == Types.Blob)
                {
                    _rawData = ((helper.GetBlobIndexSize() == 2) ? (uint)reader.ReadUInt16() : reader.ReadUInt32());
                }

                // Rid
                if ((int)type < 64)
                {
                    Table table = helper.GetTable(type);
                    _rawData = (uint)(((uint)type << 24) | ((table.Count < 65536) ? (uint)reader.ReadUInt16() : reader.ReadUInt32()));
                }

                // Coded token (may need to be uncompressed from 2-byte form)
                else if ((int)type < 97)
                {
                    int     codedToken     = (helper.SizeOfType(type) == 2) ? reader.ReadUInt16() : reader.ReadInt32();
                    Types[] referredTables = (Types[])helper.CodedTokenTypes(type);

                    int tableIndex = (int)(codedToken & ~(-1 << helper.CodedTokenBits(referredTables.Length)));
                    int index      = (int)(codedToken >> helper.CodedTokenBits(referredTables.Length));

                    int token = helper.ToToken(referredTables[tableIndex], index - 1);
                    _rawData = (uint)token;
                }

                _data = CreateData(helper);
            }
            catch            //(Exception e)
            {
                _type = Types.String;
                _data = "Unreadable cell: " + type + " " + _rawData;
            }
        }
Example #2
0
        public Table(Types type, Types[] colTypes, String[] colNames, MDTables helper, BinaryReader reader)
        {
            _type   = type;
            _helper = helper;

            _colDescs = new ColDesc[colTypes.Length];

            for (int i = 0; i < _colDescs.Length; i++)
            {
                _colDescs[i] = new ColDesc(colTypes[i], colNames[i]);
            }

            _rows = new Row[helper.GetTableRows(type)];

            _rowSize = 0;
            foreach (ColDesc cd in _colDescs)
            {
                _rowSize += _helper.SizeOfType(cd.Type);
            }

            data = reader.ReadBytes(_rowSize * Count);
        }