public byte[] Get(int index) { AssertElementIndexIsValid(index); if (index >= GetNextIndex()) { throw new InvalidElementIndexException("index is outside the file"); } int byteIndex = GetByteIndex(index); return(_fileWithHeader.GetAmount(byteIndex, GetElementSize())); }
private static void GetPutArrayTestAssert(FileWithHeader fwh, int index, byte[] data) { int nextIndexBefore = fwh.GetNextIndex(); fwh.Put(index, data); if (index + data.Length >= nextIndexBefore) { Assert.AreEqual(index + data.Length, fwh.GetNextIndex()); } byte[] actual = fwh.GetAmount(index, data.Length); TestHelper.AssertByteArraysAreSame(data, actual); }
private PersistentHeapUsedSpace GetSpaceAt(int token) { int sizeIndex = token - PersistentHeapSpace.GetUserSizeSize(); byte[] sizeBytes = _file.GetAmount(sizeIndex, PersistentHeapSpace.GetUserSizeSize()); int userSize = PersistentHeapSpace.GetUserSize(sizeBytes); int fullLength = userSize + PersistentHeapSpace.GetUserSizeSize(); int endIndex = sizeIndex + fullLength - 1; byte[] data = _file.GetRange(sizeIndex + PersistentHeapSpace.GetUserSizeSize(), endIndex); //let PersistentHeapUsedSpace be default PersistentHeapUsedSpace usedSpace = new PersistentHeapUsedSpace(sizeIndex, endIndex, data); return(usedSpace); }