ReadArrayBytes returns an iterator that can be used to iterate over the elements of an array in the MessagePack data while being read by the provided Reader. The type parameter V specifies the type of the elements in the array. After the iterator is exhausted, the remaining bytes in the buffer and a
(b []byte, readFn func([]byte) (T, []byte, error))
| 173 | // After the iterator is exhausted, the remaining bytes in the buffer |
| 174 | // and any error can be read by calling the returned function. |
| 175 | func ReadArrayBytes[T any](b []byte, readFn func([]byte) (T, []byte, error)) (iter.Seq[T], func() (remain []byte, err error)) { |
| 176 | if IsNil(b) { |
| 177 | b, err := ReadNilBytes(b) |
| 178 | return func(yield func(T) bool) {}, func() ([]byte, error) { return b, err } |
| 179 | } |
| 180 | sz, b, err := ReadArrayHeaderBytes(b) |
| 181 | if err != nil || sz == 0 { |
| 182 | return func(yield func(T) bool) {}, func() ([]byte, error) { return b, err } |
| 183 | } |
| 184 | return func(yield func(T) bool) { |
| 185 | for range sz { |
| 186 | var v T |
| 187 | v, b, err = readFn(b) |
| 188 | if err != nil || !yield(v) { |
| 189 | return |
| 190 | } |
| 191 | } |
| 192 | }, func() ([]byte, error) { |
| 193 | return b, err |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // AppendArray writes an array to the provided buffer. |
| 198 | // The writeFn parameter specifies the function to use to write each element of the array. |
searching dependent graphs…