introduce Encoding object

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-11-22 14:37:07 +01:00
parent 41c78b8d98
commit 41a5fa1348
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E

View File

@ -29,6 +29,11 @@ import ./types
export types export types
type type
Encoding = object
ecK: int # Number of blocks to encode
ecM: int # Number of resulting parity blocks
interleave: int # How far apart are blocks of an erasure code according to original index
Manifest* = ref object of RootObj Manifest* = ref 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
@ -38,9 +43,7 @@ type
codec: MultiCodec # Data set codec codec: MultiCodec # Data set codec
case protected {.serialize.}: bool # Protected datasets have erasure coded info case protected {.serialize.}: bool # Protected datasets have erasure coded info
of true: of true:
ecK: int # Number of blocks to encode code: Encoding # Parameters of the RS code applied
ecM: int # Number of resulting parity blocks
interleave: int # How far apart are blocks of an erasure code according to original index
originalManifest: Manifest # The original Manifest being erasure coded originalManifest: Manifest # The original Manifest being erasure coded
else: else:
discard discard
@ -68,13 +71,13 @@ proc protected*(self: Manifest): bool =
self.protected self.protected
proc ecK*(self: Manifest): int = proc ecK*(self: Manifest): int =
self.ecK self.code.ecK
proc ecM*(self: Manifest): int = proc ecM*(self: Manifest): int =
self.ecM self.code.ecM
proc interleave*(self: Manifest): int = proc interleave*(self: Manifest): int =
self.interleave self.code.interleave
proc originalManifest*(self: Manifest): Manifest = proc originalManifest*(self: Manifest): Manifest =
self.originalManifest self.originalManifest
@ -247,8 +250,10 @@ proc new*(
hcodec: manifest.hcodec, hcodec: manifest.hcodec,
blockSize: manifest.blockSize, blockSize: manifest.blockSize,
protected: true, protected: true,
ecK: ecK, ecM: ecM, code: Encoding(
interleave: interleave, ecK: ecK,
ecM: ecM,
interleave: interleave),
originalManifest: manifest) originalManifest: manifest)
proc new*( proc new*(
@ -290,8 +295,9 @@ proc new*(
hcodec: hcodec, hcodec: hcodec,
codec: codec, codec: codec,
protected: true, protected: true,
ecK: ecK, code: Encoding(
ecM: ecM, ecK: ecK,
interleave: interleave, ecM: ecM,
interleave: interleave),
originalManifest: originalManifest originalManifest: originalManifest
) )