MCPcopy Create free account
hub / github.com/francoispqt/gojay / ExampleDecodeArrayFunc

Function ExampleDecodeArrayFunc

decode_example_test.go:80–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

78}
79
80func ExampleDecodeArrayFunc() {
81 reader := strings.NewReader(`[
82 "foo",
83 "bar"
84 ]`)
85 dec := gojay.NewDecoder(reader)
86
87 strSlice := make([]string, 0)
88 err := dec.DecodeArray(gojay.DecodeArrayFunc(func(dec *gojay.Decoder) error {
89 var str string
90 if err := dec.AddString(&str); err != nil {
91 return err
92 }
93 strSlice = append(strSlice, str)
94 return nil
95 }))
96
97 if err != nil {
98 log.Fatal(err)
99 }
100
101 fmt.Print(strSlice)
102 // Output:
103 // [foo bar]
104}
105
106func ExampleNewDecoder() {
107 reader := strings.NewReader(`"gojay"`)

Callers

nothing calls this directly

Calls 4

DecodeArrayMethod · 0.95
AddStringMethod · 0.95
NewDecoderFunction · 0.92
DecodeArrayFuncFuncType · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…