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

Function ExampleReadMap

msgp/iter_test.go:71–93  ·  view source on GitHub ↗

Example: reading a map[string]int using ReadMap with a *Reader. It prints key=value pairs in the same order they were written.

()

Source from the content-addressed store, hash-verified

69// Example: reading a map[string]int using ReadMap with a *Reader.
70// It prints key=value pairs in the same order they were written.
71func ExampleReadMap() {
72 var buf bytes.Buffer
73 w := NewWriter(&buf)
74
75 // Write a map {"a":1, "b":2} using WriteMap - we use the sorted version so output is predictable.
76 _ = WriteMapSorted(w, map[string]int{"a": 1, "b": 2}, w.WriteString, w.WriteInt)
77 _ = w.Flush()
78
79 r := NewReader(&buf)
80
81 seq, done := ReadMap(r, r.ReadString, r.ReadInt)
82 seq(func(k string, v int) bool {
83 fmt.Printf("%s=%d\n", k, v)
84 return true
85 })
86 if err := done(); err != nil {
87 fmt.Println("err:", err)
88 }
89
90 // Output:
91 // a=1
92 // b=2
93}
94
95// Example: writing a map using WriteMap (non-sorted).
96// Uses a single-entry map to keep output deterministic.

Callers

nothing calls this directly

Calls 5

FlushMethod · 0.95
NewWriterFunction · 0.85
WriteMapSortedFunction · 0.85
NewReaderFunction · 0.85
ReadMapFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…