Exemple #1
0
// marshal multiple objects to buffer.
func ExampleMarshal() {
	// objects to marshal
	var x core.Marshaler // for example NewAmf0String("oryx")
	var y core.Marshaler // for example NewAmf0Number(1.0)

	var b bytes.Buffer // marshal objects to b

	if err := core.Marshal(x, &b); err != nil {
		_ = err // when error.
	}
	if err := core.Marshal(y, &b); err != nil {
		_ = err // when error.
	}

	_ = b.Bytes() // use the bytes contains x and y
}
Exemple #2
0
func (v *Amf0Object) MarshalBinary() (data []byte, err error) {
	var b bytes.Buffer

	if err = b.WriteByte(MarkerAmf0Object); err != nil {
		return
	}

	if err = core.Marshal(v.properties, &b); err != nil {
		return
	}

	return b.Bytes(), nil
}
Exemple #3
0
func (v *amf0Properties) MarshalBinary() (data []byte, err error) {
	var b bytes.Buffer

	// properties.
	for _, e := range v.properties {
		if err = core.Marshal(&e.key, &b); err != nil {
			return
		}
		if err = core.Marshal(e.value, &b); err != nil {
			return
		}
	}

	// EOF.
	if _, err = b.Write([]byte{0, 0}); err != nil {
		return
	}

	if err = core.Marshal(&v.eof, &b); err != nil {
		return
	}

	return b.Bytes(), nil
}
Exemple #4
0
func (v *Amf0EcmaArray) MarshalBinary() (data []byte, err error) {
	var b bytes.Buffer

	if err = b.WriteByte(MarkerAmf0EcmaArray); err != nil {
		return
	}

	var count uint32
	if err = binary.Write(&b, binary.BigEndian, count); err != nil {
		return
	}

	if err = core.Marshal(v.properties, &b); err != nil {
		return
	}

	return b.Bytes(), nil
}
Exemple #5
0
func (v *Amf0StrictArray) MarshalBinary() (data []byte, err error) {
	var b bytes.Buffer

	if err = b.WriteByte(MarkerAmf0StrictArray); err != nil {
		return
	}

	var count uint32 = uint32(len(v.properties))
	if err = binary.Write(&b, binary.BigEndian, count); err != nil {
		return
	}

	for _, e := range v.properties {
		if err = core.Marshal(e, &b); err != nil {
			return
		}
	}

	return b.Bytes(), nil
}