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 2016/04/06 22:39:20 UTC

thrift git commit: THRIFT-3746 JSON protocol left in incorrect state on read errors Client: Go Patch: Tyler Treat

Repository: thrift
Updated Branches:
  refs/heads/master 717334816 -> 51850abb7


THRIFT-3746 JSON protocol left in incorrect state on read errors
Client: Go
Patch: Tyler Treat <ty...@webfilings.com>

This closes #955


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/51850abb
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/51850abb
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/51850abb

Branch: refs/heads/master
Commit: 51850abb7ed0a7304f60cbced853285c9b63f4cb
Parents: 7173348
Author: Tyler Treat <ty...@webfilings.com>
Authored: Wed Mar 16 10:06:55 2016 -0500
Committer: Jens Geyer <je...@apache.org>
Committed: Wed Apr 6 22:38:55 2016 +0200

----------------------------------------------------------------------
 lib/go/thrift/json_protocol.go        | 11 +++++-----
 lib/go/thrift/simple_json_protocol.go | 35 ++++++++++++------------------
 2 files changed, 20 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/51850abb/lib/go/thrift/json_protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/json_protocol.go b/lib/go/thrift/json_protocol.go
index 442fa91..e24d065 100644
--- a/lib/go/thrift/json_protocol.go
+++ b/lib/go/thrift/json_protocol.go
@@ -60,7 +60,8 @@ func NewTJSONProtocolFactory() *TJSONProtocolFactory {
 }
 
 func (p *TJSONProtocol) WriteMessageBegin(name string, typeId TMessageType, seqId int32) error {
-	p.resetContextStack() // THRIFT-3735
+	p.resetContextStack()
+	p.writer.Reset(p.trans)
 	if e := p.OutputListBegin(); e != nil {
 		return e
 	}
@@ -203,18 +204,17 @@ func (p *TJSONProtocol) WriteBinary(v []byte) error {
 	if e := p.OutputPreValue(); e != nil {
 		return e
 	}
-	if _, e := p.write(JSON_QUOTE_BYTES); e != nil {
+	if _, e := p.writer.Write(JSON_QUOTE_BYTES); e != nil {
 		return NewTProtocolException(e)
 	}
 	writer := base64.NewEncoder(base64.StdEncoding, p.writer)
 	if _, e := writer.Write(v); e != nil {
-		p.writer.Reset(p.trans) // THRIFT-3735
 		return NewTProtocolException(e)
 	}
 	if e := writer.Close(); e != nil {
 		return NewTProtocolException(e)
 	}
-	if _, e := p.write(JSON_QUOTE_BYTES); e != nil {
+	if _, e := p.writer.Write(JSON_QUOTE_BYTES); e != nil {
 		return NewTProtocolException(e)
 	}
 	return p.OutputPostValue()
@@ -222,7 +222,8 @@ func (p *TJSONProtocol) WriteBinary(v []byte) error {
 
 // Reading methods.
 func (p *TJSONProtocol) ReadMessageBegin() (name string, typeId TMessageType, seqId int32, err error) {
-	p.resetContextStack() // THRIFT-3735
+	p.resetContextStack()
+	p.reader.Reset(p.trans)
 	if isNull, err := p.ParseListBegin(); isNull || err != nil {
 		return name, typeId, seqId, err
 	}

http://git-wip-us.apache.org/repos/asf/thrift/blob/51850abb/lib/go/thrift/simple_json_protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/simple_json_protocol.go b/lib/go/thrift/simple_json_protocol.go
index 7353322..c746f8c 100644
--- a/lib/go/thrift/simple_json_protocol.go
+++ b/lib/go/thrift/simple_json_protocol.go
@@ -156,7 +156,8 @@ func mismatch(expected, actual string) error {
 }
 
 func (p *TSimpleJSONProtocol) WriteMessageBegin(name string, typeId TMessageType, seqId int32) error {
-	p.resetContextStack() // THRIFT-3735
+	p.resetContextStack() 
+	p.writer.Reset(p.trans)
 	if e := p.OutputListBegin(); e != nil {
 		return e
 	}
@@ -270,18 +271,17 @@ func (p *TSimpleJSONProtocol) WriteBinary(v []byte) error {
 	if e := p.OutputPreValue(); e != nil {
 		return e
 	}
-	if _, e := p.write(JSON_QUOTE_BYTES); e != nil {
+	if _, e := p.writer.Write(JSON_QUOTE_BYTES); e != nil {
 		return NewTProtocolException(e)
 	}
 	writer := base64.NewEncoder(base64.StdEncoding, p.writer)
 	if _, e := writer.Write(v); e != nil {
-		p.writer.Reset(p.trans) // THRIFT-3735
 		return NewTProtocolException(e)
 	}
 	if e := writer.Close(); e != nil {
 		return NewTProtocolException(e)
 	}
-	if _, e := p.write(JSON_QUOTE_BYTES); e != nil {
+	if _, e := p.writer.Write(JSON_QUOTE_BYTES); e != nil {
 		return NewTProtocolException(e)
 	}
 	return p.OutputPostValue()
@@ -289,7 +289,8 @@ func (p *TSimpleJSONProtocol) WriteBinary(v []byte) error {
 
 // Reading methods.
 func (p *TSimpleJSONProtocol) ReadMessageBegin() (name string, typeId TMessageType, seqId int32, err error) {
-	p.resetContextStack() // THRIFT-3735
+	p.resetContextStack()   
+	p.reader.Reset(p.trans) 
 	if isNull, err := p.ParseListBegin(); isNull || err != nil {
 		return name, typeId, seqId, err
 	}
@@ -568,12 +569,12 @@ func (p *TSimpleJSONProtocol) OutputPreValue() error {
 	cxt := _ParseContext(p.dumpContext[len(p.dumpContext)-1])
 	switch cxt {
 	case _CONTEXT_IN_LIST, _CONTEXT_IN_OBJECT_NEXT_KEY:
-		if _, e := p.write(JSON_COMMA); e != nil {
+		if _, e := p.writer.Write(JSON_COMMA); e != nil {
 			return NewTProtocolException(e)
 		}
 		break
 	case _CONTEXT_IN_OBJECT_NEXT_VALUE:
-		if _, e := p.write(JSON_COLON); e != nil {
+		if _, e := p.writer.Write(JSON_COLON); e != nil {
 			return NewTProtocolException(e)
 		}
 		break
@@ -629,7 +630,7 @@ func (p *TSimpleJSONProtocol) OutputNull() error {
 	if e := p.OutputPreValue(); e != nil {
 		return e
 	}
-	if _, e := p.write(JSON_NULL); e != nil {
+	if _, e := p.writer.Write(JSON_NULL); e != nil {
 		return NewTProtocolException(e)
 	}
 	return p.OutputPostValue()
@@ -687,7 +688,7 @@ func (p *TSimpleJSONProtocol) OutputString(s string) error {
 }
 
 func (p *TSimpleJSONProtocol) OutputStringData(s string) error {
-	_, e := p.write([]byte(s))
+	_, e := p.writer.Write([]byte(s))
 	return NewTProtocolException(e)
 }
 
@@ -695,7 +696,7 @@ func (p *TSimpleJSONProtocol) OutputObjectBegin() error {
 	if e := p.OutputPreValue(); e != nil {
 		return e
 	}
-	if _, e := p.write(JSON_LBRACE); e != nil {
+	if _, e := p.writer.Write(JSON_LBRACE); e != nil {
 		return NewTProtocolException(e)
 	}
 	p.dumpContext = append(p.dumpContext, int(_CONTEXT_IN_OBJECT_FIRST))
@@ -703,7 +704,7 @@ func (p *TSimpleJSONProtocol) OutputObjectBegin() error {
 }
 
 func (p *TSimpleJSONProtocol) OutputObjectEnd() error {
-	if _, e := p.write(JSON_RBRACE); e != nil {
+	if _, e := p.writer.Write(JSON_RBRACE); e != nil {
 		return NewTProtocolException(e)
 	}
 	p.dumpContext = p.dumpContext[:len(p.dumpContext)-1]
@@ -717,7 +718,7 @@ func (p *TSimpleJSONProtocol) OutputListBegin() error {
 	if e := p.OutputPreValue(); e != nil {
 		return e
 	}
-	if _, e := p.write(JSON_LBRACKET); e != nil {
+	if _, e := p.writer.Write(JSON_LBRACKET); e != nil {
 		return NewTProtocolException(e)
 	}
 	p.dumpContext = append(p.dumpContext, int(_CONTEXT_IN_LIST_FIRST))
@@ -725,7 +726,7 @@ func (p *TSimpleJSONProtocol) OutputListBegin() error {
 }
 
 func (p *TSimpleJSONProtocol) OutputListEnd() error {
-	if _, e := p.write(JSON_RBRACKET); e != nil {
+	if _, e := p.writer.Write(JSON_RBRACKET); e != nil {
 		return NewTProtocolException(e)
 	}
 	p.dumpContext = p.dumpContext[:len(p.dumpContext)-1]
@@ -1327,11 +1328,3 @@ func (p *TSimpleJSONProtocol) resetContextStack() {
 	p.parseContextStack = []int{int(_CONTEXT_IN_TOPLEVEL)}
 	p.dumpContext = []int{int(_CONTEXT_IN_TOPLEVEL)}
 }
-
-func (p *TSimpleJSONProtocol) write(b []byte) (int, error) {
-	n, err := p.writer.Write(b)
-	if err != nil {
-		p.writer.Reset(p.trans) // THRIFT-3735
-	}
-	return n, err
-}