Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Signed 8-bit headers being treated as unsigned #26

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
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
change uint8 to 'B' and add int8 support for 'b'
  • Loading branch information
alex-goodisman committed Nov 22, 2021
commit 35185a90b7f1a586bad0fd8e347e8c8e536e717d
4 changes: 3 additions & 1 deletion integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ func TestRoundTripAllFieldValueTypes61(t *testing.T) {
timestamp,
nil,
byte(2),
int8(-2),
float64(2.64),
float32(2.32),
int64(2 << 60),
Expand All @@ -1212,7 +1213,8 @@ func TestRoundTripAllFieldValueTypes61(t *testing.T) {
"S": string("string"),
"T": timestamp,
"V": nil,
"b": byte(1),
"B": byte(1),
"b": int8(-1),
"d": float64(1.64),
"f": float32(1.32),
"l": int64(1 << 60),
Expand Down
12 changes: 10 additions & 2 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ func readTimestamp(r io.Reader) (v time.Time, err error) {
'S': string
'T': time.Time
'V': nil
'b': byte
'b': int8
'B': byte
'd': float64
'f': float32
'l': int64
Expand All @@ -183,13 +184,20 @@ func readField(r io.Reader) (v interface{}, err error) {
}
return (value != 0), nil

case 'b':
case 'B':
var value [1]byte
if _, err = io.ReadFull(r, value[0:1]); err != nil {
return
}
return value[0], nil

case 'b':
var value int8
if err = binary.Read(r, binary.BigEndian, &value); err != nil {
return
}
return value, nil

case 's':
var value int16
if err = binary.Read(r, binary.BigEndian, &value); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ type Decimal struct {
//
// bool
// byte
// int8
// float32
// float64
// int
Expand Down Expand Up @@ -226,7 +227,7 @@ type Table map[string]interface{}

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

case []interface{}:
Expand Down
10 changes: 8 additions & 2 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ func writeLongstr(w io.Writer, s string) (err error) {
'S': string
'T': time.Time
'V': nil
'b': byte
'b': int8
'B': byte
'd': float64
'f': float32
'l': int64
Expand All @@ -299,10 +300,15 @@ func writeField(w io.Writer, value interface{}) (err error) {
enc = buf[:2]

case byte:
buf[0] = 'b'
buf[0] = 'B'
buf[1] = v
enc = buf[:2]

case int8:
buf[0] = 'b'
buf[1] = uint8(v)
enc = buf[:2]

case int16:
buf[0] = 's'
binary.BigEndian.PutUint16(buf[1:3], uint16(v))
Expand Down