Beispiel #1
0
func ExampleAmf0Object_MarshalBinary() {
	s := protocol.NewAmf0Object()

	s.Set("pj", protocol.NewAmf0String("oryx"))
	s.Set("start", protocol.NewAmf0Number(2015))

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println("amf0 object")

	// Output:
	// 31
	// amf0 object
}
Beispiel #2
0
func ExampleAmf0Object_UnmarshalBinary() {
	b := []byte{3, 0, 2, 'p', 'j', 2, 0, 4, 'o', 'r', 'y', 'x', 0, 5, 's', 't', 'a', 'r', 't', 0, 64, 159, 124, 0, 0, 0, 0, 0, 0, 0, 9} // read from network

	// must always new the amf0 object to init the properties.
	s := protocol.NewAmf0Object()
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println("amf0 object")

	if v, ok := s.Get("pj").(*protocol.Amf0String); ok {
		fmt.Println("value string:", string(*v))
	}
	if v, ok := s.Get("start").(*protocol.Amf0Number); ok {
		fmt.Println("value number:", float64(*v))
	}

	// Output:
	// amf0 object
	// value string: oryx
	// value number: 2015
}