public void Read(ref Buffer buffer) { byte type = buffer.ReadBytesByte(); Debug.Assert(type == (byte)Global.DataType.DATA_FIELD); string sname = buffer.ReadBytesString(); DataType dataType = (DataType)buffer.ReadBytesByte(); switch (dataType) { case DataType.DATA_BOOL: SetData(dataType, buffer.ReadBytesBool(), sname); break; case DataType.DATA_CHAR: SetData <byte>(dataType, buffer.ReadBytesByte(), sname); break; case DataType.DATA_SHORT: SetData <short>(dataType, buffer.ReadBytesShort(), sname); break; case DataType.DATA_INT: SetData <int>(dataType, buffer.ReadBytesInt32(), sname); break; case DataType.DATA_LONG_LONG: SetData <Int64> (dataType, (long)buffer.ReadBytesInt64(), sname); break; case DataType.DATA_FLOAT: SetData(dataType, buffer.ReadBytesFloat(), sname); break; case DataType.DATA_DOUBLE: SetData(dataType, buffer.ReadBytesDouble(), sname); break; case DataType.DATA_STRING: SetData(dataType, buffer.ReadBytesString(), sname); break; default: throw new ArgumentOutOfRangeException("dataType", "Invalid data type!"); } }
public void Read(ref Buffer buffer) { byte type = buffer.ReadBytesByte(); Debug.Assert(type == (byte)Global.DataType.DATA_OBJECT); name = buffer.ReadBytesString(); ushort fieldCount = (ushort)buffer.ReadBytesShort(); for (int i = 0; i < fieldCount; i++) { Field field = new Field(); field.Read(ref buffer); AddField(field); } ushort arrayCount = (ushort)buffer.ReadBytesShort(); for (int i = 0; i < arrayCount; i++) { Array array = new Array(); array.Read(ref buffer); AddArray(array); } }
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!"); } }