1 Star 0 Fork 1

晨雯熙/FileServer

forked from openes/FileServer 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
msg.c 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
稀风 提交于 2023-08-12 15:22 +08:00 . 应用层协议设计与实现:协议实现
/******************************************************************************
* 文件名称: msg.c
* 内容摘要: 消息处理
* 创建者の: 孔佳伟
* 个人主页: https://gitee.com/thin-wind/jump
* 修改记录:
******************************************************************************/
#include "msg.h"
#include <string.h>
#include <stdlib.h>
/******************************************************************************
* 函数名称: MESSAGE* MessageNew(uint16_t type,
uint16_t cmd,
uint16_t index,
uint16_t total,
const uint8_t* payload,
uint32_t length)
* 功能说明: 创建消息对象
* 输入参数: uint16_t type --类型
    uint16_t cmd --指令
    uint16_t index --数据包序号索引
    uint16_t total --数据总包数
    const uint8_t* payload --数据区首地址
    uint32_t length --数据长度
* 输出参数: 无
* 函数返回: 无
* 其它说明: 无
******************************************************************************/
MESSAGE* MessageNew(uint16_t type,
uint16_t cmd,
uint16_t index,
uint16_t total,
const uint8_t* payload,
uint32_t length)
{
MESSAGE* msg = malloc(sizeof(MESSAGE) + length);
if(NULL == msg)
return NULL;
if(NULL == payload)
return NULL;
msg->type = type;
msg->cmd = cmd;
msg->index = index;
msg->total = total;
msg->length = length;
// msg 是 MESSAGE 类型的,msg+1 则指向 msg->payload,注意柔性数组本身并不占用内存空间
if(NULL != payload)
memcpy(msg + 1, payload, length);
return msg;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/worktom/FileServer.git
git@gitee.com:worktom/FileServer.git
worktom
FileServer
FileServer
main

搜索帮助