mirror of
https://github.com/logos-storage/nim-leopard.git
synced 2026-01-07 16:13:10 +00:00
[wip] can use object of CatchableError for LeopardError with workaround
This commit is contained in:
parent
26135f37e3
commit
4d8964e554
27
leopard.nim
27
leopard.nim
@ -47,20 +47,19 @@ type
|
|||||||
LeopardNeedMoreData = wrapper.LeopardNeedMoreData
|
LeopardNeedMoreData = wrapper.LeopardNeedMoreData
|
||||||
LeopardSuccess = wrapper.LeopardSuccess
|
LeopardSuccess = wrapper.LeopardSuccess
|
||||||
|
|
||||||
# Regardless of comment above, if LeopardError is `object of CatchableError`
|
LeopardError* = object of CatchableError
|
||||||
# there seems to be a weird edge case, possibly owing to the LeopardResult
|
|
||||||
# enum starting with a negative number, whereby there is a compile-time error
|
|
||||||
# on Linux and Windows (but not macOS) re: stew/results in the context of a
|
|
||||||
# nimbus-build-system project; that error is not encountered in a
|
|
||||||
# choosenim/nimble setup using Nim 1.2, 1.4, or 1.6.
|
|
||||||
LeopardError* = object # of CatchableError
|
|
||||||
code*: LeopardResult
|
code*: LeopardResult
|
||||||
msg*: string
|
|
||||||
|
|
||||||
ParityData* = Data
|
ParityData* = Data
|
||||||
|
|
||||||
ReedSolomonCode* = tuple[codeword, data, parity: uint] # symbol counts
|
ReedSolomonCode* = tuple[codeword, data, parity: uint] # symbol counts
|
||||||
|
|
||||||
|
# workaround for https://github.com/nim-lang/Nim/issues/19619
|
||||||
|
# necessary for use of nim-leopard in nimbus-build-system projects because nbs
|
||||||
|
# ships libbacktrace by default
|
||||||
|
proc `$`*(err: LeopardError): string {.noSideEffect.} =
|
||||||
|
$err
|
||||||
|
|
||||||
# https://github.com/catid/leopard/issues/12
|
# https://github.com/catid/leopard/issues/12
|
||||||
# https://www.cs.cmu.edu/~guyb/realworld/reedsolomon/reed_solomon_codes.html
|
# https://www.cs.cmu.edu/~guyb/realworld/reedsolomon/reed_solomon_codes.html
|
||||||
#
|
#
|
||||||
@ -70,12 +69,6 @@ type
|
|||||||
# data symbols = 239
|
# data symbols = 239
|
||||||
# parity symbols = 255 - 239 = 16
|
# parity symbols = 255 - 239 = 16
|
||||||
|
|
||||||
func isValid*(code: ReedSolomonCode): bool =
|
|
||||||
not ((code.codeword - code.data != code.parity) or
|
|
||||||
(code.parity > code.data) or (code.codeword < MinSymbols + 1) or
|
|
||||||
(code.data < MinSymbols) or (code.parity < MinSymbols) or
|
|
||||||
(code.codeword > MaxTotalSymbols))
|
|
||||||
|
|
||||||
proc RS*(codeword, data: Positive): ReedSolomonCode =
|
proc RS*(codeword, data: Positive): ReedSolomonCode =
|
||||||
var
|
var
|
||||||
parity = codeword - data
|
parity = codeword - data
|
||||||
@ -83,6 +76,12 @@ proc RS*(codeword, data: Positive): ReedSolomonCode =
|
|||||||
if parity < 0: parity = 0
|
if parity < 0: parity = 0
|
||||||
(codeword: codeword.uint, data: data.uint, parity: parity.uint)
|
(codeword: codeword.uint, data: data.uint, parity: parity.uint)
|
||||||
|
|
||||||
|
func isValid*(code: ReedSolomonCode): bool =
|
||||||
|
not ((code.codeword - code.data != code.parity) or
|
||||||
|
(code.parity > code.data) or (code.codeword < MinSymbols + 1) or
|
||||||
|
(code.data < MinSymbols) or (code.parity < MinSymbols) or
|
||||||
|
(code.codeword > MaxTotalSymbols))
|
||||||
|
|
||||||
when (NimMajor, NimMinor, NimPatch) < (1, 4, 0):
|
when (NimMajor, NimMinor, NimPatch) < (1, 4, 0):
|
||||||
const
|
const
|
||||||
header = "<stdlib.h>"
|
header = "<stdlib.h>"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user