Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Loads additional numRows into the storage.
- /// </summary>
- /// <param name="numRows">Number of rows to load</param>
- private void LoadRows(uint numRows)
- {
- // rowsLoaded records are already loaded, so skip those + header (=20)
- binReader.BaseStream.Position = 20 + rowsLoaded * recordSize;
- for (int i = 0; i < (int)numRows; ++i)
- {
- // read the full record as plain bytes
- byte[] curData = binReader.ReadBytes((int)recordSize);
- // a collection of untyped values
- List<object> curRecord = new List<object>();
- for (int j = 0; j < (int)numFields; ++j)
- {
- object value = null;
- // Get the guessed format for the current field
- Type type = formatGuesser.GetFormat((int)j);
- // Float and int are simple. Just convert to single/int32
- if (type == typeof(float))
- value = (object)BitConverter.ToSingle(curData, j * 4);
- else if (type == typeof(int))
- value = (object)BitConverter.ToInt32(curData, j * 4);
- // string is also not really complex. Should reference into the stringtable
- else if (type == typeof(string))
- {
- // tmp should now be the offset in bytes into the stringtable
- int tmp = BitConverter.ToInt32(curData, j * 4);
- // if its not in the stringtable its an invalid string. This may happen
- if (stringList.ContainsKey((uint)tmp))
- {
- // get the hash of the string
- uint hash = (uint)(stringList[(uint)tmp].GetHashCode());
- // increase the internal references on that string (which is used when a string is modified)
- // if the string modified is referenced more than once a new string has to be made
- ++stringReferences[hash];
- value = (object)stringList[(uint)tmp];
- }
- else
- value = (object)"";
- }
- // StringBuilder is the dummytype for empty localized fields
- else if (type == typeof(StringBuilder))
- {
- value = (object)new StringBuilder("");
- }
- // decimal is the dummytype for the last field in licalized strings (the bitmask)
- else if (type == typeof(decimal))
- {
- uint val = BitConverter.ToUInt32(curData, j * 4);
- decimal dec = (decimal)val;
- value = (object)dec;
- }
- curRecord.Add(value);
- }
- if (RecordLoaded != null)
- RecordLoaded((uint)i, numRows);
- recordList.Add(curRecord);
- }
- rowsLoaded += numRows;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement