Example: slice roundtrip with struct elements in a byte slice using AppendArray/ReadArrayBytes. Uses testDec as the element type, with EncoderToBytes/DecoderFromBytes helpers.
()
| 223 | // Example: slice roundtrip with struct elements in a byte slice using AppendArray/ReadArrayBytes. |
| 224 | // Uses testDec as the element type, with EncoderToBytes/DecoderFromBytes helpers. |
| 225 | func ExampleReadArrayBytes_struct() { |
| 226 | in := []testDec{{A: 1, B: "x"}, {A: 2, B: "y"}} |
| 227 | var b []byte |
| 228 | |
| 229 | // Append []testDec using EncoderToBytes as the per-element appender. |
| 230 | b = AppendArray(b, in, EncoderToBytes(testDec{})) |
| 231 | |
| 232 | // Read back using DecoderFromBytes as the per-element reader. |
| 233 | seq, finish := ReadArrayBytes(b, DecoderFromBytes(testDec{})) |
| 234 | |
| 235 | seq(func(v testDec) bool { |
| 236 | fmt.Printf("%d %s\n", v.A, v.B) |
| 237 | return true |
| 238 | }) |
| 239 | if _, err := finish(); err != nil { |
| 240 | fmt.Println("err:", err) |
| 241 | } |
| 242 | |
| 243 | // Output: |
| 244 | // 1 x |
| 245 | // 2 y |
| 246 | } |
| 247 | |
| 248 | // Example: map roundtrip with struct values in a byte slice using AppendMapSorted/ReadMapBytes. |
| 249 | // Uses testDec as the value type and sorts keys for deterministic output. |
nothing calls this directly
no test coverage detected
searching dependent graphs…