From 7311b761b249d43378451a591a47ea5f9c6592e9 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Tue, 15 Aug 2023 13:16:29 +0500 Subject: [PATCH] Fixed cyclic package dep --- rtmp/amf/command.go | 7 ++----- rtmp/amf/encode.go | 8 +++----- rtmp/chunk_wrap.go | 5 ++++- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/rtmp/amf/command.go b/rtmp/amf/command.go index d09f11f..31a1889 100644 --- a/rtmp/amf/command.go +++ b/rtmp/amf/command.go @@ -33,7 +33,7 @@ func (amf_obj_root AMFObj) ProcessConnect() (err error) { return } -func EncodeConnectResponse(msg_ptr *Message) (error) { +func EncodeConnectResponse() ([]byte, error) { amf_root_obj := make(AMFObj) amf_root_obj[0] = "_result" amf_root_obj[1] = 1.0 @@ -50,8 +50,5 @@ func EncodeConnectResponse(msg_ptr *Message) (error) { amf_event_obj["description"] = "Connection Succeeded" amf_event_obj["objectEncoding"] = 0.0 - if err := Encode(amf_root_obj, msg_ptr); err != nil { - return err - } - return nil + return Encode(amf_root_obj) } diff --git a/rtmp/amf/encode.go b/rtmp/amf/encode.go index b354edd..b2589da 100644 --- a/rtmp/amf/encode.go +++ b/rtmp/amf/encode.go @@ -6,18 +6,16 @@ import ( "errors" ) -func Encode(amf_root_obj AMFObj, msg_ptr *Message) (error) { +func Encode(amf_root_obj AMFObj) ([]byte, error) { tmp_buffer := make([]byte, 1024) bytes_encoded := 0 for i := 0; i < len(amf_root_obj); i++ { if err := encode_next(amf_root_obj[i], &tmp_buffer, &bytes_encoded); err != nil { - return err + return tmp_buffer[:bytes_encoded], err } } - msg_ptr.msg_len = bytes_encoded - msg_ptr.data = tmp_buffer[:bytes_encoded] - return nil + return tmp_buffer[:bytes_encoded], nil } func encode_number(num_to_enc float64, tmp_buffer *[]byte, bytes_encoded *int) { diff --git a/rtmp/chunk_wrap.go b/rtmp/chunk_wrap.go index 14f4fa1..1abdad1 100644 --- a/rtmp/chunk_wrap.go +++ b/rtmp/chunk_wrap.go @@ -127,9 +127,12 @@ func (chnk_wrp_ptr *ChunkWrapper) WriteChunkSize() (error) { func (chnk_wrp_ptr *ChunkWrapper) WriteConnectResponse() (error) { msg_ptr := new(Message) msg_ptr.msg_type = 20 - if err := amf.EncodeConnectResponse(msg_ptr); err != nil { + msg_data, err := amf.EncodeConnectResponse() + if err != nil { return err } + msg_ptr.msg_len = uint32(len(msg_data)) + msg_ptr.data = msg_data if err := chnk_wrp_ptr.WriteChunk(3, 0, msg_ptr); err != nil { return err }