Skip to content

Commit

Permalink
perf: use kitex BinaryProtocol replace apache BinaryProtocol for buff…
Browse files Browse the repository at this point in the history
…ered protocol
  • Loading branch information
YangruiEmma committed Aug 16, 2024
1 parent bf81229 commit 2daa371
Show file tree
Hide file tree
Showing 8 changed files with 590 additions and 509 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/cloudwego/dynamicgo v0.3.0
github.com/cloudwego/fastpb v0.0.4
github.com/cloudwego/frugal v0.2.0
github.com/cloudwego/gopkg v0.1.1-0.20240812141034-843ef58f1234
github.com/cloudwego/gopkg v0.1.1-0.20240816085453-9fbe8155005d
github.com/cloudwego/localsession v0.0.2
github.com/cloudwego/netpoll v0.6.3
github.com/cloudwego/runtimex v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/cloudwego/fastpb v0.0.4 h1:/ROVVfoFtpfc+1pkQLzGs+azjxUbSOsAqSY4tAAx4m
github.com/cloudwego/fastpb v0.0.4/go.mod h1:/V13XFTq2TUkxj2qWReV8MwfPC4NnPcy6FsrojnsSG0=
github.com/cloudwego/frugal v0.2.0 h1:0ETSzQYoYqVvdl7EKjqJ9aJnDoG6TzvNKV3PMQiQTS8=
github.com/cloudwego/frugal v0.2.0/go.mod h1:cpnV6kdRMjN3ylxRo63RNbZ9rBK6oxs70Zk6QZ4Enj4=
github.com/cloudwego/gopkg v0.1.1-0.20240812141034-843ef58f1234 h1:ID8y5ks8EetjB7Qqqgfd9FhPIpt+PSUsQxHeZA64+7Q=
github.com/cloudwego/gopkg v0.1.1-0.20240812141034-843ef58f1234/go.mod h1:32yKw2zkpTMtuX6amJR0EMK79f0vGPr67UcArCOlZLU=
github.com/cloudwego/gopkg v0.1.1-0.20240816085453-9fbe8155005d h1:QBV/89XA0Mwlk6LQgLIDIf1vDMWSn9O2Xx1lJX7PRGI=
github.com/cloudwego/gopkg v0.1.1-0.20240816085453-9fbe8155005d/go.mod h1:32yKw2zkpTMtuX6amJR0EMK79f0vGPr67UcArCOlZLU=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/cloudwego/localsession v0.0.2 h1:N9/IDtCPj1fCL9bCTP+DbXx3f40YjVYWcwkJG0YhQkY=
Expand Down
19 changes: 15 additions & 4 deletions pkg/protocol/bthrift/apache/apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package apache

import (
"errors"
"io"

"github.com/apache/thrift/lib/go/thrift"
"github.com/cloudwego/gopkg/protocol/thrift/apache"
Expand All @@ -40,20 +41,30 @@ func checkTStruct(v interface{}) error {
return nil
}

func callThriftRead(t apache.TTransport, v interface{}) error {
func callThriftRead(r io.ReadWriter, v interface{}) error {
p, ok := v.(thrift.TStruct)
if !ok {
return errNotThriftTStruct
}
in := thrift.NewTBinaryProtocol(t, true, true)
t, ok := r.(byteBuffer)
if ok {
in := NewBinaryProtocol(t)
return p.Read(in)
}
in := thrift.NewTBinaryProtocol(apache.NewDefaultTransport(r), true, true)
return p.Read(in)
}

func callThriftWrite(t apache.TTransport, v interface{}) error {
func callThriftWrite(w io.ReadWriter, v interface{}) error {
p, ok := v.(thrift.TStruct)
if !ok {
return errNotThriftTStruct
}
out := thrift.NewTBinaryProtocol(t, true, true)
t, ok := w.(byteBuffer)
if ok {
out := NewBinaryProtocol(t)
return p.Write(out)
}
out := thrift.NewTBinaryProtocol(apache.NewDefaultTransport(w), true, true)
return p.Write(out)
}
Loading

0 comments on commit 2daa371

Please sign in to comment.