-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathmsgpack_document.go
More file actions
41 lines (32 loc) · 1.18 KB
/
msgpack_document.go
File metadata and controls
41 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package xpath
import (
"bytes"
"fmt"
"github.com/antchfx/jsonquery"
path "github.com/antchfx/xpath"
"github.com/tinylib/msgp/msgp"
)
type msgpackDocument jsonDocument
func (*msgpackDocument) Parse(buf []byte) (dataNode, error) {
var json bytes.Buffer
// Unmarshal the message-pack binary message to JSON and proceed with the jsonquery class
if _, err := msgp.UnmarshalAsJSON(&json, buf); err != nil {
return nil, fmt.Errorf("unmarshalling to json failed: %w", err)
}
return jsonquery.Parse(&json)
}
func (d *msgpackDocument) QueryAll(node dataNode, expr string) ([]dataNode, error) {
return (*jsonDocument)(d).QueryAll(node, expr)
}
func (d *msgpackDocument) CreateXPathNavigator(node dataNode) path.NodeNavigator {
return (*jsonDocument)(d).CreateXPathNavigator(node)
}
func (d *msgpackDocument) GetNodePath(node, relativeTo dataNode, sep string) string {
return (*jsonDocument)(d).GetNodePath(node, relativeTo, sep)
}
func (d *msgpackDocument) GetNodeName(node dataNode, sep string, withParent bool) string {
return (*jsonDocument)(d).GetNodeName(node, sep, withParent)
}
func (d *msgpackDocument) OutputXML(node dataNode) string {
return (*jsonDocument)(d).OutputXML(node)
}