Skip to content

Commit 6d52470

Browse files
Merge pull request #26 from alex-goodisman/signed-byte-tags
Fix Signed 8-bit headers being treated as unsigned
2 parents 52a5b5a + 35185a9 commit 6d52470

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

integration_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ func TestRoundTripAllFieldValueTypes61(t *testing.T) {
11991199
timestamp,
12001200
nil,
12011201
byte(2),
1202+
int8(-2),
12021203
float64(2.64),
12031204
float32(2.32),
12041205
int64(2 << 60),
@@ -1212,7 +1213,8 @@ func TestRoundTripAllFieldValueTypes61(t *testing.T) {
12121213
"S": string("string"),
12131214
"T": timestamp,
12141215
"V": nil,
1215-
"b": byte(1),
1216+
"B": byte(1),
1217+
"b": int8(-1),
12161218
"d": float64(1.64),
12171219
"f": float32(1.32),
12181220
"l": int64(1 << 60),

read.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ func readTimestamp(r io.Reader) (v time.Time, err error) {
161161
'S': string
162162
'T': time.Time
163163
'V': nil
164-
'b': byte
164+
'b': int8
165+
'B': byte
165166
'd': float64
166167
'f': float32
167168
'l': int64
@@ -183,13 +184,20 @@ func readField(r io.Reader) (v interface{}, err error) {
183184
}
184185
return (value != 0), nil
185186

186-
case 'b':
187+
case 'B':
187188
var value [1]byte
188189
if _, err = io.ReadFull(r, value[0:1]); err != nil {
189190
return
190191
}
191192
return value[0], nil
192193

194+
case 'b':
195+
var value int8
196+
if err = binary.Read(r, binary.BigEndian, &value); err != nil {
197+
return
198+
}
199+
return value, nil
200+
193201
case 's':
194202
var value int16
195203
if err = binary.Read(r, binary.BigEndian, &value); err != nil {

types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ type Decimal struct {
198198
//
199199
// bool
200200
// byte
201+
// int8
201202
// float32
202203
// float64
203204
// int
@@ -226,7 +227,7 @@ type Table map[string]interface{}
226227

227228
func validateField(f interface{}) error {
228229
switch fv := f.(type) {
229-
case nil, bool, byte, int, int16, int32, int64, float32, float64, string, []byte, Decimal, time.Time:
230+
case nil, bool, byte, int8, int, int16, int32, int64, float32, float64, string, []byte, Decimal, time.Time:
230231
return nil
231232

232233
case []interface{}:

write.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ func writeLongstr(w io.Writer, s string) (err error) {
276276
'S': string
277277
'T': time.Time
278278
'V': nil
279-
'b': byte
279+
'b': int8
280+
'B': byte
280281
'd': float64
281282
'f': float32
282283
'l': int64
@@ -299,10 +300,15 @@ func writeField(w io.Writer, value interface{}) (err error) {
299300
enc = buf[:2]
300301

301302
case byte:
302-
buf[0] = 'b'
303+
buf[0] = 'B'
303304
buf[1] = v
304305
enc = buf[:2]
305306

307+
case int8:
308+
buf[0] = 'b'
309+
buf[1] = uint8(v)
310+
enc = buf[:2]
311+
306312
case int16:
307313
buf[0] = 's'
308314
binary.BigEndian.PutUint16(buf[1:3], uint16(v))

0 commit comments

Comments
 (0)