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;
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))
原文:https://www.cnblogs.com/khldragon/p/2-guan-yu-xie-yi-shu-ju-bao-de-she-ji.html