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:
parent
61ec4275c8
commit
3fce267352
|
@ -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]
|
||||
|
||||
|
@ -86,12 +86,11 @@ proc `$`*(b: Block): string =
|
|||
result &= "\ndata: " & string.fromBytes(b.data)
|
||||
|
||||
func new*(
|
||||
T: type Block,
|
||||
data: openArray[byte] = [],
|
||||
version = CIDv1,
|
||||
mcodec = Sha256HashCodec,
|
||||
codec = BlockCodec
|
||||
): ?!Block =
|
||||
T: type Block,
|
||||
data: openArray[byte] = [],
|
||||
version = CIDv1,
|
||||
mcodec = Sha256HashCodec,
|
||||
codec = BlockCodec): ?!Block =
|
||||
## creates a new block for both storage and network IO
|
||||
##
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue