public StoredItem(Network expectedNetwork, DiskBlockPos position) { #pragma warning disable CS0612 // Type or member is obsolete _Header = new StoredHeader(expectedNetwork); #pragma warning restore CS0612 // Type or member is obsolete _BlockPosition = position; }
public StoredItem(uint magic, T item, DiskBlockPos position) { _BlockPosition = position; _Item = item; _Header.Magic = magic; _Header.ItemSize = (uint)item.GetSerializedSize(); }
/// <summary> /// /// </summary> /// <param name="headersOnly"></param> /// <param name="blockStart">Inclusive block count</param> /// <param name="blockEnd">Exclusive block count</param> /// <returns></returns> public IEnumerable <StoredBlock> Enumerate(bool headersOnly, int blockCountStart, int count = 999999999) { int blockCount = 0; DiskBlockPos start = null; foreach (var block in Enumerate(true, null)) { if (blockCount == blockCountStart) { start = block.BlockPosition; } blockCount++; } if (start == null) { yield break; } int i = 0; #pragma warning disable CS0612 // Type or member is obsolete foreach (var result in Enumerate(headersOnly, new DiskBlockPosRange(start))) #pragma warning restore CS0612 // Type or member is obsolete { if (i >= count) { break; } yield return(result); i++; } }
protected override StoredBlock ReadStoredItem(Stream stream, DiskBlockPos pos) { StoredBlock block = new StoredBlock(Network, pos); block.ParseSkipBlockContent = headerOnly; block.ReadWrite(stream, false); return(block); }
protected DiskBlockPos SeekEnd(FileLock @lock) { if (_last != null) { return(_last); } _last = SeekEnd(); return(_last); }
protected override StoredItem <BlockUndo> CreateStoredItem(BlockUndo item, DiskBlockPos position) { var stored = new StoredItem <BlockUndo>(Network.Magic, item, position); stored.HasChecksum = true; if (item.CalculatedChecksum == null) { throw new InvalidOperationException("A block undo should have an calculated checksum with ComputeChecksum"); } stored.Checksum = item.CalculatedChecksum; return(stored); }
public DiskBlockPos Append(TItem item) { using (var @lock = CreateLock(FileLockType.ReadWrite)) { DiskBlockPos position = SeekEnd(@lock); if (position.Position > MaxFileSize) { position = new DiskBlockPos(position.File + 1, 0); } var stored = CreateStoredItem(item, position); Write(stored); position = new DiskBlockPos(position.File, position.Position + stored.GetStorageSize()); _last = position; return(stored.BlockPosition); } }
/// <summary> /// Represent a disk block range /// </summary> /// <param name="begin">Beginning of the range (included)</param> /// <param name="end">End of the range (excluded)</param> public DiskBlockPosRange(DiskBlockPos begin = null, DiskBlockPos end = null) { if (begin == null) { begin = DiskBlockPos.Begin; } if (end == null) { end = DiskBlockPos.End; } _Begin = begin; _End = end; if (end <= begin) { throw new ArgumentException("End should be more than begin"); } }
protected override StoredItem <BlockUndo> ReadStoredItem(System.IO.Stream stream, DiskBlockPos pos) { StoredItem <BlockUndo> item = new StoredItem <BlockUndo>(Network, pos); item.HasChecksum = true; item.ReadWrite(stream, false); item.Item.CalculatedChecksum = item.Checksum; return(item); }
protected abstract TStoredItem ReadStoredItem(Stream stream, DiskBlockPos pos);
protected abstract TStoredItem CreateStoredItem(TItem item, DiskBlockPos position);
public bool InRange(DiskBlockPos pos) { return(Begin <= pos && pos < End); }
public StoredBlock(uint magic, Block block, DiskBlockPos blockPosition) : base(magic, block, blockPosition) { }
public StoredBlock(Network expectedNetwork, DiskBlockPos position) : base(expectedNetwork, position) { }
protected override StoredBlock CreateStoredItem(Block item, DiskBlockPos position) { return(new StoredBlock(Network.Magic, item, position)); }