diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-05-31 16:20:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 16:20:34 +0200 |
commit | 8f5f0cf44898a5785a0fb2cf814969e13ab17a3c (patch) | |
tree | a8cb724a8f7617f9147f9a7b3661cc701b04f8aa /vendor/github.com/uber/jaeger-client-go/thrift/serializer.go | |
parent | 60b372b49b53ef4fccb16a366e7133a861143612 (diff) | |
parent | d657a070d36e206b1312db48c26cb72cd26e7202 (diff) | |
download | podman-8f5f0cf44898a5785a0fb2cf814969e13ab17a3c.tar.gz podman-8f5f0cf44898a5785a0fb2cf814969e13ab17a3c.tar.bz2 podman-8f5f0cf44898a5785a0fb2cf814969e13ab17a3c.zip |
Merge pull request #10450 from containers/dependabot/go_modules/github.com/uber/jaeger-client-go-2.29.1incompatible
Bump github.com/uber/jaeger-client-go from 2.28.0+incompatible to 2.29.1+incompatible
Diffstat (limited to 'vendor/github.com/uber/jaeger-client-go/thrift/serializer.go')
-rw-r--r-- | vendor/github.com/uber/jaeger-client-go/thrift/serializer.go | 87 |
1 files changed, 74 insertions, 13 deletions
diff --git a/vendor/github.com/uber/jaeger-client-go/thrift/serializer.go b/vendor/github.com/uber/jaeger-client-go/thrift/serializer.go index 771222999..c44979094 100644 --- a/vendor/github.com/uber/jaeger-client-go/thrift/serializer.go +++ b/vendor/github.com/uber/jaeger-client-go/thrift/serializer.go @@ -19,57 +19,118 @@ package thrift +import ( + "context" + "sync" +) + type TSerializer struct { Transport *TMemoryBuffer Protocol TProtocol } type TStruct interface { - Write(p TProtocol) error - Read(p TProtocol) error + Write(ctx context.Context, p TProtocol) error + Read(ctx context.Context, p TProtocol) error } func NewTSerializer() *TSerializer { transport := NewTMemoryBufferLen(1024) - protocol := NewTBinaryProtocolFactoryDefault().GetProtocol(transport) + protocol := NewTBinaryProtocolTransport(transport) return &TSerializer{ - transport, - protocol} + Transport: transport, + Protocol: protocol, + } } -func (t *TSerializer) WriteString(msg TStruct) (s string, err error) { +func (t *TSerializer) WriteString(ctx context.Context, msg TStruct) (s string, err error) { t.Transport.Reset() - if err = msg.Write(t.Protocol); err != nil { + if err = msg.Write(ctx, t.Protocol); err != nil { return } - if err = t.Protocol.Flush(); err != nil { + if err = t.Protocol.Flush(ctx); err != nil { return } - if err = t.Transport.Flush(); err != nil { + if err = t.Transport.Flush(ctx); err != nil { return } return t.Transport.String(), nil } -func (t *TSerializer) Write(msg TStruct) (b []byte, err error) { +func (t *TSerializer) Write(ctx context.Context, msg TStruct) (b []byte, err error) { t.Transport.Reset() - if err = msg.Write(t.Protocol); err != nil { + if err = msg.Write(ctx, t.Protocol); err != nil { return } - if err = t.Protocol.Flush(); err != nil { + if err = t.Protocol.Flush(ctx); err != nil { return } - if err = t.Transport.Flush(); err != nil { + if err = t.Transport.Flush(ctx); err != nil { return } b = append(b, t.Transport.Bytes()...) return } + +// TSerializerPool is the thread-safe version of TSerializer, it uses resource +// pool of TSerializer under the hood. +// +// It must be initialized with either NewTSerializerPool or +// NewTSerializerPoolSizeFactory. +type TSerializerPool struct { + pool sync.Pool +} + +// NewTSerializerPool creates a new TSerializerPool. +// +// NewTSerializer can be used as the arg here. +func NewTSerializerPool(f func() *TSerializer) *TSerializerPool { + return &TSerializerPool{ + pool: sync.Pool{ + New: func() interface{} { + return f() + }, + }, + } +} + +// NewTSerializerPoolSizeFactory creates a new TSerializerPool with the given +// size and protocol factory. +// +// Note that the size is not the limit. The TMemoryBuffer underneath can grow +// larger than that. It just dictates the initial size. +func NewTSerializerPoolSizeFactory(size int, factory TProtocolFactory) *TSerializerPool { + return &TSerializerPool{ + pool: sync.Pool{ + New: func() interface{} { + transport := NewTMemoryBufferLen(size) + protocol := factory.GetProtocol(transport) + + return &TSerializer{ + Transport: transport, + Protocol: protocol, + } + }, + }, + } +} + +func (t *TSerializerPool) WriteString(ctx context.Context, msg TStruct) (string, error) { + s := t.pool.Get().(*TSerializer) + defer t.pool.Put(s) + return s.WriteString(ctx, msg) +} + +func (t *TSerializerPool) Write(ctx context.Context, msg TStruct) ([]byte, error) { + s := t.pool.Get().(*TSerializer) + defer t.pool.Put(s) + return s.Write(ctx, msg) +} |