You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: msgcodec.go
    path of file: ./repos/cellnet/codec
    
    the code of the file until where you have to start completion: package codec

import (
	"github.com/davyxu/cellnet"
)

// 编码消息, 在使用了带内存池的codec中，可以传入session或peer的ContextSet，保存内存池上下文，默认ctx传nil
func EncodeMessage(msg interface{}, ctx cellnet.ContextSet) (data []byte, meta *cellnet.MessageMeta, err error) {

	// 获取消息元
    
func EncodeMessage(msg interface{}, ctx cellnet.ContextSet) (data []byte, meta *cellnet.MessageMeta, err error) {

	// 获取消息元信息
	meta = cellnet.MessageMetaByMsg(msg)
	if meta == nil {
		return nil, nil, cellnet.NewErrorContext("msg not exists", msg)
	}

	// 将消息编码为字节数组
	var raw interface{}
	raw, err = meta.Codec.Encode(msg, ctx)

	if err != nil {
		return
	}

	data = raw.([]byte)

	return
}