Skip to content

Commit

Permalink
调整sonic的使用
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Nov 29, 2024
1 parent a7f3f80 commit 152a8ce
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"sync"

"github.com/bytedance/sonic"
"github.com/farseer-go/fs/snc"
)

// Dictionary 字典
Expand Down Expand Up @@ -79,7 +79,7 @@ func (receiver *Dictionary[TKey, TValue]) Scan(val any) error {
// UnmarshalJSON to deserialize []byte
func (receiver *Dictionary[TKey, TValue]) UnmarshalJSON(ba []byte) error {
t := map[TKey]TValue{}
err := sonic.Unmarshal(ba, &t)
err := snc.Unmarshal(ba, &t)
*receiver = NewDictionaryFromMap(t)
return err
}
Expand Down
6 changes: 3 additions & 3 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"sync"

"github.com/bytedance/sonic"
"github.com/farseer-go/fs/parse"
"github.com/farseer-go/fs/snc"
)

// List 集合
Expand Down Expand Up @@ -109,7 +109,7 @@ func (receiver List[T]) MarshalJSON() ([]byte, error) {
}
receiver.lock.RLock()
defer receiver.lock.RUnlock()
return sonic.Marshal(receiver.source)
return snc.Marshal(receiver.source)
}

// UnmarshalJSON to deserialize []byte
Expand All @@ -119,7 +119,7 @@ func (receiver *List[T]) UnmarshalJSON(b []byte) error {
}
receiver.lock.RLock()
defer receiver.lock.RUnlock()
return sonic.Unmarshal(b, receiver.source)
return snc.Unmarshal(b, receiver.source)
}

// GormDataType gorm common data type
Expand Down
4 changes: 2 additions & 2 deletions readonlyDictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"database/sql/driver"
"sync"

"github.com/bytedance/sonic"
"github.com/farseer-go/fs/parse"
"github.com/farseer-go/fs/snc"
)

// ReadonlyDictionary 只读字典
Expand Down Expand Up @@ -143,7 +143,7 @@ func (receiver ReadonlyDictionary[TKey, TValue]) MarshalJSON() ([]byte, error) {
return []byte("{}"), nil
}

return sonic.Marshal(receiver.ToMap())
return snc.Marshal(receiver.ToMap())
}

// GormDataType gorm common data type
Expand Down
4 changes: 2 additions & 2 deletions test/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package test
import (
"testing"

"github.com/bytedance/sonic"
"github.com/farseer-go/collections"
"github.com/farseer-go/fs/snc"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -78,7 +78,7 @@ func Test_collection_RemoveAll(t *testing.T) {
func TestCollection_MarshalJSON(t *testing.T) {
lst := collections.NewList[int](1, 2, 3, 6)
strjson, _ := lst.MarshalJSON()
retjson, _ := sonic.Marshal(lst)
retjson, _ := snc.Marshal(lst)
assert.Equal(t, retjson, strjson)
}

Expand Down
6 changes: 3 additions & 3 deletions test/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"testing"

"github.com/bytedance/sonic"
"github.com/farseer-go/collections"
"github.com/farseer-go/fs/snc"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -212,10 +212,10 @@ func TestDictionary_IsNil(t *testing.T) {
func TestDictionaryJson(t *testing.T) {
var dic collections.Dictionary[int, int]
assert.True(t, dic.IsNil())
marshal, _ := sonic.Marshal(dic)
marshal, _ := snc.Marshal(dic)
assert.Equal(t, "{}", string(marshal))

_ = sonic.Unmarshal([]byte("{}"), &dic)
_ = snc.Unmarshal([]byte("{}"), &dic)
assert.False(t, dic.IsNil())
}

Expand Down
6 changes: 3 additions & 3 deletions test/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"reflect"
"testing"

"github.com/bytedance/sonic"
"github.com/farseer-go/collections"
"github.com/farseer-go/fs/snc"
"github.com/farseer-go/fs/types"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -101,10 +101,10 @@ func TestNil(t *testing.T) {

func TestListJson(t *testing.T) {
var lst collections.List[int]
marshal, _ := sonic.Marshal(lst)
marshal, _ := snc.Marshal(lst)
assert.Equal(t, "[]", string(marshal))

_ = sonic.Unmarshal([]byte("[]"), &lst)
_ = snc.Unmarshal([]byte("[]"), &lst)
assert.False(t, lst.IsNil())
}

Expand Down

0 comments on commit 152a8ce

Please sign in to comment.