Skip to content

Commit

Permalink
delegate sonic
Browse files Browse the repository at this point in the history
  • Loading branch information
day253 committed Oct 19, 2024
1 parent faa4c0a commit 43ecf99
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
6 changes: 3 additions & 3 deletions objects/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/bytedance/sonic"
json "github.com/bytedance/sonic"
)

var (
Expand Down Expand Up @@ -69,7 +69,7 @@ func M(keyAndValuePairs ...interface{}) Map {
// NewMapFromJSON creates a new map from a JSON string representation
func NewMapFromJSON(data string) (Map, error) {
var unmarshalled map[string]interface{}
err := sonic.Unmarshal([]byte(data), &unmarshalled)
err := json.Unmarshal([]byte(data), &unmarshalled)
if err != nil {
return nil, errors.New("Map: JSON decode failed with: " + err.Error())
}
Expand Down Expand Up @@ -253,7 +253,7 @@ func (d Map) MSI() map[string]interface{} {

// JSON converts the map to a JSON string
func (d Map) JSON() (string, error) {
result, err := sonic.Marshal(d)
result, err := json.Marshal(d)
if err != nil {
err = errors.New("Map: JSON encode failed with: " + err.Error())
}
Expand Down
9 changes: 2 additions & 7 deletions objects/sonic.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
//go:build go1.18
// +build go1.18

package objects

import (
"encoding/json"

"github.com/bytedance/sonic"
json "github.com/bytedance/sonic"
)

func String[T any](t T) string {
return string(Bytes(t))
}

func Bytes[T any](t T) []byte {
result, _ := sonic.Marshal(t)
result, _ := json.Marshal(t)
return result
}

Expand Down
3 changes: 2 additions & 1 deletion registry-zookeeper/entity.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package registry_zookeeper

import (
"encoding/json"
"os"
"strconv"

json "github.com/bytedance/sonic"
)

type serversetEndpoint struct {
Expand Down
3 changes: 2 additions & 1 deletion registry-zookeeper/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package registry_zookeeper

import (
"context"
"encoding/json"
"fmt"
"net"
"strings"
"time"

json "github.com/bytedance/sonic"

"github.com/cloudwego/kitex/pkg/discovery"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/go-zookeeper/zk"
Expand Down

0 comments on commit 43ecf99

Please sign in to comment.