Skip to content

Commit

Permalink
export api
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed May 19, 2024
1 parent 006fefc commit 0caaf9d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dev/ast/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/bytedance/sonic/internal/native"
"github.com/bytedance/sonic/internal/native/types"
"github.com/bytedance/sonic/internal/rt"
"github.com/davecgh/go-spew/spew"
)

Expand Down Expand Up @@ -101,3 +102,14 @@ func (self *Parser) skip() (int, types.ParsingError) {
return start, 0
}

func Get(src []byte, path ...interface{}) (Node, error) {
node, err := parseLazy(rt.Mem2Str(src), &path)
// NOTICE: always copy JSON string to avoid memory leak
r := node
r.node.JSON = rt.Mem2Str([]byte(node.node.JSON))
return node, err
}

func GetFromString(src string, path ...interface{}) (Node, error) {
return parseLazy(src, &path)
}

0 comments on commit 0caaf9d

Please sign in to comment.