Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // NotFoundError is returned when trying to get a key that doesn't // exist. NotFoundError = errors.New("Item not found in the object.") // WrongTypeError is returned when a key exists, but its type is not the // one requested. WrongTypeError = errors.New("Item not found in the object.") )
var ( // DefaultIdentifier is the default implementation of the Identifier // type. It holds knowledge of all implemented amf0 types in this // package. DefaultIdentifier = NewIdentifier( func() AmfType { return &Array{NewPaired()} }, func() AmfType { return new(Null) }, func() AmfType { return new(Undefined) }, func() AmfType { return new(Bool) }, func() AmfType { return new(Number) }, func() AmfType { return &Object{NewPaired()} }, func() AmfType { return new(String) }, func() AmfType { return new(LongString) }, ) )
var (
ObjectEndSeq = []byte{0x00, 0x00, 0x09}
)
Functions ¶
func EncodeToBytes ¶
EncodeToBytes uses the default Encoder to marshal the given AmfType `t` to a []byte, instead of writing to an io.Writer. Any error returned above will be returned here.
Types ¶
type AmfType ¶
type AmfType interface { // Decodes information for the type from the reader. This expects // the reader to return starting from the first byte _after_ the // type marker. Decode(io.Reader) error // Encodes and writes the type to the reader. Returns an error // if one occurred on the reader. Encode(io.Writer) (int, error) // Gets the associated marker byte for the type. Marker() byte // Native returns the native Golang type assosciated with this AmfType. Native() reflect.Type }
AMF Types (strings, numbers, etc) implement the AmfType interface, which specifies that they have methods available to decode and encode data.
type Decoder ¶
var ( Decode Decoder = func(r io.Reader) (AmfType, error) { var typeId [1]byte if _, err := io.ReadFull(r, typeId[:]); err != nil { return nil, err } typ := DefaultIdentifier.TypeOf(typeId[0]) if typ == nil { return nil, UnknownPacketError(typeId[0]) } if err := typ.Decode(r); err != nil { return nil, err } return typ, nil } )
type Encoder ¶
Encoder represents a func capable of writing a representation of the AmfType "t" to the io.Writer "w". By contract, this type must obey the rules of amf0 encoding, which means there must be a marker, and a payload.
var ( // Encode serves as a default implementation of the Encoder type. It is // compliant with the amf0 specification. It returns the number of bytes // that it wrote (usually 1+len(payload)), and any errors that it // encountered along the way. Encode Encoder = func(t AmfType, w io.Writer) (int, error) { buf := new(bytes.Buffer) buf.Write([]byte{t.Marker()}) if _, err := t.Encode(buf); err != nil { return 0, err } n, err := io.Copy(w, buf) return int(n), err } )
type Identifier ¶
type Identifier struct {
// contains filtered or unexported fields
}
Identifier is a type capable of preforming bi-direcitonal lookups with respect to the various AmfTypes implemented here. It has two discrete responsibilities:
Fetch the AmfType assosciated with a given marker ID. ``` typ := DefaultIdentifier.TypeOf(0x01) #=> (reflect.TypeOf(new(amf0.Bool)).Elem()) ```
Fetch the AmfType assosciated with a given native type. (i.e., going from a `bool` to an `amf0.Bool`.) ``` typ := DefaultIdentifier.AmfType(true) #=> (reflect.TypeOf(new(amf0.Bool)).Elem()) ```
func NewIdentifier ¶
func NewIdentifier(types ...TypeFactory) *Identifier
NewIdentifier returns a pointer to a new instance of the Identifier type. By calling this method, all of the TypeOf and AmfType permutations are precomputed, saving tiem in the future.
func (*Identifier) NewMatchingType ¶
func (i *Identifier) NewMatchingType(v interface{}) AmfType
NewMatchingType returns a new instance of an AmfType in the same kind as given by v. If no matching type is found, nil is returned instead.
func (*Identifier) NewMatchingTypeFromValue ¶
func (i *Identifier) NewMatchingTypeFromValue(val reflect.Value) AmfType
NewMatchingTypeFromValue returns a new instance of an AmfType in the same kind as given by v. If no matching type is found, nil is returned instead.
func (*Identifier) TypeOf ¶
func (i *Identifier) TypeOf(id byte) AmfType
TypeOf returns the AmfType assosciated with a given marker ID.
type LongString ¶
type LongString string
func NewLongString ¶
func NewLongString(str string) *LongString
func (*LongString) Marker ¶
func (l *LongString) Marker() byte
func (*LongString) Native ¶
func (l *LongString) Native() reflect.Type
type Paired ¶
type Paired struct {
// contains filtered or unexported fields
}
func (*Paired) Bool ¶
Returns a boolean type AMF specified by the key. If the key isn't found it returns a NotFoundError. If it is found but is of the wrong type, this returns a WrongTypeError.
type TypeFactory ¶
type TypeFactory func() AmfType
TypeFactory is a factory type that returns new instances of a specific AmfType.
type UnknownPacketError ¶
type UnknownPacketError byte
func (UnknownPacketError) Error ¶
func (e UnknownPacketError) Error() string