/// <summary> /// Unpack or read the contents of this object from a Binary Reader. /// </summary> /// <param name="parent"></param> /// <param name="reader"></param> public override void Unpack(IInternalPersistent parent, System.IO.BinaryReader reader) { DataIsUserDefined = false; bool?r = CollectionOnDisk.ReadPersistentData(parent, reader, ref Data); if (r == null) { DataIsUserDefined = true; } else if (!r.Value) { Data = null; } }
/// <summary> /// Unpack this item for DeSerialization from Stream /// </summary> /// <param name="parent"></param> /// <param name="reader"></param> public virtual void Unpack(IInternalPersistent parent, System.IO.BinaryReader reader) { bool?r = CollectionOnDisk.ReadPersistentData(parent, reader, ref Key); if (r == null) { if (((BTreeAlgorithm)parent).onKeyUnpack != null) { Key = ((BTreeAlgorithm)parent).onKeyUnpack(reader); } else { throw new SopException("Can't Deserialize Custom persisted 'Key'."); } } if (Value == null) { var f = (File.File)InternalPersistent.GetParent(parent, typeof(File.File)); Value = new ItemOnDisk(f.DataBlockSize); } bool valueIsReference = reader.ReadBoolean(); if (valueIsReference) { Value.DiskBuffer.DataAddress = reader.ReadInt64(); } else { object o = Value; CollectionOnDisk.ReadPersistentData(parent, reader, ref o); Value = (ItemOnDisk)o; if (Value.DataIsUserDefined && ((BTreeAlgorithm)parent).onValueUnpack != null) { Value.Data = ((BTreeAlgorithm)parent).onValueUnpack(reader); } } IsDirty = false; }
/// <summary> /// Unpack Deserializes Node from Stream /// </summary> /// <param name="parent"></param> /// <param name="reader"></param> public void Unpack(IInternalPersistent parent, System.IO.BinaryReader reader) { Count = reader.ReadInt16(); HintSizeOnDisk = reader.ReadInt32(); ParentAddress = reader.ReadInt64(); if (Slots == null) { Slots = new BTreeItemOnDisk[((BTreeAlgorithm)parent).SlotLength]; } if (ChildrenAddresses == null) { ChildrenAddresses = new long[Slots.Length + 1]; ResetArray(ChildrenAddresses, -1); } short newCount = 0; for (int i = 0; i <= Slots.Length; i++) { ChildrenAddresses[i] = reader.ReadInt64(); if (ChildrenAddresses[i] != -1) { newCount++; } } if (ChildrenAddresses[0] == -1L) { ChildrenAddresses = null; } else if (newCount > 0 && Count != newCount - 1) { Count = (short)(newCount - 1); } for (int i = 0; i < Count; i++) { Slots[i] = new BTreeItemOnDisk(); object key = null; int vn = reader.ReadInt32(); Slots[i].VersionNumber = vn; if (Slots[i].Key is IPersistentVersioned) { ((IPersistentVersioned)Slots[i].Key).VersionNumber = Slots[i].VersionNumber; } // read key from disk CollectionOnDisk.ReadPersistentData(parent, reader, ref key); if (key == null) { if (((BTreeAlgorithm)parent).onKeyUnpack != null) { key = ((BTreeAlgorithm)parent).onKeyUnpack(reader); } if (key == null) { if (i == 0) { ((BTreeAlgorithm)parent).RootNeedsReload = true; return; } throw new InvalidOperationException( "Can't DeSerialize Key, ensure there is a TypeStore Entry for this data type."); } } Slots[i].Key = key; Slots[i].Value = new ItemOnDisk(); if (((BTreeAlgorithm)parent).IsDataInKeySegment) { if (((BTreeAlgorithm)parent).IsDataLongInt) { long l = reader.ReadInt64(); Slots[i].Value.Data = l; } else { if (((BTreeAlgorithm)parent).PersistenceType == PersistenceType.Unknown) { throw new InvalidOperationException("Parent BTreeAlgorithm PersistenceType is unknown."); } // write the value and keep track of its data size and location in the disk buffer. long startPos = reader.BaseStream.Position; if (CollectionOnDisk.ReadPersistentData(parent, reader, ref Slots[i].Value.Data, ItemType.Value) == null) { ((BTreeAlgorithm)parent).ValueUnpack(reader, Slots[i]); } Slots[i].HintSizeOnDisk = (int)(reader.BaseStream.Position - startPos); } Slots[i].ValueLoaded = true; Slots[i].Value.IsDirty = false; } else { // read Address of Value in Data Segment long l = reader.ReadInt64(); Slots[i].Value.DiskBuffer = ((BTreeAlgorithm)parent).CreateBlock(); // new Sop.DataBlock((DataBlockSize) parent.DiskBuffer.Length); ((CollectionOnDisk)parent).SetIsDirty(Slots[i].Value.DiskBuffer, false); Slots[i].ValueLoaded = false; ((BTreeAlgorithm)parent).DataBlockDriver.SetId(Slots[i].Value.DiskBuffer, l); Slots[i].Value.DiskBuffer.contiguousBlockCount = reader.ReadUInt16(); } } }