Block and manifest as objects (#708)

* make block and manifest objects

* use unsafeAddr since block is an object type now

* make object var
This commit is contained in:
Dmitriy Ryajov 2024-02-18 20:10:16 -06:00 committed by GitHub
parent 61ec4275c8
commit 3fce267352
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 11 deletions

View File

@ -31,7 +31,7 @@ import ./codextypes
export errors, logutils, units, codextypes
type
Block* = ref object of RootObj
Block* = object of RootObj
cid*: Cid
data*: seq[byte]
@ -90,8 +90,7 @@ func new*(
data: openArray[byte] = [],
version = CIDv1,
mcodec = Sha256HashCodec,
codec = BlockCodec
): ?!Block =
codec = BlockCodec): ?!Block =
## creates a new block for both storage and network IO
##

View File

@ -29,7 +29,7 @@ import ../logutils
# TODO: Manifest should be reworked to more concrete types,
# perhaps using inheritance
type
Manifest* = ref object of RootObj
Manifest* = object of RootObj
treeCid {.serialize.}: Cid # Root of the merkle tree
datasetSize {.serialize.}: NBytes # Total size of all blocks
blockSize {.serialize.}: NBytes # Size of each contained block (might not be needed if blocks are len-prefixed)
@ -148,7 +148,7 @@ func rounded*(self: Manifest): int =
func steps*(self: Manifest): int =
## Number of EC groups in *protected* manifest
divUp(self.originalBlocksCount, self.ecK)
divUp(self.rounded, self.ecK)
func verify*(self: Manifest): ?!void =
## Check manifest correctness

View File

@ -110,7 +110,7 @@ method readOnce*(
if blk.isEmpty:
zeroMem(pbytes.offset(read), readBytes)
else:
copyMem(pbytes.offset(read), blk.data[blockOffset].addr, readBytes)
copyMem(pbytes.offset(read), blk.data[blockOffset].unsafeAddr, readBytes)
# Update current positions in the stream and outbuf
self.offset += readBytes

View File

@ -331,8 +331,8 @@ suite "Slot builder":
protectedManifest,
cellSize = cellSize).tryGet()
var
verifyManifest = (await builder.buildManifest()).tryGet()
offset = verifyManifest.verifyRoot.data.buffer.len div 2
rng.shuffle(
Rng.instance,