Example: Writing and array with WriteArray, then reading back using ReadArray with a *Reader. It prints each element in order.
()
| 41 | // then reading back using ReadArray with a *Reader. |
| 42 | // It prints each element in order. |
| 43 | func ExampleWriteArray() { |
| 44 | var buf bytes.Buffer |
| 45 | w := NewWriter(&buf) |
| 46 | |
| 47 | // Write an array [10, 20, 30] using WriteArray |
| 48 | _ = WriteArray(w, []int8{10, 20, 30}, w.WriteInt8) |
| 49 | _ = w.Flush() |
| 50 | |
| 51 | r := NewReader(&buf) |
| 52 | |
| 53 | seq := ReadArray(r, r.ReadInt) |
| 54 | seq(func(v int, err error) bool { |
| 55 | if err != nil { |
| 56 | fmt.Println("err:", err) |
| 57 | return false |
| 58 | } |
| 59 | fmt.Println(v) |
| 60 | return true |
| 61 | }) |
| 62 | |
| 63 | // Output: |
| 64 | // 10 |
| 65 | // 20 |
| 66 | // 30 |
| 67 | } |
| 68 | |
| 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…