MCPcopy
hub / github.com/tinylib/msgp / ExampleReadArray

Function ExampleReadArray

msgp/iter_test.go:14–38  ·  view source on GitHub ↗

Example: reading an array of ints using ReadArray with a *Reader. It prints each element in order.

()

Source from the content-addressed store, hash-verified

12// Example: reading an array of ints using ReadArray with a *Reader.
13// It prints each element in order.
14func ExampleReadArray() {
15 var buf bytes.Buffer
16 w := NewWriter(&buf)
17
18 // Write an array [10, 20, 30] using WriteArray
19 _ = WriteArray(w, []int{10, 20, 30}, w.WriteInt)
20 _ = w.Flush()
21
22 r := NewReader(&buf)
23
24 seq := ReadArray(r, r.ReadInt)
25 seq(func(v int, err error) bool {
26 if err != nil {
27 fmt.Println("err:", err)
28 return false
29 }
30 fmt.Println(v)
31 return true
32 })
33
34 // Output:
35 // 10
36 // 20
37 // 30
38}
39
40// Example: Writing and array with WriteArray,
41// then reading back using ReadArray with a *Reader.

Callers

nothing calls this directly

Calls 5

FlushMethod · 0.95
NewWriterFunction · 0.85
WriteArrayFunction · 0.85
NewReaderFunction · 0.85
ReadArrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…