summaryrefslogtreecommitdiff
path: root/lib/go/thrift/compact_protocol.go
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2015-09-05 12:50:24 +0200
committerJens Geyer <jensg@apache.org>2015-09-05 12:50:24 +0200
commit5bc8b5a3a5da507b6f87436ca629be664496a69f (patch)
tree86e30670ce34e95273566755524bb39840724513 /lib/go/thrift/compact_protocol.go
parent96d80200c5dae4fa95b8fa068c6a712773ec321b (diff)
downloadthrift-5bc8b5a3a5da507b6f87436ca629be664496a69f.tar.gz
THRIFT-3302 Go JSON protocol should encode Thrift byte type as signed integer string
Client: Go Patch: Nobuaki Sukegawa <nsukeg@gmail.com> This closes #591
Diffstat (limited to 'lib/go/thrift/compact_protocol.go')
-rw-r--r--lib/go/thrift/compact_protocol.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/go/thrift/compact_protocol.go b/lib/go/thrift/compact_protocol.go
index 731bd163b..0bc5fddeb 100644
--- a/lib/go/thrift/compact_protocol.go
+++ b/lib/go/thrift/compact_protocol.go
@@ -267,8 +267,8 @@ func (p *TCompactProtocol) WriteBool(value bool) error {
}
// Write a byte. Nothing to see here!
-func (p *TCompactProtocol) WriteByte(value byte) error {
- err := p.writeByteDirect(value)
+func (p *TCompactProtocol) WriteByte(value int8) error {
+ err := p.writeByteDirect(byte(value))
return NewTProtocolException(err)
}
@@ -330,7 +330,7 @@ func (p *TCompactProtocol) WriteBinary(bin []byte) error {
// Read a message header.
func (p *TCompactProtocol) ReadMessageBegin() (name string, typeId TMessageType, seqId int32, err error) {
- protocolId, err := p.ReadByte()
+ protocolId, err := p.readByteDirect()
if err != nil {
return
}
@@ -340,7 +340,7 @@ func (p *TCompactProtocol) ReadMessageBegin() (name string, typeId TMessageType,
return "", typeId, seqId, NewTProtocolExceptionWithType(BAD_VERSION, e)
}
- versionAndType, err := p.ReadByte()
+ versionAndType, err := p.readByteDirect()
if err != nil {
return
}
@@ -382,7 +382,7 @@ func (p *TCompactProtocol) ReadStructEnd() error {
// Read a field header off the wire.
func (p *TCompactProtocol) ReadFieldBegin() (name string, typeId TType, id int16, err error) {
- t, err := p.ReadByte()
+ t, err := p.readByteDirect()
if err != nil {
return
}
@@ -441,7 +441,7 @@ func (p *TCompactProtocol) ReadMapBegin() (keyType TType, valueType TType, size
keyAndValueType := byte(STOP)
if size != 0 {
- keyAndValueType, err = p.ReadByte()
+ keyAndValueType, err = p.readByteDirect()
if err != nil {
return
}
@@ -458,7 +458,7 @@ func (p *TCompactProtocol) ReadMapEnd() error { return nil }
// of the element type header will be 0xF, and a varint will follow with the
// true size.
func (p *TCompactProtocol) ReadListBegin() (elemType TType, size int, err error) {
- size_and_type, err := p.ReadByte()
+ size_and_type, err := p.readByteDirect()
if err != nil {
return
}
@@ -503,17 +503,17 @@ func (p *TCompactProtocol) ReadBool() (value bool, err error) {
p.boolValueIsNotNull = false
return p.boolValue, nil
}
- v, err := p.ReadByte()
+ v, err := p.readByteDirect()
return v == COMPACT_BOOLEAN_TRUE, err
}
// Read a single byte off the wire. Nothing interesting here.
-func (p *TCompactProtocol) ReadByte() (value byte, err error) {
- value, err = p.trans.ReadByte()
+func (p *TCompactProtocol) ReadByte() (int8, error) {
+ v, err := p.readByteDirect()
if err != nil {
return 0, NewTProtocolException(err)
}
- return
+ return int8(v), err
}
// Read an i16 from the wire as a zigzag varint.
@@ -721,7 +721,7 @@ func (p *TCompactProtocol) readVarint64() (int64, error) {
shift := uint(0)
result := int64(0)
for {
- b, err := p.ReadByte()
+ b, err := p.readByteDirect()
if err != nil {
return 0, err
}
@@ -734,6 +734,11 @@ func (p *TCompactProtocol) readVarint64() (int64, error) {
return result, nil
}
+// Read a byte, unlike ReadByte that reads Thrift-byte that is i8.
+func (p *TCompactProtocol) readByteDirect() (byte, error) {
+ return p.trans.ReadByte()
+}
+
//
// encoding helpers
//