Exemplo n.º 1
0
func TestMarshallingPointerTypes(t *testing.T) {
	buf, err := encoding.Marshal(&struct {
		Foo *amf0.Object
	}{amf0.NewObject()})

	assert.Nil(t, err)
	assert.Equal(t, []byte{0x3, 0x0, 0x0, 0x9}, buf)
}
Exemplo n.º 2
0
func TestMarshallingNilTypes(t *testing.T) {
	buf, err := encoding.Marshal(&struct {
		Foo *amf0.Object
	}{ /* Foo will be a nil pointer */ })

	assert.Nil(t, err)
	assert.Equal(t, []byte{0x05}, buf)
}
Exemplo n.º 3
0
func TestMarshallingNonNativeMembers(t *testing.T) {
	buf, err := encoding.Marshal(&struct {
		Foo amf0.Object
	}{*amf0.NewObject()})

	assert.Nil(t, err)
	assert.Equal(t, []byte{0x3, 0x0, 0x0, 0x9}, buf)
}
Exemplo n.º 4
0
func TestMarshalingNativeMembers(t *testing.T) {
	buf, err := encoding.Marshal(&struct {
		Foo bool
	}{false})

	assert.Nil(t, err)

	assert.Equal(t, byte(0x01), buf[0],
		"amf0/encoding: did not marshal	marker")
	assert.Equal(t, byte(0x00), buf[1],
		"amf0/encoding: did not marshal value")
}
Exemplo n.º 5
0
// Marshal implements the Data.Marshal function.
func (d *DataFrame) Marshal() (*chunk.Chunk, error) {
	m, err := encoding.Marshal(d)
	if err != nil {
		return nil, err
	}

	return &chunk.Chunk{
		Header: &chunk.Header{
			BasicHeader: chunk.BasicHeader{0, 4},
			MessageHeader: chunk.MessageHeader{
				Length:   uint32(len(m)),
				TypeId:   0x12,
				StreamId: 1,
			},
		},
		Data: m,
	}, nil
}
Exemplo n.º 6
0
// Marshal implements Marshallable.Marshal.
func (r *ConnectResponse) Marshal() ([]byte, error) {
	r.ResponseType = SuccessfulResponseType
	return encoding.Marshal(r)
}
Exemplo n.º 7
0
// Marshal implements Marshallable.Marshal.
func (r *CreateStreamResponse) Marshal() ([]byte, error) {
	r.ResponseType = SuccessfulResponseType
	return encoding.Marshal(r)
}
Exemplo n.º 8
0
// Data marshals the data contained in the *Status type, returning either a
// []byte containing that data, or an error if it was unmarshallable.
func (s *Status) Data() ([]byte, error) {
	return encoding.Marshal(s)
}
Exemplo n.º 9
0
	// commands are to be sent over.
	OnStatusMessageStreamId uint32 = 1
	// OnStatusName is the name of the OnStatus command, as used in the
	// CommandHeader type.
	OnStatusName string = "onStatus"

	// Amf0CmdTypeId is the message type ID used to send the OnStatus
	// command in the chunk.
	Amf0CmdTypeId byte = 0x14
)

var (
	// OnStatusCommandHeader is a []byte containing a marshalled version of
	// the CommandHeader attached to all outgoing onStatus commands.
	OnStatusCommandHeader, _ = encoding.Marshal(&CommandHeader{
		Name: OnStatusName,
	})
)

// Status encapsulates the data contained in the body of an OnStatus command.
type Status struct {
	// Arguments correspond to the "arguments" field in the body of an
	// OnStatus command (as defined by the RTMP specification).
	Arguments amf0.Object
}

// NewStatus returns a new instance of the *Status type.
func NewStatus() *Status {
	return &Status{
		Arguments: *amf0.NewObject(),
	}