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

Function ReadMap

msgp/iter.go:74–106  ·  view source on GitHub ↗

ReadMap returns an iterator that can be used to iterate over the elements of a map in the MessagePack data while being read by the provided Reader. The type parameters K and V specify the types of the keys and values in the map. The returned iterator implements the iter.Seq2[K, V] interface, allowin

(m *Reader, readKey func() (K, error), readVal func() (V, error))

Source from the content-addressed store, hash-verified

72// The returned function can be used to read any error that
73// occurred during iteration when iteration is done.
74func ReadMap[K, V any](m *Reader, readKey func() (K, error), readVal func() (V, error)) (iter.Seq2[K, V], func() error) {
75 var err error
76 return func(yield func(K, V) bool) {
77 var sz uint32
78 if m.IsNil() {
79 err = m.ReadNil()
80 return
81 }
82 sz, err = m.ReadMapHeader()
83 if err != nil {
84 err = fmt.Errorf("cannot read map header: %w", err)
85 return
86 }
87
88 for range sz {
89 var k K
90 k, err = readKey()
91 if err != nil {
92 err = fmt.Errorf("cannot read key: %w", err)
93 return
94 }
95 var v V
96 v, err = readVal()
97 if err != nil {
98 err = fmt.Errorf("cannot read value: %w", err)
99 return
100 }
101 if !yield(k, v) {
102 return
103 }
104 }
105 }, func() error { return err }
106}
107
108// WriteMap writes a map to the provided Writer.
109// The writeKey and writeVal parameters specify the functions

Callers 6

FuzzReaderFunction · 0.85
ExampleReadMapFunction · 0.85
ExampleWriteMapFunction · 0.85
ExampleReadMap_structFunction · 0.85

Calls 3

IsNilMethod · 0.80
ReadNilMethod · 0.80
ReadMapHeaderMethod · 0.80

Tested by 6

FuzzReaderFunction · 0.68
ExampleReadMapFunction · 0.68
ExampleWriteMapFunction · 0.68
ExampleReadMap_structFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…