mirror of
https://github.com/logos-storage/nim-poseidon2.git
synced 2026-01-03 06:03:10 +00:00
fix empty seq support
This commit is contained in:
parent
7be0e6dfe7
commit
59f7b0545e
@ -27,13 +27,14 @@ iterator elements*(bytes: openArray[byte], _: type F): F =
|
||||
## sequences that end with 0x0's.
|
||||
const chunkLen = 31
|
||||
const endMarker = @[1'u8]
|
||||
let empty = bytes.len == 0
|
||||
var chunkStart = 0
|
||||
while chunkStart + chunkLen <= bytes.len:
|
||||
let chunkEnd = chunkStart + chunkLen - 1
|
||||
let element = F.fromOpenArray(bytes.toOpenArray(chunkStart, chunkEnd))
|
||||
yield element
|
||||
chunkStart += chunkLen
|
||||
if bytes.len - chunkStart > 0:
|
||||
if (bytes.len - chunkStart > 0) or empty:
|
||||
let finalChunk = bytes[chunkStart..<bytes.len] & endMarker
|
||||
let finalElement = F.fromOpenArray(finalChunk)
|
||||
yield finalElement
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user