Skip to content

Commit

Permalink
fix: make GenericMessage iterator work reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Jan 22, 2025
1 parent ddb9db3 commit e899ed6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/msg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,18 @@ Base.length(s::GenericMessage) = fieldcount(typeof(s)) - 1 + length(s.__data__)

function Base.iterate(s::GenericMessage)
f = keys(s)
fiter = iterate(f)
fiter === nothing && return nothing
v = values(s)
(f[1] => v[1], (f[2:end], v[2:end]))
(fiter[1] => first(v), (fiter[2], 2))
end

function Base.iterate(s::GenericMessage, (fstate, vndx))
f = keys(s)
fiter = iterate(f, fstate)
fiter === nothing && return nothing
v = values(s)
(fiter[1] => v[vndx], (fiter[2], vndx+1))
end

"""
Expand Down

0 comments on commit e899ed6

Please sign in to comment.