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

Function ExampleWriteArray

msgp/iter_test.go:43–67  ·  view source on GitHub ↗

Example: Writing and array with WriteArray, then reading back using ReadArray with a *Reader. It prints each element in order.

()

Source from the content-addressed store, hash-verified

41// then reading back using ReadArray with a *Reader.
42// It prints each element in order.
43func 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.

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…