Example: reading a map[string]float64 from a byte slice using ReadMapBytes. It prints key=value pairs and then checks the remaining bytes/error from the returned closure.
()
| 142 | // Example: reading a map[string]float64 from a byte slice using ReadMapBytes. |
| 143 | // It prints key=value pairs and then checks the remaining bytes/error from the returned closure. |
| 144 | func ExampleReadMapBytes() { |
| 145 | var b []byte |
| 146 | // Append {"pi":3.14, "e":2.718} using AppendMap - we use the sorted version for the example |
| 147 | b = AppendMapSorted(b, map[string]float64{"pi": 3.14, "e": 2.718}, AppendString, AppendFloat64) |
| 148 | |
| 149 | seq, finish := ReadMapBytes(b, ReadStringBytes, ReadFloat64Bytes) |
| 150 | seq(func(k string, v float64) bool { |
| 151 | fmt.Printf("%s=%.3f\n", k, v) |
| 152 | return true |
| 153 | }) |
| 154 | if _, err := finish(); err != nil { |
| 155 | fmt.Println("err:", err) |
| 156 | } |
| 157 | |
| 158 | // Output: |
| 159 | // e=2.718 |
| 160 | // pi=3.140 |
| 161 | } |
| 162 | |
| 163 | // Example: slice roundtrip with struct elements using WriteArray/ReadArray. |
| 164 | // Uses testDec as the element type, with EncoderTo/DecoderFrom helpers. |
nothing calls this directly
no test coverage detected
searching dependent graphs…