/// <summary> /// Read header data from byte[] buffer into local variables /// using fixed position be be faster than use BufferReader /// </summary> public BasePage(PageBuffer buffer) { _buffer = buffer; // page information this.PageID = _buffer.ReadUInt32(P_PAGE_ID); this.PageType = (PageType)_buffer.ReadByte(P_PAGE_TYPE); this.PrevPageID = _buffer.ReadUInt32(P_PREV_PAGE_ID); this.NextPageID = _buffer.ReadUInt32(P_NEXT_PAGE_ID); // transaction information this.TransactionID = _buffer.ReadUInt32(P_TRANSACTION_ID); this.IsConfirmed = _buffer.ReadBool(P_IS_CONFIRMED); this.ColID = _buffer.ReadUInt32(P_COL_ID); // blocks information this.ItemsCount = _buffer.ReadByte(P_ITEMS_COUNT); this.UsedBytes = _buffer.ReadUInt16(P_USED_BYTES); this.FragmentedBytes = _buffer.ReadUInt16(P_FRAGMENTED_BYTES); this.NextFreePosition = _buffer.ReadUInt16(P_NEXT_FREE_POSITION); this.HighestIndex = _buffer.ReadByte(P_HIGHEST_INDEX); }
/// <summary> /// Get a page segment item based on index slot /// </summary> public BufferSlice Get(byte index) { ENSURE(index < byte.MaxValue, "slot index must be between 0-254"); // read slot address var positionAddr = CalcPositionAddr(index); var lengthAddr = CalcLengthAddr(index); // read segment position/length var position = _buffer.ReadUInt16(positionAddr); var length = _buffer.ReadUInt16(lengthAddr); ENSURE(this.IsValidPos(position), "invalid segment position"); ENSURE(this.IsValidLen(length), "invalid segment length"); // return buffer slice with content only data return(_buffer.Slice(position, length)); }
/// <summary> /// Get a page segment item based on index slot /// </summary> public BufferSlice Get(byte index) { ENSURE(this.ItemsCount > 0, "should have items in this page"); ENSURE(this.HighestIndex != byte.MaxValue, "should be have at least 1 index in this page"); ENSURE(index <= this.HighestIndex, "get only index below highest index"); // read slot address var positionAddr = CalcPositionAddr(index); var lengthAddr = CalcLengthAddr(index); // read segment position/length var position = _buffer.ReadUInt16(positionAddr); var length = _buffer.ReadUInt16(lengthAddr); ENSURE(this.IsValidPos(position), "invalid segment position"); ENSURE(this.IsValidLen(length), "invalid segment length"); // return buffer slice with content only data return(_buffer.Slice(position, length)); }