public void Read(ref Buffer buffer) { DataType type = (DataType)buffer.ReadBytesByte(); Debug.Assert(type == DataType.DATA_ARRAY); name = buffer.ReadBytesString(); dataType = (DataType)buffer.ReadBytesByte(); count = (uint)buffer.ReadBytesInt32(); if (data != null) { data = null; } if (dataType != DataType.DATA_STRING) { data = new byte[count * SizeOf(dataType)]; System.Array.Copy(buffer.Data, buffer.Position, data, 0, count * SizeOf(dataType)); buffer.AddOffset(count * SizeOf(dataType)); } else { uint start = buffer.Position; for (uint i = 0; i < count; i++) { buffer.ReadBytesString(); } size = buffer.Position - start; data = new byte[size]; System.Array.Copy(buffer.Data, start, data, 0, size); } }
public void Read(ref Buffer buffer) { version = (Global.Version)buffer.ReadBytesShort(); if (version == Global.Version.VERSION_INVALID) { throw new ArgumentOutOfRangeException("version", "Invalid database version!"); } if (version > Global.Version.VERSION_LATEST) { throw new ArgumentOutOfRangeException("version", "Unsupported version!"); } switch (version) { case Global.Version.VERSION_1_0: name = buffer.ReadBytesString(); buffer.AddOffset(sizeof(uint)); //we skip the size (don't need it) ushort objectCount = (ushort)buffer.ReadBytesShort(); for (ushort i = 0; i < objectCount; i++) { Object obj = new Object(); obj.Read(ref buffer); AddObject(obj); } break; case Global.Version.VERSION_2_0: name = buffer.ReadBytesString(); uint checksum = (uint)buffer.ReadBytesInt32(); uint p = buffer.Position; uint size = (uint)buffer.ReadBytesInt32() - sizeof(short) - sizeof(short) - (uint)name.Length - sizeof(uint); if (crc32(buffer.Data, p, size) != checksum) { throw new ArgumentOutOfRangeException("crc32", "Checksum mismatch!"); } // objectCount already defined in case VERSION_1_0 objectCount = (ushort)buffer.ReadBytesShort(); for (ushort i = 0; i < objectCount; i++) { Object obj = new Object(); obj.Read(ref buffer); AddObject(obj); } break; default: throw new ArgumentOutOfRangeException("version", "Invalid database version!"); } }