Skip to content

Commit

Permalink
modify api
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Aug 10, 2022
1 parent b8eaba9 commit f186daf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -25,8 +25,8 @@ CPU_avx2 := amd64
TMPL_avx := fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64
TMPL_avx2 := fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64

CFLAGS_avx := -msse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 -DDEBUG=1
CFLAGS_avx2 := -msse4 -mavx -mavx2 -DUSE_AVX=1 -DUSE_AVX2=1
CFLAGS_avx := -msse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0
CFLAGS_avx2 := -msse4 -mavx -mavx2 -DUSE_AVX=1 -DUSE_AVX2=1

CC_amd64 := clang
ASM2ASM_amd64 := tools/asm2asm/asm2asm.py
Expand Down
3 changes: 3 additions & 0 deletions api.go
Expand Up @@ -64,6 +64,9 @@ import (
// CopyString indicates decoder to decode string values by copying instead of referring.
CopyString bool

// ValidString indicates decoder to valid string values: decoder will return errors when
// invalid UTF-8 chars or unescaped control chars(\u0000-\u001f).
ValidString bool
}

var (
Expand Down
12 changes: 9 additions & 3 deletions sonic.go
Expand Up @@ -61,6 +61,8 @@ type frozenConfig struct {
// Froze convert the Config to API
func (cfg Config) Froze() API {
api := &frozenConfig{Config: cfg}

// configure encoder options:
if cfg.EscapeHTML {
api.encoderOpts |= encoder.EscapeHTML
}
Expand All @@ -73,6 +75,11 @@ func (cfg Config) Froze() API {
if cfg.NoQuoteTextMarshaler {
api.encoderOpts |= encoder.NoQuoteTextMarshaler
}
if cfg.NoNullSliceOrMap {
api.encoderOpts |= encoder.NoNullSliceOrMap
}

// configure decoder options:
if cfg.UseInt64 {
api.decoderOpts |= decoder.OptionUseInt64
}
Expand All @@ -85,8 +92,8 @@ func (cfg Config) Froze() API {
if cfg.CopyString {
api.decoderOpts |= decoder.OptionCopyString
}
if cfg.NoNullSliceOrMap {
api.encoderOpts |= encoder.NoNullSliceOrMap
if cfg.ValidString {
api.decoderOpts |= decoder.OptionValidateString
}
return api
}
Expand All @@ -111,7 +118,6 @@ func (cfg *frozenConfig) MarshalIndent(val interface{}, prefix, indent string) (
func (cfg *frozenConfig) UnmarshalFromString(buf string, val interface{}) error {
dec := decoder.NewDecoder(buf)
dec.SetOptions(cfg.decoderOpts)
dec.ValidString()
err := dec.Decode(val)
pos := dec.Pos()

Expand Down

0 comments on commit f186daf

Please sign in to comment.