Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
27
backend/internal/util/gjson.go
Normal file
27
backend/internal/util/gjson.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// GetGJSONBytesNoCopy returns a GJSON result that may reference data directly.
|
||||
// Callers must not retain the result or mutate data while using it.
|
||||
func GetGJSONBytesNoCopy(data []byte, path string) gjson.Result {
|
||||
if len(data) == 0 {
|
||||
return gjson.Result{}
|
||||
}
|
||||
return gjson.Get(unsafe.String(unsafe.SliceData(data), len(data)), path)
|
||||
}
|
||||
|
||||
// ParseGJSONBytesNoCopy parses data into a GJSON result that references data
|
||||
// directly. gjson.ParseBytes copies the whole document, which is prohibitive
|
||||
// for multi-megabyte payloads. Callers must not retain the result or mutate
|
||||
// data while using it.
|
||||
func ParseGJSONBytesNoCopy(data []byte) gjson.Result {
|
||||
if len(data) == 0 {
|
||||
return gjson.Result{}
|
||||
}
|
||||
return gjson.Parse(unsafe.String(unsafe.SliceData(data), len(data)))
|
||||
}
|
||||
Loading…
Reference in a new issue