good morning!!!!

Skip to content
Snippets Groups Projects
Commit 00dadb46 authored by a's avatar a
Browse files

more json iter

parent 1c88d0e7
Branches
Tags
No related merge requests found
...@@ -242,8 +242,8 @@ func newHTTPServerConn(r *http.Request, w http.ResponseWriter) ServerCodec { ...@@ -242,8 +242,8 @@ func newHTTPServerConn(r *http.Request, w http.ResponseWriter) ServerCodec {
param = pb param = pb
} }
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
buf.Grow(64) buf.Grow(128)
json.NewEncoder(buf).Encode(jsonrpcMessage{ jzon.NewEncoder(buf).Encode(jsonrpcMessage{
ID: NewStringIDPtr(id), ID: NewStringIDPtr(id),
Method: method_up, Method: method_up,
Params: param, Params: param,
......
...@@ -31,6 +31,8 @@ import ( ...@@ -31,6 +31,8 @@ import (
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
) )
var jzon = jsoniter.ConfigCompatibleWithStandardLibrary
const ( const (
vsn = "2.0" vsn = "2.0"
serviceMethodSeparator = "_" serviceMethodSeparator = "_"
...@@ -92,7 +94,7 @@ func (msg *jsonrpcMessage) namespace() string { ...@@ -92,7 +94,7 @@ func (msg *jsonrpcMessage) namespace() string {
} }
func (msg *jsonrpcMessage) String() string { func (msg *jsonrpcMessage) String() string {
b, _ := jsoniter.Marshal(msg) b, _ := jzon.Marshal(msg)
return string(b) return string(b)
} }
...@@ -106,7 +108,7 @@ func (msg *jsonrpcMessage) errorResponse(err error) *jsonrpcMessage { ...@@ -106,7 +108,7 @@ func (msg *jsonrpcMessage) errorResponse(err error) *jsonrpcMessage {
func (msg *jsonrpcMessage) response(result any) *jsonrpcMessage { func (msg *jsonrpcMessage) response(result any) *jsonrpcMessage {
// do a funny marshaling // do a funny marshaling
enc, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(result) enc, err := jzon.Marshal(result)
if err != nil { if err != nil {
return msg.errorResponse(err) return msg.errorResponse(err)
} }
...@@ -203,8 +205,8 @@ func NewFuncCodec(conn deadlineCloser, encode, decode func(v any) error) ServerC ...@@ -203,8 +205,8 @@ func NewFuncCodec(conn deadlineCloser, encode, decode func(v any) error) ServerC
// NewCodec creates a codec on the given connection. If conn implements ConnRemoteAddr, log // NewCodec creates a codec on the given connection. If conn implements ConnRemoteAddr, log
// messages will use it to include the remote address of the connection. // messages will use it to include the remote address of the connection.
func NewCodec(conn Conn) ServerCodec { func NewCodec(conn Conn) ServerCodec {
enc := json.NewEncoder(conn) enc := jzon.NewEncoder(conn)
dec := json.NewDecoder(conn) dec := jzon.NewDecoder(conn)
dec.UseNumber() dec.UseNumber()
return NewFuncCodec(conn, enc.Encode, dec.Decode) return NewFuncCodec(conn, enc.Encode, dec.Decode)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment