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 export errors, logutils, units, codextypes
type type
Block* = ref object of RootObj Block* = object of RootObj
cid*: Cid cid*: Cid
data*: seq[byte] data*: seq[byte]
@ -86,12 +86,11 @@ proc `$`*(b: Block): string =
result &= "\ndata: " & string.fromBytes(b.data) result &= "\ndata: " & string.fromBytes(b.data)
func new*( func new*(
T: type Block, T: type Block,
data: openArray[byte] = [], data: openArray[byte] = [],
version = CIDv1, version = CIDv1,
mcodec = Sha256HashCodec, mcodec = Sha256HashCodec,
codec = BlockCodec codec = BlockCodec): ?!Block =
): ?!Block =
## creates a new block for both storage and network IO ## 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, # TODO: Manifest should be reworked to more concrete types,
# perhaps using inheritance # perhaps using inheritance
type type
Manifest* = ref object of RootObj Manifest* = object of RootObj
treeCid {.serialize.}: Cid # Root of the merkle tree treeCid {.serialize.}: Cid # Root of the merkle tree
datasetSize {.serialize.}: NBytes # Total size of all blocks 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) 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 = func steps*(self: Manifest): int =
## Number of EC groups in *protected* manifest ## Number of EC groups in *protected* manifest
divUp(self.originalBlocksCount, self.ecK) divUp(self.rounded, self.ecK)
func verify*(self: Manifest): ?!void = func verify*(self: Manifest): ?!void =
## Check manifest correctness ## Check manifest correctness

View File

@ -110,7 +110,7 @@ method readOnce*(
if blk.isEmpty: if blk.isEmpty:
zeroMem(pbytes.offset(read), readBytes) zeroMem(pbytes.offset(read), readBytes)
else: 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 # Update current positions in the stream and outbuf
self.offset += readBytes self.offset += readBytes

View File

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