Example: reading a map[string]int using ReadMap with a *Reader. It prints key=value pairs in the same order they were written.
()
| 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. |
| 71 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…