Skip to content

Commit

Permalink
merge 0.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
donnie4w committed Sep 24, 2024
1 parent 90ec2e1 commit d5b944d
Show file tree
Hide file tree
Showing 26 changed files with 2,983 additions and 2,885 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/donnie4w/gothrift

go 1.21.0
go 1.22.4
2 changes: 1 addition & 1 deletion thrift/binary_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func generateSafeReadBytesBenchmark(askedSize int32, dataSize int) func(b *testi
return func(b *testing.B) {
data := make([]byte, dataSize)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
safeReadBytes(askedSize, bytes.NewReader(data))
}
}
Expand Down
76 changes: 45 additions & 31 deletions thrift/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,47 +56,47 @@ const (
//
// For example, say you want to migrate this old code into using TConfiguration:
//
// sccket, err := thrift.NewTSocketTimeout("host:port", time.Second, time.Second)
// transFactory := thrift.NewTFramedTransportFactoryMaxLength(
// thrift.NewTTransportFactory(),
// 1024 * 1024 * 256,
// )
// protoFactory := thrift.NewTBinaryProtocolFactory(true, true)
// socket, err := thrift.NewTSocketTimeout("host:port", time.Second, time.Second)
// transFactory := thrift.NewTFramedTransportFactoryMaxLength(
// thrift.NewTTransportFactory(),
// 1024 * 1024 * 256,
// )
// protoFactory := thrift.NewTBinaryProtocolFactory(true, true)
//
// This is the wrong way to do it because in the end the TConfiguration used by
// socket and transFactory will be overwritten by the one used by protoFactory
// because of TConfiguration propagation:
//
// // bad example, DO NOT USE
// sccket := thrift.NewTSocketConf("host:port", &thrift.TConfiguration{
// ConnectTimeout: time.Second,
// SocketTimeout: time.Second,
// })
// transFactory := thrift.NewTFramedTransportFactoryConf(
// thrift.NewTTransportFactory(),
// &thrift.TConfiguration{
// MaxFrameSize: 1024 * 1024 * 256,
// },
// )
// protoFactory := thrift.NewTBinaryProtocolFactoryConf(&thrift.TConfiguration{
// TBinaryStrictRead: thrift.BoolPtr(true),
// TBinaryStrictWrite: thrift.BoolPtr(true),
// })
// // bad example, DO NOT USE
// socket := thrift.NewTSocketConf("host:port", &thrift.TConfiguration{
// ConnectTimeout: time.Second,
// SocketTimeout: time.Second,
// })
// transFactory := thrift.NewTFramedTransportFactoryConf(
// thrift.NewTTransportFactory(),
// &thrift.TConfiguration{
// MaxFrameSize: 1024 * 1024 * 256,
// },
// )
// protoFactory := thrift.NewTBinaryProtocolFactoryConf(&thrift.TConfiguration{
// TBinaryStrictRead: thrift.BoolPtr(true),
// TBinaryStrictWrite: thrift.BoolPtr(true),
// })
//
// This is the correct way to do it:
//
// conf := &thrift.TConfiguration{
// ConnectTimeout: time.Second,
// SocketTimeout: time.Second,
// conf := &thrift.TConfiguration{
// ConnectTimeout: time.Second,
// SocketTimeout: time.Second,
//
// MaxFrameSize: 1024 * 1024 * 256,
// MaxFrameSize: 1024 * 1024 * 256,
//
// TBinaryStrictRead: thrift.BoolPtr(true),
// TBinaryStrictWrite: thrift.BoolPtr(true),
// }
// sccket := thrift.NewTSocketConf("host:port", conf)
// transFactory := thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), conf)
// protoFactory := thrift.NewTBinaryProtocolFactoryConf(conf)
// TBinaryStrictRead: thrift.BoolPtr(true),
// TBinaryStrictWrite: thrift.BoolPtr(true),
// }
// socket := thrift.NewTSocketConf("host:port", conf)
// transFactory := thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), conf)
// protoFactory := thrift.NewTBinaryProtocolFactoryConf(conf)
//
// [1]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-tconfiguration.md
type TConfiguration struct {
Expand Down Expand Up @@ -132,6 +132,8 @@ type TConfiguration struct {
// THeaderProtocolIDPtr and THeaderProtocolIDPtrMust helper functions
// are provided to help filling this value.
THeaderProtocolID *THeaderProtocolID
// The write transforms to be applied to THeaderTransport.
THeaderTransforms []THeaderTransformID

// Used internally by deprecated constructors, to avoid overriding
// underlying TTransport/TProtocol's cfg by accidental propagations.
Expand Down Expand Up @@ -245,6 +247,18 @@ func (tc *TConfiguration) GetTHeaderProtocolID() THeaderProtocolID {
return protoID
}

// GetTHeaderTransforms returns the THeaderTransformIDs to be applied on
// THeaderTransport writing.
//
// It's nil-safe. If tc is nil, empty slice will be returned (meaning no
// transforms to be applied).
func (tc *TConfiguration) GetTHeaderTransforms() []THeaderTransformID {
if tc == nil {
return nil
}
return tc.THeaderTransforms
}

// THeaderProtocolIDPtr validates and returns the pointer to id.
//
// If id is not a valid THeaderProtocolID, a pointer to THeaderProtocolDefault
Expand Down
Loading

0 comments on commit d5b944d

Please sign in to comment.