message-size-increase #3

Open
sashakoshka wants to merge 75 commits from message-size-increase into main
Showing only changes of commit 3a88619f9b - Show all commits

View File

@ -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 }