consensus/utils/json.go

29 lines
726 B
Go
Raw Normal View History

2023-05-27 12:43:22 +00:00
package utils
import (
gojson "git.gammaspectra.live/P2Pool/go-json"
2023-05-27 12:43:22 +00:00
"io"
)
var JsonEncodeOptions = []gojson.EncodeOptionFunc{gojson.DisableHTMLEscape(), gojson.DisableNormalizeUTF8()}
2023-05-27 12:43:22 +00:00
func MarshalJSON(val any) ([]byte, error) {
return gojson.MarshalWithOption(val, JsonEncodeOptions...)
2023-05-27 12:43:22 +00:00
}
func MarshalJSONIndent(val any, indent string) ([]byte, error) {
return gojson.MarshalIndentWithOption(val, "", indent, JsonEncodeOptions...)
2023-05-27 12:43:22 +00:00
}
func UnmarshalJSON(data []byte, val any) error {
return gojson.UnmarshalWithOption(data, val)
2023-05-27 12:43:22 +00:00
}
func NewJSONEncoder(writer io.Writer) *gojson.Encoder {
return gojson.NewEncoder(writer)
2023-05-27 12:43:22 +00:00
}
func NewJSONDecoder(reader io.Reader) *gojson.Decoder {
return gojson.NewDecoder(reader)
2023-05-27 12:43:22 +00:00
}