Example: slice roundtrip with struct elements using WriteArray/ReadArray. Uses testDec as the element type, with EncoderTo/DecoderFrom helpers.
()
| 163 | // Example: slice roundtrip with struct elements using WriteArray/ReadArray. |
| 164 | // Uses testDec as the element type, with EncoderTo/DecoderFrom helpers. |
| 165 | func ExampleReadArray_struct() { |
| 166 | var buf bytes.Buffer |
| 167 | w := NewWriter(&buf) |
| 168 | |
| 169 | in := []testDec{{A: 1, B: "x"}, {A: 2, B: "y"}} |
| 170 | // Write []testDec using EncoderTo as the per-element writer. |
| 171 | _ = WriteArray(w, in, EncoderTo(w, testDec{})) |
| 172 | _ = w.Flush() |
| 173 | |
| 174 | r := NewReader(&buf) |
| 175 | // Read []testDec using DecoderFrom as the per-element reader. |
| 176 | seq := ReadArray(r, DecoderFrom(r, testDec{})) |
| 177 | |
| 178 | seq(func(v testDec, err error) bool { |
| 179 | if err != nil { |
| 180 | fmt.Println("err:", err) |
| 181 | return false |
| 182 | } |
| 183 | fmt.Printf("%d %s\n", v.A, v.B) |
| 184 | return true |
| 185 | }) |
| 186 | |
| 187 | // Output: |
| 188 | // 1 x |
| 189 | // 2 y |
| 190 | } |
| 191 | |
| 192 | // Example: map roundtrip with struct values using WriteMapSorted/ReadMap. |
| 193 | // Uses testDec as the value type and sorts keys for deterministic output. |
nothing calls this directly
no test coverage detected
searching dependent graphs…