diff --git a/tape/table.go b/tape/table.go index 8bd85dc..aa8f412 100644 --- a/tape/table.go +++ b/tape/table.go @@ -1,5 +1,7 @@ package tape +import "iter" + // encoding and decoding functions must not make any allocations type TablePushFunc func(tag uint16, value []byte) (n int, err error) @@ -22,6 +24,17 @@ func DecodeTable(data []byte) TablePullFunc { } } +func DecodeTableIter(data []byte) iter.Seq2[uint16, []byte] { + return func(yield func(uint16, []byte) bool) { + pull := DecodeTable(data) + for { + tag, value, _, err := pull() + if err != nil { return } + if !yield(tag, value) { return } + } + } +} + func EncodeTable(data []byte) TablePushFunc { return func(tag uint16, value []byte) (n int, err error) { if n >= len(data) { return n, ErrWrongBufferLength }