mirror of https://bitbucket.org/ausocean/av.git
EncodeInt24 and EncodeInt32 now take unsigned integers for consistency with decoder counterparts.
This commit is contained in:
parent
ffcd011220
commit
b680e3e164
|
@ -35,7 +35,8 @@ LICENSE
|
|||
*/
|
||||
|
||||
// Package amf implements Action Message Format (AMF) encoding and decoding.
|
||||
// In AMF, encoding of numbers is big endian by default, unless specified otherwise.
|
||||
// In AMF, encoding of numbers is big endian by default, unless specified otherwise,
|
||||
// and numbers are all unsigned.
|
||||
// See https://en.wikipedia.org/wiki/Action_Message_Format.
|
||||
package amf
|
||||
|
||||
|
@ -134,7 +135,7 @@ func DecodeBoolean(buf []byte) bool {
|
|||
}
|
||||
|
||||
// EncodeInt24 encodes a 24-bit integer.
|
||||
func EncodeInt24(buf []byte, val int32) ([]byte, error) {
|
||||
func EncodeInt24(buf []byte, val uint32) ([]byte, error) {
|
||||
if len(buf) < 3 {
|
||||
return nil, ErrShortBuffer
|
||||
}
|
||||
|
@ -145,11 +146,11 @@ func EncodeInt24(buf []byte, val int32) ([]byte, error) {
|
|||
}
|
||||
|
||||
// EncodeInt32 encodes a 32-bit integer.
|
||||
func EncodeInt32(buf []byte, val int32) ([]byte, error) {
|
||||
func EncodeInt32(buf []byte, val uint32) ([]byte, error) {
|
||||
if len(buf) < 4 {
|
||||
return nil, ErrShortBuffer
|
||||
}
|
||||
binary.BigEndian.PutUint32(buf, uint32(val))
|
||||
binary.BigEndian.PutUint32(buf, val)
|
||||
return buf[4:], nil
|
||||
}
|
||||
|
||||
|
@ -160,7 +161,7 @@ func EncodeString(buf []byte, val string) ([]byte, error) {
|
|||
return nil, ErrShortBuffer
|
||||
}
|
||||
|
||||
if len(val)+typeSize+binary.Size(int32(0)) > len(buf) {
|
||||
if len(val)+typeSize+binary.Size(uint32(0)) > len(buf) {
|
||||
return nil, ErrShortBuffer
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ var testStrings = [...]string{
|
|||
"bazz",
|
||||
}
|
||||
|
||||
var testNumbers = [...]int32{
|
||||
var testNumbers = [...]uint32{
|
||||
0,
|
||||
1,
|
||||
0xababab,
|
||||
|
@ -102,7 +102,7 @@ func TestNumbers(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("EncodeInt24 failed")
|
||||
}
|
||||
dn := int32(DecodeInt24(buf))
|
||||
dn := DecodeInt24(buf)
|
||||
if n != dn {
|
||||
t.Errorf("DecodeInt24 did not produce original Number, got %v", dn)
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ func TestNumbers(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("EncodeInt32 failed")
|
||||
}
|
||||
dn = int32(DecodeInt32(buf))
|
||||
dn = DecodeInt32(buf)
|
||||
if n != dn {
|
||||
t.Errorf("DecodeInt32 did not produce original Number, got %v", dn)
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func TestProperties(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("DecodeProperty of Number failed")
|
||||
}
|
||||
if int32(prop.Number) != testNumbers[i] {
|
||||
if prop.Number != float64(testNumbers[i]) {
|
||||
t.Errorf("EncodeProperty/DecodeProperty returned wrong Number; got %v, expected %v", int32(prop.Number), testNumbers[i])
|
||||
}
|
||||
dec = dec[n:]
|
||||
|
|
Loading…
Reference in New Issue