MCPcopy Index your code
hub / github.com/tinylib/msgp / AppendMap

Function AppendMap

msgp/iter.go:258–273  ·  view source on GitHub ↗

AppendMap writes a map to the provided buffer. The writeK and writeV parameters specify the functions to use to write each key and value of the map. The returned buffer contains the encoded map. The function panics if the map is larger than math.MaxUint32 elements.

(b []byte, m map[K]V,
	writeK func(b []byte, k K) []byte,
	writeV func(b []byte, v V) []byte)

Source from the content-addressed store, hash-verified

256// The returned buffer contains the encoded map.
257// The function panics if the map is larger than math.MaxUint32 elements.
258func AppendMap[K comparable, V any](b []byte, m map[K]V,
259 writeK func(b []byte, k K) []byte,
260 writeV func(b []byte, v V) []byte) []byte {
261 if m == nil {
262 return AppendNil(b)
263 }
264 if uint64(len(m)) > math.MaxUint32 {
265 panic(fmt.Sprintf("map too large to encode: %d elements", len(m)))
266 }
267 b = AppendMapHeader(b, uint32(len(m)))
268 for k, v := range m {
269 b = writeK(b, k)
270 b = writeV(b, v)
271 }
272 return b
273}
274
275// AppendMapSorted writes a map to the provided buffer.
276// Keys are sorted before writing.

Callers 1

ExampleAppendMapFunction · 0.85

Calls 2

AppendNilFunction · 0.85
AppendMapHeaderFunction · 0.85

Tested by 1

ExampleAppendMapFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…