Пример #1
0
func ExampleAmf0EcmaArray_MarshalBinary() {
	s := protocol.NewAmf0EcmaArray()

	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 ecma array")

	// Output:
	// 35
	// amf0 ecma array
}
Пример #2
0
func ExampleAmf0EcmaArray_UnmarshalBinary() {
	b := []byte{8, 0, 0, 0, 0, 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 ecma-array to init the properties.
	s := protocol.NewAmf0EcmaArray()
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println("amf0 ecma array")

	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 ecma array
	// value string: oryx
	// value number: 2015
}