Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace TTransport with io.ReadWriter in apache bridge module #16

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions protocol/thrift/apache/apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ package apache

import (
"errors"
"io"
)

var (
fnCheckTStruct func(v interface{}) error

fnThriftRead func(t TTransport, v interface{}) error
fnThriftWrite func(t TTransport, v interface{}) error
fnThriftRead func(rw io.ReadWriter, v interface{}) error
fnThriftWrite func(rw io.ReadWriter, v interface{}) error
)

// RegisterCheckTStruct accepts `thrift.TStruct check` func and save it for later use.
Expand All @@ -52,12 +53,12 @@ func RegisterCheckTStruct(fn func(v interface{}) error) {
}

// RegisterThriftRead ...
func RegisterThriftRead(fn func(t TTransport, v interface{}) error) {
func RegisterThriftRead(fn func(rw io.ReadWriter, v interface{}) error) {
fnThriftRead = fn
}

// RegisterThriftWrite ...
func RegisterThriftWrite(fn func(t TTransport, v interface{}) error) {
func RegisterThriftWrite(fn func(rw io.ReadWriter, v interface{}) error) {
fnThriftWrite = fn
}

Expand All @@ -76,17 +77,17 @@ func CheckTStruct(v interface{}) error {
}

// ThriftRead ...
func ThriftRead(t TTransport, v interface{}) error {
func ThriftRead(rw io.ReadWriter, v interface{}) error {
if fnThriftRead == nil {
return errThriftReadNotRegistered
}
return fnThriftRead(t, v)
return fnThriftRead(rw, v)
}

// ThriftWrite ...
func ThriftWrite(t TTransport, v interface{}) error {
func ThriftWrite(rw io.ReadWriter, v interface{}) error {
if fnThriftWrite == nil {
return errThriftWriteNotRegistered
}
return fnThriftWrite(t, v)
return fnThriftWrite(rw, v)
}
10 changes: 5 additions & 5 deletions protocol/thrift/apache/apache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestThriftReadWrite(t *testing.T) {

buf := &bytes.Buffer{}

err = ThriftWrite(NewBufferTransport(buf), v)
err = ThriftWrite(buf, v)
require.Same(t, err, errThriftWriteNotRegistered)

RegisterThriftWrite(callThriftWrite)
Expand Down Expand Up @@ -84,18 +84,18 @@ func checkTStruct(v interface{}) error {
return nil
}

func callThriftRead(t TTransport, v interface{}) error {
func callThriftRead(rw io.ReadWriter, v interface{}) error {
p, ok := v.(TStruct)
if !ok {
return errNotThriftTStruct
}
return p.Read(t)
return p.Read(rw)
}

func callThriftWrite(t TTransport, v interface{}) error {
func callThriftWrite(rw io.ReadWriter, v interface{}) error {
p, ok := v.(TStruct)
if !ok {
return errNotThriftTStruct
}
return p.Write(t)
return p.Write(rw)
}
Loading