From 3a88619f9b7f2b43bd5bf62c19b4250da4b3dcd2 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 18 May 2025 16:12:55 -0400 Subject: [PATCH] tape: Add back iter compatibility for table decoding --- tape/table.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 }