Fixed cyclic package dep

This commit is contained in:
Muaz Ahmad 2023-08-15 13:16:29 +05:00
parent d1b5ade036
commit 7311b761b2
3 changed files with 9 additions and 11 deletions

View file

@ -33,7 +33,7 @@ func (amf_obj_root AMFObj) ProcessConnect() (err error) {
return return
} }
func EncodeConnectResponse(msg_ptr *Message) (error) { func EncodeConnectResponse() ([]byte, error) {
amf_root_obj := make(AMFObj) amf_root_obj := make(AMFObj)
amf_root_obj[0] = "_result" amf_root_obj[0] = "_result"
amf_root_obj[1] = 1.0 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["description"] = "Connection Succeeded"
amf_event_obj["objectEncoding"] = 0.0 amf_event_obj["objectEncoding"] = 0.0
if err := Encode(amf_root_obj, msg_ptr); err != nil { return Encode(amf_root_obj)
return err
}
return nil
} }

View file

@ -6,18 +6,16 @@ import (
"errors" "errors"
) )
func Encode(amf_root_obj AMFObj, msg_ptr *Message) (error) { func Encode(amf_root_obj AMFObj) ([]byte, error) {
tmp_buffer := make([]byte, 1024) tmp_buffer := make([]byte, 1024)
bytes_encoded := 0 bytes_encoded := 0
for i := 0; i < len(amf_root_obj); i++ { for i := 0; i < len(amf_root_obj); i++ {
if err := encode_next(amf_root_obj[i], &tmp_buffer, &bytes_encoded); err != nil { 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 return tmp_buffer[:bytes_encoded], nil
msg_ptr.data = tmp_buffer[:bytes_encoded]
return nil
} }
func encode_number(num_to_enc float64, tmp_buffer *[]byte, bytes_encoded *int) { func encode_number(num_to_enc float64, tmp_buffer *[]byte, bytes_encoded *int) {

View file

@ -127,9 +127,12 @@ func (chnk_wrp_ptr *ChunkWrapper) WriteChunkSize() (error) {
func (chnk_wrp_ptr *ChunkWrapper) WriteConnectResponse() (error) { func (chnk_wrp_ptr *ChunkWrapper) WriteConnectResponse() (error) {
msg_ptr := new(Message) msg_ptr := new(Message)
msg_ptr.msg_type = 20 msg_ptr.msg_type = 20
if err := amf.EncodeConnectResponse(msg_ptr); err != nil { msg_data, err := amf.EncodeConnectResponse()
if err != nil {
return err 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 { if err := chnk_wrp_ptr.WriteChunk(3, 0, msg_ptr); err != nil {
return err return err
} }