diff --git a/codex/erasure.nim b/codex/erasure.nim index 5dfebcd4..03955f4a 100644 --- a/codex/erasure.nim +++ b/codex/erasure.nim @@ -8,18 +8,5 @@ ## those terms. import ./erasure/erasure -import ./erasure/backends/leopard export erasure - -func leoEncoderProvider*( - size, buffers, parity: int -): EncoderBackend {.raises: [Defect].} = - ## create new Leo Encoder - LeoEncoderBackend.new(size, buffers, parity) - -func leoDecoderProvider*( - size, buffers, parity: int -): DecoderBackend {.raises: [Defect].} = - ## create new Leo Decoder - LeoDecoderBackend.new(size, buffers, parity) diff --git a/codex/erasure/asyncbackend.nim b/codex/erasure/asyncbackend.nim index 4827806a..f40942b6 100644 --- a/codex/erasure/asyncbackend.nim +++ b/codex/erasure/asyncbackend.nim @@ -14,6 +14,7 @@ import pkg/taskpools/flowvars import pkg/chronos import pkg/chronos/threadsync import pkg/questionable/results +import pkg/leopard import ./backend import ../errors @@ -29,169 +30,109 @@ const type EncoderBackendPtr = ptr EncoderBackend DecoderBackendPtr = ptr DecoderBackend + DecoderPtr = ptr LeoDecoder + EncoderPtr = ptr LeoEncoder # Args objects are missing seq[seq[byte]] field, to avoid unnecessary data copy EncodeTaskArgs = object signal: ThreadSignalPtr - backend: EncoderBackendPtr - blockSize: int - ecM: int + encoder: EncoderPtr DecodeTaskArgs = object signal: ThreadSignalPtr - backend: DecoderBackendPtr - blockSize: int - ecK: int + decoder: DecoderPtr SharedArrayHolder*[T] = object data: ptr UncheckedArray[T] size: int - EncodeTaskResult = Result[SharedArrayHolder[byte], cstring] - DecodeTaskResult = Result[SharedArrayHolder[byte], cstring] - -proc encodeTask(args: EncodeTaskArgs, data: seq[seq[byte]]): EncodeTaskResult = - var - data = data.unsafeAddr - parity = newSeqWith[seq[byte]](args.ecM, newSeq[byte](args.blockSize)) + TaskResult = Result[void, cstring] +proc encodeTask(args: EncodeTaskArgs): TaskResult = try: - let res = args.backend[].encode(data[], parity) - - if res.isOk: - let - resDataSize = parity.len * args.blockSize - resData = cast[ptr UncheckedArray[byte]](allocShared0(resDataSize)) - arrHolder = SharedArrayHolder[byte]( - data: resData, - size: resDataSize - ) - - for i in 0..