add pkt_pack_desc_args
parent
55ea1e740f
commit
2094d416c8
|
@ -100,3 +100,9 @@ inline int32_t pkt_msg_decode(pkt_header *header, pkt_desc* desc, uint32_t args,
|
|||
|
||||
return pkt_validate_eof_msg(&uc);
|
||||
}
|
||||
|
||||
inline size_t pkt_pack_desc_args(pkt_desc *desc) {
|
||||
size_t cnt = 0;
|
||||
for (pkt_desc *field = desc; field->type != CWP_NOT_AN_ITEM; ++field, ++cnt) {}
|
||||
return cnt;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#include "pkt_01_welcome.h"
|
||||
#include "packet_utils.h"
|
||||
#include "world.h"
|
||||
#include "game.h"
|
||||
|
||||
#define PKT_01_WELCOME_ARGC 3
|
||||
|
||||
pkt_desc pkt_01_welcome_desc[] = {
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, block_size) },
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_size) },
|
||||
|
@ -13,14 +12,14 @@ pkt_desc pkt_01_welcome_desc[] = {
|
|||
|
||||
size_t pkt_01_welcome_encode(pkt_01_welcome *table) {
|
||||
cw_pack_context pc = {0};
|
||||
pkt_pack_msg(&pc, PKT_01_WELCOME_ARGC);
|
||||
pkt_pack_msg(&pc, pkt_pack_desc_args(pkt_01_welcome_desc));
|
||||
pkt_pack_struct(&pc, pkt_01_welcome_desc, PKT_STRUCT_PTR(table));
|
||||
return pkt_pack_msg_size(&pc);
|
||||
}
|
||||
|
||||
int32_t pkt_01_welcome_handler(pkt_header *header) {
|
||||
pkt_01_welcome table;
|
||||
PKT_IF(pkt_msg_decode(header, pkt_01_welcome_desc, PKT_01_WELCOME_ARGC, PKT_STRUCT_PTR(&table)));
|
||||
PKT_IF(pkt_msg_decode(header, pkt_01_welcome_desc, pkt_pack_desc_args(pkt_01_welcome_desc), PKT_STRUCT_PTR(&table)));
|
||||
|
||||
zpl_printf("we received: block_size: %d, chunk_size: %d and world_size: %d\n", table.block_size, table.chunk_size, table.world_size);
|
||||
|
||||
|
|
Loading…
Reference in New Issue