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

Function WriteMap

msgp/iter.go:111–136  ·  view source on GitHub ↗

WriteMap writes a map to the provided Writer. The writeKey and writeVal parameters specify the functions to use to write each key and value of the map.

(w *Writer, m map[K]V, writeKey func(K) error, writeVal func(V) error)

Source from the content-addressed store, hash-verified

109// The writeKey and writeVal parameters specify the functions
110// to use to write each key and value of the map.
111func WriteMap[K comparable, V any](w *Writer, m map[K]V, writeKey func(K) error, writeVal func(V) error) error {
112 if m == nil {
113 return w.WriteNil()
114 }
115 if uint64(len(m)) > math.MaxUint32 {
116 return fmt.Errorf("map too large to encode: %d elements", len(m))
117 }
118
119 // Write map header
120 err := w.WriteMapHeader(uint32(len(m)))
121 if err != nil {
122 return err
123 }
124 // Write elements
125 for k, v := range m {
126 err = writeKey(k)
127 if err != nil {
128 return err
129 }
130 err = writeVal(v)
131 if err != nil {
132 return err
133 }
134 }
135 return nil
136}
137
138// WriteMapSorted writes a map to the provided Writer.
139// The keys of the map are sorted before writing.

Callers 1

ExampleWriteMapFunction · 0.85

Calls 2

WriteNilMethod · 0.80
WriteMapHeaderMethod · 0.80

Tested by 1

ExampleWriteMapFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…