/// <summary> /// Create a PropertyStoreDataBlock from a given byte array /// </summary> /// <param name="ba">The byte array</param> /// <returns>A PropertyStoreDataBlock object</returns> public static PropertyStoreDataBlock FromByteArray(byte[] ba) { PropertyStoreDataBlock PropertyStoreDataBlock = new PropertyStoreDataBlock(); if (ba.Length < 0xC) { throw new ArgumentException(String.Format("Size of the PropertyStoreDataBlock Structure is less than 12 ({0})", ba.Length)); } UInt32 BlockSize = BitConverter.ToUInt32(ba, 0); if (BlockSize > ba.Length) { throw new ArgumentException(String.Format("BlockSize is {0} is incorrect (expected {1})", BlockSize, PropertyStoreDataBlock.BlockSize)); } BlockSignature BlockSignature = (BlockSignature)BitConverter.ToUInt32(ba, 4); if (BlockSignature != PropertyStoreDataBlock.BlockSignature) { throw new ArgumentException(String.Format("BlockSignature is {0} is incorrect (expected {1})", BlockSignature, PropertyStoreDataBlock.BlockSignature)); } byte[] data = new byte[BlockSize - 4]; Buffer.BlockCopy(BitConverter.GetBytes(BlockSize - 4), 0, data, 0, 4); Buffer.BlockCopy(ba, 8, data, 4, (int)BlockSize - 8); SerializedPropertyStore SerializedPropertyStore = SerializedPropertyStore.FromByteArray(data); PropertyStoreDataBlock.PropertyStore = SerializedPropertyStore.PropertyStorage; return(PropertyStoreDataBlock); }
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); }
public static bool WriteTo([NotNull] this SerializedPropertyStore obj, BinaryWriter writer) { throw new NotImplementedException(); }