add pkt_pack_desc_args

isolation_bkp/dynres
Dominik Madarász 2021-05-04 23:12:32 +02:00
parent 55ea1e740f
commit 2094d416c8
2 changed files with 10 additions and 5 deletions

View File

@ -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); 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;
}

View File

@ -1,9 +1,8 @@
#include "pkt_01_welcome.h" #include "pkt_01_welcome.h"
#include "packet_utils.h"
#include "world.h" #include "world.h"
#include "game.h" #include "game.h"
#define PKT_01_WELCOME_ARGC 3
pkt_desc pkt_01_welcome_desc[] = { 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, block_size) },
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_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) { size_t pkt_01_welcome_encode(pkt_01_welcome *table) {
cw_pack_context pc = {0}; 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)); pkt_pack_struct(&pc, pkt_01_welcome_desc, PKT_STRUCT_PTR(table));
return pkt_pack_msg_size(&pc); return pkt_pack_msg_size(&pc);
} }
int32_t pkt_01_welcome_handler(pkt_header *header) { int32_t pkt_01_welcome_handler(pkt_header *header) {
pkt_01_welcome table; 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); zpl_printf("we received: block_size: %d, chunk_size: %d and world_size: %d\n", table.block_size, table.chunk_size, table.world_size);