MCPcopy
hub / github.com/tinylib/msgp / ReadArray

Function ReadArray

msgp/iter.go:18–40  ·  view source on GitHub ↗

ReadArray 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. The returned iterator implements the iter.Seq[V] interface, allowing for sequ

(m *Reader, readFn func() (T, error))

Source from the content-addressed store, hash-verified

16// allowing for sequential access to the array elements.
17// The iterator will always stop after one error has been encountered.
18func ReadArray[T any](m *Reader, readFn func() (T, error)) iter.Seq2[T, error] {
19 return func(yield func(T, error) bool) {
20 // Check if nil
21 if m.IsNil() {
22 m.ReadNil()
23 return
24 }
25 // Regular array.
26 var empty T
27 length, err := m.ReadArrayHeader()
28 if err != nil {
29 yield(empty, fmt.Errorf("cannot read array header: %w", err))
30 return
31 }
32 for range length {
33 var v T
34 v, err = readFn()
35 if !yield(v, err) || err != nil {
36 return
37 }
38 }
39 }
40}
41
42// WriteArray writes an array to the provided Writer.
43// The writeFn parameter specifies the function to use to write each element of the array.

Callers 12

FuzzReaderFunction · 0.85
ExampleReadArrayFunction · 0.85
ExampleWriteArrayFunction · 0.85
ExampleReadArray_structFunction · 0.85
TestReadNumberArray_IntFunction · 0.85
TestReadArray_StringFunction · 0.85
TestReadArray_BoolFunction · 0.85

Calls 3

IsNilMethod · 0.80
ReadNilMethod · 0.80
ReadArrayHeaderMethod · 0.80

Tested by 12

FuzzReaderFunction · 0.68
ExampleReadArrayFunction · 0.68
ExampleWriteArrayFunction · 0.68
ExampleReadArray_structFunction · 0.68
TestReadNumberArray_IntFunction · 0.68
TestReadArray_StringFunction · 0.68
TestReadArray_BoolFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…