Exemple #1
0
func (v *amf0Properties) UnmarshalBinary(data []byte) (err error) {
	b := bytes.NewBuffer(data)

	for b.Len() > 0 {
		var key amf0Utf8
		if err = core.Unmarshal(&key, b); err != nil {
			return
		}

		var value Amf0Any
		if value, err = Amf0Discovery(b.Bytes()); err != nil {
			return
		}
		if err = core.Unmarshal(value, b); err != nil {
			return
		}

		// EOF.
		if _, ok := value.(*amf0ObjectEOF); ok && len(key) == 0 {
			break
		}

		v.Set(string(key), value)
	}

	return
}
Exemple #2
0
func (v *Amf0StrictArray) UnmarshalBinary(data []byte) (err error) {
	b := bytes.NewBuffer(data)

	var m byte
	if m, err = b.ReadByte(); err != nil {
		return
	}

	if m != MarkerAmf0StrictArray {
		return Amf0Error
	}

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

	for i := 0; i < int(count); i++ {
		var a Amf0Any
		if a, err = Amf0Discovery(b.Bytes()); err != nil {
			return
		}

		if err = core.Unmarshal(a, b); err != nil {
			return
		}

		v.Add(a)
	}

	return
}
Exemple #3
0
// unmarshal multiple objects from buffer
func ExampleUnmarshal() {
	var b bytes.Buffer // read from network.

	var x core.UnmarshalSizer // for example Amf0String
	var y core.UnmarshalSizer // for example Amf0Number

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

	// use x and y.
	_ = x
	_ = y
}
Exemple #4
0
func (v *Amf0Object) UnmarshalBinary(data []byte) (err error) {
	b := bytes.NewBuffer(data)

	var m byte
	if m, err = b.ReadByte(); err != nil {
		return
	}

	if m != MarkerAmf0Object {
		return Amf0Error
	}

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

	return
}
Exemple #5
0
func (v *Amf0EcmaArray) UnmarshalBinary(data []byte) (err error) {
	b := bytes.NewBuffer(data)

	var m byte
	if m, err = b.ReadByte(); err != nil {
		return
	}

	if m != MarkerAmf0EcmaArray {
		return Amf0Error
	}

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

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

	return
}