public DbcTable(Stream storage, bool storageOwner = true) { if (storage == null) { throw new ArgumentNullException("storage"); } if (!storage.CanSeek || !storage.CanRead) { throw new ArgumentException("storage"); } stream = storage; streamOwner = storageOwner; stream.Seek(0, SeekOrigin.Begin); reader = new BinaryReader(storage, Encoding.UTF8, true); magic = reader.ReadInt32(); if (magic == 0x43424457) { format = DbcFileFormat.Dbc; headerLength = HEADER_LENGTH_DBC; } else if (magic == 0x32424457) { format = DbcFileFormat.Db2; headerLength = HEADER_LENGTH_DB2; } else if (magic == 0x32484357) { format = DbcFileFormat.AdbCache; headerLength = HEADER_LENGTH_DB2; } else { throw new InvalidDataException("Invalid header."); } count = reader.ReadInt32(); recordLength = reader.ReadInt32(); perRecord = reader.ReadInt32(); stringBlockLength = reader.ReadInt32(); if (format != DbcFileFormat.Dbc) { hashTable = reader.ReadInt32(); build = reader.ReadInt32(); _lastWrittenTimestamp = reader.ReadInt32(); minID = reader.ReadInt32(); maxID = reader.ReadInt32(); locale = reader.ReadInt32(); unknown = reader.ReadInt32(); if (maxID != 0) { lookupID = headerLength; headerLength = headerLength + (maxID - minID + 1) * 6; } } else { hashTable = 0; build = -1; _lastWrittenTimestamp = 0; minID = -1; maxID = -1; locale = 0; } stringBlockOffset = perRecord * count + headerLength; }
public DbcTable(Stream storage, bool ownsStorage = true) { if (storage == null) throw new ArgumentNullException("storage"); if (!storage.CanSeek || !storage.CanRead) throw new ArgumentException("storage"); _store = storage; _ownsStream = ownsStorage; _store.Seek(0, SeekOrigin.Begin); _reader = new BinaryReader(storage, Encoding.UTF8, true); int magic = _reader.ReadInt32(); if (magic == 0x43424457) { _format = DbcFileFormat.Dbc; _headerLength = HEADER_LENGTH_DBC; } else if (magic == 0x32424457) { _format = DbcFileFormat.Db2; _headerLength = HEADER_LENGTH_DB2; } else if (magic == 0x32484357) { _format = DbcFileFormat.AdbCache; _headerLength = HEADER_LENGTH_DB2; } else { throw new InvalidDataException("Invalid header."); } _count = _reader.ReadInt32(); _recordLength = _reader.ReadInt32(); _perRecord = _reader.ReadInt32(); _stringBlockLength = _reader.ReadInt32(); if (_format != DbcFileFormat.Dbc) { _tableHash = _reader.ReadInt32(); _build = _reader.ReadInt32(); _lastWrittenTimestamp = _reader.ReadInt32(); _minId = _reader.ReadInt32(); _maxId = _reader.ReadInt32(); _locale = _reader.ReadInt32(); _reader.ReadInt32(); if (_maxId != 0) { _idLookup = _headerLength; int numRows = _maxId - _minId + 1; _headerLength = _headerLength + numRows * 6; } } else { _tableHash = 0; _build = -1; _lastWrittenTimestamp = 0; _minId = -1; _maxId = -1; _locale = 0; } _stringBlockOffset = _perRecord * _count + _headerLength; }
public DbcTable(Stream storage, bool ownsStorage = true) { if (storage == null) { throw new ArgumentNullException("storage"); } if (!storage.CanSeek || !storage.CanRead) { throw new ArgumentException("storage"); } _store = storage; _ownsStream = ownsStorage; _store.Seek(0, SeekOrigin.Begin); _reader = new BinaryReader(storage, Encoding.UTF8, true); int magic = _reader.ReadInt32(); if (magic == 0x43424457) { _format = DbcFileFormat.Dbc; _headerLength = HEADER_LENGTH_DBC; } else if (magic == 0x32424457) { _format = DbcFileFormat.Db2; _headerLength = HEADER_LENGTH_DB2; } else if (magic == 0x32484357) { _format = DbcFileFormat.AdbCache; _headerLength = HEADER_LENGTH_DB2; } else { throw new InvalidDataException("Invalid header."); } _count = _reader.ReadInt32(); _recordLength = _reader.ReadInt32(); _perRecord = _reader.ReadInt32(); _stringBlockLength = _reader.ReadInt32(); if (_format != DbcFileFormat.Dbc) { _tableHash = _reader.ReadInt32(); _build = _reader.ReadInt32(); _lastWrittenTimestamp = _reader.ReadInt32(); _minId = _reader.ReadInt32(); _maxId = _reader.ReadInt32(); _locale = _reader.ReadInt32(); _reader.ReadInt32(); if (_maxId != 0) { _idLookup = _headerLength; int numRows = _maxId - _minId + 1; _headerLength = _headerLength + numRows * 6; } } else { _tableHash = 0; _build = -1; _lastWrittenTimestamp = 0; _minId = -1; _maxId = -1; _locale = 0; } _stringBlockOffset = _perRecord * _count + _headerLength; }