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.
()
| 278 | // Uses a single-entry map to keep output deterministic. |
| 279 | // Use AppendMapSorted to write a sorted map. |
| 280 | func 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 | |
| 300 | var nilMsg = AppendNil(nil) |
| 301 |
nothing calls this directly
no test coverage detected
searching dependent graphs…