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

Function ExampleWriteMap

msgp/iter_test.go:98–118  ·  view source on GitHub ↗

Example: writing a map using WriteMap (non-sorted). Uses a single-entry map to keep output deterministic. Use WriteMapSorted to write a sorted map.

()

Source from the content-addressed store, hash-verified

96// Uses a single-entry map to keep output deterministic.
97// Use WriteMapSorted to write a sorted map.
98func ExampleWriteMap() {
99 var buf bytes.Buffer
100 w := NewWriter(&buf)
101
102 // Write a map {"only":1} using WriteMap
103 _ = WriteMap(w, map[string]int{"only": 1}, w.WriteString, w.WriteInt)
104 _ = w.Flush()
105
106 r := NewReader(&buf)
107 seq, done := ReadMap(r, r.ReadString, r.ReadInt)
108 seq(func(k string, v int) bool {
109 fmt.Printf("%s=%d\n", k, v)
110 return true
111 })
112 if err := done(); err != nil {
113 fmt.Println("err:", err)
114 }
115
116 // Output:
117 // only=1
118}
119
120// Example: reading an array of strings from a byte slice using ReadArrayBytes.
121// It prints each element and then checks for a final error from the returned closure.

Callers

nothing calls this directly

Calls 5

FlushMethod · 0.95
NewWriterFunction · 0.85
WriteMapFunction · 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…