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

Function ExampleAppendMap

msgp/iter_test.go:280–298  ·  view source on GitHub ↗

Example: appending a map to a byte slice using AppendMap (non-sorted). Uses a single-entry map to keep output deterministic. Use AppendMapSorted to write a sorted map.

()

Source from the content-addressed store, hash-verified

278// Uses a single-entry map to keep output deterministic.
279// Use AppendMapSorted to write a sorted map.
280func ExampleAppendMap() {
281 var b []byte
282
283 // Append {"only":1} using AppendMap
284 b = AppendMap(b, map[string]int{"only": 1}, AppendString, AppendInt)
285
286 // Read back and print
287 seq, finish := ReadMapBytes(b, ReadStringBytes, ReadIntBytes)
288 seq(func(k string, v int) bool {
289 fmt.Printf("%s=%d\n", k, v)
290 return true
291 })
292 if _, err := finish(); err != nil {
293 fmt.Println("err:", err)
294 }
295
296 // Output:
297 // only=1
298}
299
300var nilMsg = AppendNil(nil)
301

Callers

nothing calls this directly

Calls 2

AppendMapFunction · 0.85
ReadMapBytesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…