2、关于协议数据包的设计

2.1、 数据包packet定义

padding部分为来适应不同的接口。

typedef struct __attribute__((__packed__)) {
    uint8_t padding[xsp_PADDING_BYTES];
    uint16_t length;                
    xsp_id_t id;                    
    union {
       uint8_t data[0];
       uint16_t data16[0];
       uint32_t data32[0];      
    };
} xsp_packet_t;

2.2、 数据包头部设置

This define must be equal to the size of the packet overhead in csp_packet_t.
It is used in csp_buffer_get() to check the allocated buffer size against the required buffer size.
分配的缓冲区的大小应该注意数据和头部大小,初始化时要求的字节加上数据包头部字节才是真的缓冲区大小。

#define CSP_BUFFER_PACKET_OVERHEAD  (sizeof(csp_packet_t) - sizeof(((csp_packet_t *)0)->data))
posted @ 2020-02-11 16:00  khldragon  阅读(191)  评论(0编辑  收藏  举报