mirror of https://bitbucket.org/ausocean/av.git
TypeString now exported (was typeString).
This commit is contained in:
parent
54d351a55e
commit
adfb87dcf9
|
@ -51,7 +51,7 @@ import (
|
|||
const (
|
||||
typeNumber = 0x00
|
||||
typeBoolean = 0x01
|
||||
typeString = 0x02
|
||||
TypeString = 0x02
|
||||
TypeObject = 0x03
|
||||
typeMovieClip = 0x04
|
||||
TypeNull = 0x05
|
||||
|
@ -93,7 +93,7 @@ type Property struct {
|
|||
var (
|
||||
ErrShortBuffer = errors.New("amf: short buffer") // The supplied buffer was too short.
|
||||
ErrInvalidType = errors.New("amf: invalid type") // An invalid type was supplied to the encoder.
|
||||
ErrUnexpectedType = errors.New("amf: unexpected end") // An unexpected type was encountered while decoding.
|
||||
ErrUnexpectedType = errors.New("amf: unexpected type") // An unexpected type was encountered while decoding.
|
||||
ErrPropertyNotFound = errors.New("amf: property not found") // The requested property was not found.
|
||||
)
|
||||
|
||||
|
@ -160,6 +160,7 @@ func EncodeInt32(buf []byte, val uint32) ([]byte, error) {
|
|||
}
|
||||
|
||||
// EncodeString encodes a string.
|
||||
// Strings less than 65536 in length are encoded as TypeString, while longer strings are ecodeded as typeLongString.
|
||||
func EncodeString(buf []byte, val string) ([]byte, error) {
|
||||
const typeSize = 1
|
||||
if len(val) < 65536 && len(val)+typeSize+binary.Size(int16(0)) > len(buf) {
|
||||
|
@ -171,7 +172,7 @@ func EncodeString(buf []byte, val string) ([]byte, error) {
|
|||
}
|
||||
|
||||
if len(val) < 65536 {
|
||||
buf[0] = typeString
|
||||
buf[0] = TypeString
|
||||
buf = buf[1:]
|
||||
binary.BigEndian.PutUint16(buf[:2], uint16(len(val)))
|
||||
buf = buf[2:]
|
||||
|
@ -263,7 +264,7 @@ func EncodeProperty(prop *Property, buf []byte) ([]byte, error) {
|
|||
return EncodeNumber(buf, prop.Number)
|
||||
case typeBoolean:
|
||||
return EncodeBoolean(buf, prop.Number != 0)
|
||||
case typeString:
|
||||
case TypeString:
|
||||
return EncodeString(buf, prop.String)
|
||||
case TypeNull:
|
||||
if len(buf) < 2 {
|
||||
|
@ -320,7 +321,7 @@ func DecodeProperty(prop *Property, buf []byte, decodeName bool) (int, error) {
|
|||
prop.Number = float64(buf[0])
|
||||
buf = buf[1:]
|
||||
|
||||
case typeString:
|
||||
case TypeString:
|
||||
n := DecodeInt16(buf[:2])
|
||||
if len(buf) < int(n+2) {
|
||||
return 0, ErrShortBuffer
|
||||
|
@ -354,7 +355,6 @@ func DecodeProperty(prop *Property, buf []byte, decodeName bool) (int, error) {
|
|||
}
|
||||
|
||||
// Encode encodes an Object into its AMF representation.
|
||||
// This is the top-level encoding function and is typically the only function callers will need to use.
|
||||
func Encode(obj *Object, buf []byte) ([]byte, error) {
|
||||
if len(buf) < 5 {
|
||||
return nil, ErrShortBuffer
|
||||
|
@ -481,7 +481,7 @@ func (obj *Object) NumberProperty(name string, idx int) (float64, error) {
|
|||
|
||||
// StringProperty is a wrapper for Property that returns a String property's value, if any.
|
||||
func (obj *Object) StringProperty(name string, idx int) (string, error) {
|
||||
prop, err := obj.Property(name, idx, typeString)
|
||||
prop, err := obj.Property(name, idx, TypeString)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestSanity(t *testing.T) {
|
|||
// TestStrings tests string encoding and decoding.
|
||||
func TestStrings(t *testing.T) {
|
||||
// Short string encoding is as follows:
|
||||
// enc[0] = data type (typeString)
|
||||
// enc[0] = data type (TypeString)
|
||||
// end[1:3] = size
|
||||
// enc[3:] = data
|
||||
for _, s := range testStrings {
|
||||
|
@ -67,8 +67,8 @@ func TestStrings(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("EncodeString failed")
|
||||
}
|
||||
if buf[0] != typeString {
|
||||
t.Errorf("Expected typeString, got %v", buf[0])
|
||||
if buf[0] != TypeString {
|
||||
t.Errorf("Expected TypeString, got %v", buf[0])
|
||||
}
|
||||
ds := DecodeString(buf[1:])
|
||||
if s != ds {
|
||||
|
@ -76,7 +76,7 @@ func TestStrings(t *testing.T) {
|
|||
}
|
||||
}
|
||||
// Long string encoding is as follows:
|
||||
// enc[0] = data type (typeString)
|
||||
// enc[0] = data type (TypeString)
|
||||
// end[1:5] = size
|
||||
// enc[5:] = data
|
||||
s := string(make([]byte, 65536))
|
||||
|
@ -148,7 +148,7 @@ func TestProperties(t *testing.T) {
|
|||
// Encode/decode string properties.
|
||||
enc = buf[:]
|
||||
for i := range testStrings {
|
||||
enc, err = EncodeProperty(&Property{Type: typeString, String: testStrings[i]}, enc)
|
||||
enc, err = EncodeProperty(&Property{Type: TypeString, String: testStrings[i]}, enc)
|
||||
if err != nil {
|
||||
t.Errorf("EncodeProperty of string failed")
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ func TestObject(t *testing.T) {
|
|||
// Construct a more complicated object that includes a nested object.
|
||||
var obj2 Object
|
||||
for i := range testStrings {
|
||||
obj2.Properties = append(obj2.Properties, Property{Type: typeString, String: testStrings[i]})
|
||||
obj2.Properties = append(obj2.Properties, Property{Type: TypeString, String: testStrings[i]})
|
||||
obj2.Properties = append(obj2.Properties, Property{Type: typeNumber, Number: float64(testNumbers[i])})
|
||||
}
|
||||
obj2.Properties = append(obj2.Properties, Property{Type: TypeObject, Object: obj1})
|
||||
|
|
Loading…
Reference in New Issue