Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package thrift
import (
"bufio"
"bytes"
"errors"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -565,6 +566,10 @@ func (p *TSimpleJSONProtocol) Transport() TTransport {
}

func (p *TSimpleJSONProtocol) OutputPreValue() error {
if len(p.dumpContext) == 0 {
return errors.New("dumpContext is empty")
}

cxt := _ParseContext(p.dumpContext[len(p.dumpContext)-1])
switch cxt {
case _CONTEXT_IN_LIST, _CONTEXT_IN_OBJECT_NEXT_KEY:
Expand All @@ -582,6 +587,10 @@ func (p *TSimpleJSONProtocol) OutputPreValue() error {
}

func (p *TSimpleJSONProtocol) OutputPostValue() error {
if len(p.dumpContext) == 0 {
return errors.New("dumpContext is empty")
}

cxt := _ParseContext(p.dumpContext[len(p.dumpContext)-1])
switch cxt {
case _CONTEXT_IN_LIST_FIRST:
Expand All @@ -608,6 +617,10 @@ func (p *TSimpleJSONProtocol) OutputBool(value bool) error {
if e := p.OutputPreValue(); e != nil {
return e
}
if len(p.dumpContext) == 0 {
return errors.New("dumpContext is empty")
}

var v string
if value {
v = string(JSON_TRUE)
Expand Down Expand Up @@ -648,6 +661,9 @@ func (p *TSimpleJSONProtocol) OutputF64(value float64) error {
v = string(JSON_QUOTE) + JSON_NEGATIVE_INFINITY + string(JSON_QUOTE)
} else {
v = strconv.FormatFloat(value, 'g', -1, 64)
if len(p.dumpContext) == 0 {
return errors.New("dumpContext is empty")
}
switch _ParseContext(p.dumpContext[len(p.dumpContext)-1]) {
case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY:
v = string(JSON_QUOTE) + v + string(JSON_QUOTE)
Expand All @@ -664,6 +680,10 @@ func (p *TSimpleJSONProtocol) OutputI64(value int64) error {
if e := p.OutputPreValue(); e != nil {
return e
}
if len(p.dumpContext) == 0 {
return errors.New("dumpContext is empty")
}

v := strconv.FormatInt(value, 10)
switch _ParseContext(p.dumpContext[len(p.dumpContext)-1]) {
case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY:
Expand Down Expand Up @@ -706,6 +726,10 @@ func (p *TSimpleJSONProtocol) OutputObjectEnd() error {
if _, e := p.write(JSON_RBRACE); e != nil {
return NewTProtocolException(e)
}
if len(p.dumpContext) == 0 {
return errors.New("dumpContext is empty")
}

p.dumpContext = p.dumpContext[:len(p.dumpContext)-1]
if e := p.OutputPostValue(); e != nil {
return e
Expand All @@ -728,6 +752,10 @@ func (p *TSimpleJSONProtocol) OutputListEnd() error {
if _, e := p.write(JSON_RBRACKET); e != nil {
return NewTProtocolException(e)
}
if len(p.dumpContext) == 0 {
return errors.New("dumpContext is empty")
}

p.dumpContext = p.dumpContext[:len(p.dumpContext)-1]
if e := p.OutputPostValue(); e != nil {
return e
Expand All @@ -752,6 +780,10 @@ func (p *TSimpleJSONProtocol) ParsePreValue() error {
if e := p.readNonSignificantWhitespace(); e != nil {
return NewTProtocolException(e)
}
if len(p.parseContextStack) == 0 {
return errors.New("parseContextStack is empty")
}

cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1])
b, _ := p.reader.Peek(1)
switch cxt {
Expand Down Expand Up @@ -812,6 +844,10 @@ func (p *TSimpleJSONProtocol) ParsePostValue() error {
if e := p.readNonSignificantWhitespace(); e != nil {
return NewTProtocolException(e)
}
if len(p.parseContextStack) == 0 {
return errors.New("parseContextStack is empty")
}

cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1])
switch cxt {
case _CONTEXT_IN_LIST_FIRST:
Expand Down Expand Up @@ -991,6 +1027,10 @@ func (p *TSimpleJSONProtocol) ParseObjectEnd() error {
if isNull, err := p.readIfNull(); isNull || err != nil {
return err
}
if len(p.parseContextStack) == 0 {
return errors.New("parseContextStack is empty")
}

cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1])
if (cxt != _CONTEXT_IN_OBJECT_FIRST) && (cxt != _CONTEXT_IN_OBJECT_NEXT_KEY) {
e := fmt.Errorf("Expected to be in the Object Context, but not in Object Context (%d)", cxt)
Expand Down Expand Up @@ -1052,6 +1092,10 @@ func (p *TSimpleJSONProtocol) ParseListEnd() error {
if isNull, err := p.readIfNull(); isNull || err != nil {
return err
}
if len(p.parseContextStack) == 0 {
return errors.New("parseContextStack is empty")
}

cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1])
if cxt != _CONTEXT_IN_LIST {
e := fmt.Errorf("Expected to be in the List Context, but not in List Context (%d)", cxt)
Expand Down