/// <summary>
        /// Create a LinkTargetIDList from a given byte array
        /// </summary>
        /// <param name="ba">The byte array</param>
        /// <returns>A LinkTargetIDList object</returns>
        public static SerializedPropertyStore FromByteArray(byte[] ba)
        {
            SerializedPropertyStore PropertyStore = new SerializedPropertyStore();

            if (ba.Length < 8)
            {
                throw new ArgumentException(String.Format("Size of the SerializedPropertyStore is less than 8 ({0})", ba.Length));
            }

            UInt32 StoreSize = BitConverter.ToUInt32(ba, 0);

            if (ba.Length < StoreSize)
            {
                throw new ArgumentException(String.Format("Size of the SerializedPropertyStore is less than {0} ({1})", StoreSize, ba.Length));
            }

            ba = ba.Skip(4).ToArray();
            UInt32 StorageSize = BitConverter.ToUInt32(ba, 0);

            while (StorageSize > 5)
            {
                SerializedPropertyStorage PropertyStorage = SerializedPropertyStorage.FromByteArray(ba);
                PropertyStore.PropertyStorage.Add(PropertyStorage);
                ba          = ba.Skip((int)StorageSize).ToArray();
                StorageSize = BitConverter.ToUInt32(ba, 0);
            }

            return(PropertyStore);
        }
        /// <inheritdoc />
        public override byte[] GetBytes()
        {
            int Offset = 4;

            byte[] PropertyStore = new byte[StoreSize];
            Buffer.BlockCopy(BitConverter.GetBytes(StoreSize), 0, PropertyStore, 0, 4);
            for (int i = 0; i < this.PropertyStorage.Count; i++)
            {
                SerializedPropertyStorage PropertyStorage = this.PropertyStorage[i];
                Buffer.BlockCopy(PropertyStorage.GetBytes(), 0, PropertyStore, Offset, (int)PropertyStorage.StorageSize);
                Offset += (int)PropertyStorage.StorageSize;
            }
            return(PropertyStore);
        }
Пример #3
0
        public static bool Load([NotNull] this SerializedPropertyStorage obj, BinaryReader reader)
        {
            obj.StorageSize = reader.ReadInt32();

            if (obj.StorageSize == 0)
            {
                return(true);
            }

            obj.Version  = reader.ReadInt32();
            obj.FormatID = reader.ReadGuid();

            var ok = true;

            while (true)
            {
                // TODO
                // Error tolerance:
                //  To be error tolerant, we will behave as if the binary sequence
                // was a string and we were to apply the following regex:
                //      ^(ByName|ById)*$
                // This means that we will backtrack to try to find alternatives.

                // At this moment what we have is:
                // - No backtracking
                // - Test by name, and if it fails, read by id

                var namedValue = new SerializedPropertyValueByName();
                var ok2        = namedValue.Load(reader);
                SerializedPropertyValue value = namedValue;
                if (!ok2)
                {
                    var identifiedValue = new SerializedPropertyValueById();
                    ok2   = identifiedValue.Load(reader);
                    value = identifiedValue;
                }

                ok &= ok2;

                obj.SerializedPropertyValues.Add(value);

                if (value.ValueSize == 0)
                {
                    break;
                }
            }

            return(ok);
        }
Пример #4
0
        /// <inheritdoc />
        public override byte[] GetBytes()
        {
            int Offset = 8;

            byte[] PropertyStoreDataBlock = new byte[BlockSize];
            Buffer.BlockCopy(BitConverter.GetBytes(BlockSize), 0, PropertyStoreDataBlock, 0, 4);
            Buffer.BlockCopy(BitConverter.GetBytes((UInt32)BlockSignature), 0, PropertyStoreDataBlock, 4, 4);
            for (int i = 0; i < PropertyStore.Count; i++)
            {
                SerializedPropertyStorage PropertyStorage = PropertyStore[i];
                Buffer.BlockCopy(PropertyStorage.GetBytes(), 0, PropertyStoreDataBlock, Offset, (int)PropertyStorage.StorageSize);
                Offset += (int)PropertyStorage.StorageSize;
            }
            return(PropertyStoreDataBlock);
        }
Пример #5
0
        public static bool Load([NotNull] this SerializedPropertyStore obj, BinaryReader reader)
        {
            var ok = true;

            obj.StoreSize = reader.ReadInt32();

            while (true)
            {
                var storage = new SerializedPropertyStorage();

                ok &= storage.Load(reader);

                obj.SerializedPropertyStorages.Add(storage);

                if (storage.StorageSize == 0)
                {
                    break;
                }
            }

            return(ok);
        }
Пример #6
0
 public static bool WriteTo([NotNull] this SerializedPropertyStorage obj, BinaryWriter writer)
 {
     throw new NotImplementedException();
 }