MCPcopy Index your code
hub / github.com/vmihailenco/msgpack / ExampleDecoder_Query

Function ExampleDecoder_Query

example_test.go:94–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

92}
93
94func ExampleDecoder_Query() {
95 b, err := msgpack.Marshal([]map[string]interface{}{
96 {"id": 1, "attrs": map[string]interface{}{"phone": 12345}},
97 {"id": 2, "attrs": map[string]interface{}{"phone": 54321}},
98 })
99 if err != nil {
100 panic(err)
101 }
102
103 dec := msgpack.NewDecoder(bytes.NewBuffer(b))
104 values, err := dec.Query("*.attrs.phone")
105 if err != nil {
106 panic(err)
107 }
108 fmt.Println("phones are", values)
109
110 dec.Reset(bytes.NewBuffer(b))
111 values, err = dec.Query("1.attrs.phone")
112 if err != nil {
113 panic(err)
114 }
115 fmt.Println("2nd phone is", values[0])
116 // Output: phones are [12345 54321]
117 // 2nd phone is 54321
118}
119
120func ExampleEncoder_UseArrayEncodedStructs() {
121 type Item struct {

Callers

nothing calls this directly

Calls 2

QueryMethod · 0.95
ResetMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…