You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2013/12/03 22:58:55 UTC
[1/2] git commit: THRIFT-2279 TSerializer only returns the first 1024
bytes serialized
Updated Branches:
refs/heads/master f322d917f -> a59603832
THRIFT-2279 TSerializer only returns the first 1024 bytes serialized
Patch: Matt Jones
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/7949447e
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/7949447e
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/7949447e
Branch: refs/heads/master
Commit: 7949447efdcb2b355d3140a0d1a765e98a9a9e68
Parents: f322d91
Author: Jens Geyer <je...@apache.org>
Authored: Tue Dec 3 22:57:05 2013 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Tue Dec 3 22:57:05 2013 +0100
----------------------------------------------------------------------
lib/go/thrift/serializer.go | 30 ++++++------------------------
1 file changed, 6 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/7949447e/lib/go/thrift/serializer.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/serializer.go b/lib/go/thrift/serializer.go
index 04c2538..7712229 100644
--- a/lib/go/thrift/serializer.go
+++ b/lib/go/thrift/serializer.go
@@ -20,7 +20,7 @@
package thrift
type TSerializer struct {
- Transport TTransport
+ Transport *TMemoryBuffer
Protocol TProtocol
}
@@ -30,9 +30,7 @@ type TStruct interface {
}
func NewTSerializer() *TSerializer {
- var transport TTransport
- transport = NewTMemoryBufferLen(1024)
-
+ transport := NewTMemoryBufferLen(1024)
protocol := NewTBinaryProtocolFactoryDefault().GetProtocol(transport)
return &TSerializer{
@@ -41,8 +39,7 @@ func NewTSerializer() *TSerializer {
}
func (t *TSerializer) WriteString(msg TStruct) (s string, err error) {
- s = ""
- err = nil
+ t.Transport.Reset()
if err = msg.Write(t.Protocol); err != nil {
return
@@ -55,19 +52,11 @@ func (t *TSerializer) WriteString(msg TStruct) (s string, err error) {
return
}
- var buf []byte
- var place int
- buf = make([]byte, 1024)
- if place, err = t.Transport.Read(buf); err != nil {
- return
- }
-
- s = string(buf[:place])
- return
+ return t.Transport.String(), nil
}
func (t *TSerializer) Write(msg TStruct) (b []byte, err error) {
- err = nil
+ t.Transport.Reset()
if err = msg.Write(t.Protocol); err != nil {
return
@@ -81,13 +70,6 @@ func (t *TSerializer) Write(msg TStruct) (b []byte, err error) {
return
}
- var buf []byte
- var place int
- buf = make([]byte, 1024)
- if place, err = t.Transport.Read(buf); err != nil {
- return
- }
-
- b = buf[:place]
+ b = append(b, t.Transport.Bytes()...)
return
}
[2/2] git commit: THRIFT-2278 Buffered transport doesn't support
writes > buffer size
Posted by je...@apache.org.
THRIFT-2278 Buffered transport doesn't support writes > buffer size
Patch: Matt Jones
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/a5960383
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/a5960383
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/a5960383
Branch: refs/heads/master
Commit: a5960383273432d5249c113f6413bbe39c13df50
Parents: 7949447
Author: Jens Geyer <je...@apache.org>
Authored: Tue Dec 3 22:57:59 2013 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Tue Dec 3 22:57:59 2013 +0100
----------------------------------------------------------------------
lib/go/thrift/buffered_transport.go | 19 ++++++++++++++-----
lib/go/thrift/framed_transport.go | 2 +-
2 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/a5960383/lib/go/thrift/buffered_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/buffered_transport.go b/lib/go/thrift/buffered_transport.go
index e3546a5..b92261c 100644
--- a/lib/go/thrift/buffered_transport.go
+++ b/lib/go/thrift/buffered_transport.go
@@ -77,12 +77,21 @@ func (p *TBufferedTransport) Read(buf []byte) (n int, err error) {
func (p *TBufferedTransport) Write(buf []byte) (n int, err error) {
wbuf := p.wbuf
- size := len(buf)
- if wbuf.pos+size > wbuf.limit { // buffer is full, flush buffer
- p.Flush()
+ remaining := len(buf)
+
+ for remaining > 0 {
+ if wbuf.pos+remaining > wbuf.limit { // buffer is full, flush buffer
+ if err := p.Flush(); err != nil {
+ return n, err
+ }
+ }
+ copied := copy(wbuf.buffer[wbuf.pos:], buf[n:])
+
+ wbuf.pos += copied
+ n += copied
+ remaining -= copied
}
- n = copy(wbuf.buffer[wbuf.pos:], buf)
- wbuf.pos += n
+
return n, nil
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/a5960383/lib/go/thrift/framed_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/framed_transport.go b/lib/go/thrift/framed_transport.go
index 3a59e7b..d1af028 100644
--- a/lib/go/thrift/framed_transport.go
+++ b/lib/go/thrift/framed_transport.go
@@ -95,7 +95,7 @@ func (p *TFramedTransport) Flush() error {
}
if size > 0 {
if n, err := p.writeBuffer.WriteTo(p.transport); err != nil {
- print("Error while flushing write buffer of size ", size, " to transport, only wrote ", n, " bytes: ", err, "\n")
+ print("Error while flushing write buffer of size ", size, " to transport, only wrote ", n, " bytes: ", err.Error(), "\n")
return NewTTransportExceptionFromError(err)
}
}