code: func (*MsgCodec) EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) {
  	if msg == nil {
  		return nil, errors.New("nil message passed in")
  	}
  
  	// try to recover panic which might possibly occur in struc.Pack call
  	defer func() {
  		if r := recover(); r != nil {
  			var ok bool
  			if err, ok = r.(error); !ok {
  				err = fmt.Errorf("%v", r)
  			}
  			err = fmt.Errorf("panic occurred: %v", err)
  		}
  	}()
  
  	var header interface{}
  
  	// encode message header
  	switch msg.GetMessageType() {
  	case api.RequestMessage:
  		header = &VppRequestHeader{VlMsgID: msgID}
  	case api.ReplyMessage:
  		header = &VppReplyHeader{VlMsgID: msgID}
  	case api.EventMessage:
  		header = &VppEventHeader{VlMsgID: msgID}
  	default:
  		header = &VppOtherHeader{VlMsgID: msgID}
  	}
  
  	buf := new(bytes.Buffer)
  
  	// encode message header
  	if err := struc.Pack(buf, header); err != nil {
  		return nil, fmt.Errorf("failed to encode message header: %+v, error: %v", header, err)
  	}
  
  	// encode message content
  	if reflect.TypeOf(msg).Elem().NumField() > 0 {
  		if err := struc.Pack(buf, msg); err != nil {
  			return nil, fmt.Errorf("failed to encode message data: %+v, error: %v", data, err)
  		}
  	}
  
  	return buf.Bytes(), nil
  }
docs: // EncodeMsg encodes provided `Message` structure into its binary-encoded data representation.