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

try to add extra types from rabbitmq spec #494

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 41 additions & 1 deletion read.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,23 @@ func readTimestamp(r io.Reader) (v time.Time, err error) {

/*
'A': []interface{}
'B': byte
'D': Decimal
'F': Table
'I': int32
'L': int64
'S': string
'T': time.Time
'U': int16
'V': nil
'b': byte
'b': int8
'd': float64
'f': float32
'i': uint32
'l': int64
's': int16
't': bool
'u': uint16
'x': []byte
*/
func readField(r io.Reader) (v interface{}, err error) {
Expand All @@ -190,27 +195,62 @@ func readField(r io.Reader) (v interface{}, err error) {
}
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 {
return
}
return value, nil

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

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

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

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

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

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

case 'f':
var value float32
if err = binary.Read(r, binary.BigEndian, &value); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ func writeField(w io.Writer, value interface{}) (err error) {
}
enc = buf[:2]

case int8:
buf[0] = 'B'
buf[1] = byte(v)
enc = buf[:2]

case byte:
buf[0] = 'b'
buf[1] = byte(v)
Expand All @@ -308,6 +313,11 @@ func writeField(w io.Writer, value interface{}) (err error) {
binary.BigEndian.PutUint16(buf[1:3], uint16(v))
enc = buf[:3]

case uint16:
buf[0] = 'u'
binary.BigEndian.PutUint16(buf[1:3], uint16(v))
enc = buf[:3]

case int:
buf[0] = 'I'
binary.BigEndian.PutUint32(buf[1:5], uint32(v))
Expand All @@ -323,6 +333,11 @@ func writeField(w io.Writer, value interface{}) (err error) {
binary.BigEndian.PutUint64(buf[1:9], uint64(v))
enc = buf[:9]

case uint64:
buf[0] = 'l'
binary.BigEndian.PutUint64(buf[1:9], uint64(v))
enc = buf[:9]

case float32:
buf[0] = 'f'
binary.BigEndian.PutUint32(buf[1:5], math.Float32bits(v))
Expand Down