| 92 | } |
| 93 | |
| 94 | func 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 | |
| 120 | func ExampleEncoder_UseArrayEncodedStructs() { |
| 121 | type Item struct { |