Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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!");
            }
        }
Beispiel #3
0
        public void Read(ref Buffer buffer)
        {
            ushort magic = (ushort)buffer.ReadBytesShort();

            Debug.Assert(magic == Global.MAGIC_NUMBER);

            byte count = buffer.ReadBytesByte();

            List <uint> offsets = new List <uint>();

            for (byte i = 0; i < count; i++)
            {
                offsets.Add((uint)buffer.ReadBytesInt32());
            }

            foreach (uint offs in offsets)
            {
                Debug.Assert(buffer.Position == offs);

                buffer.Position = offs;

                Database db = new Database();

                db.Read(ref buffer);
                AddDatabase(db);
            }
        }
Beispiel #4
0
        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!");
            }
        }