From 985a4cb5f2102ca0972726109c34be9ed30d4fd8 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 2 Jun 2013 15:49:09 +0200 Subject: [PATCH] marshal: provide type-specific serialization/unserialization functions Those functions should be used in place of `marshal_serialize()` and `marshal_unserialize()` if possible. --- src/daemon/client.c | 20 +++----- src/daemon/event.c | 3 +- src/daemon/lldpd.c | 2 +- src/lldpd-structs.h | 24 +++++----- src/marshal.h | 33 ++++++++++++-- tests/check_marshal.c | 104 ++++++++++++++++-------------------------- 6 files changed, 88 insertions(+), 98 deletions(-) diff --git a/src/daemon/client.c b/src/daemon/client.c index 000e3647..58a3b50e 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -33,7 +33,7 @@ client_handle_get_configuration(struct lldpd *cfg, enum hmsg_type *type, { ssize_t output_len; log_debug("rpc", "client requested configuration"); - output_len = marshal_serialize(lldpd_config, &cfg->g_config, output); + output_len = lldpd_config_serialize(&cfg->g_config, output); if (output_len <= 0) { output_len = 0; *type = NONE; @@ -47,16 +47,14 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { struct lldpd_config *config; - void *p; log_debug("rpc", "client request a change in configuration"); /* Get the proposed configuration. */ - if (marshal_unserialize(lldpd_config, input, input_len, &p) <= 0) { + if (lldpd_config_unserialize(input, input_len, &config) <= 0) { *type = NONE; return 0; } - config = p; - + /* What needs to be done? Transmit delay? */ if (config->c_tx_interval > 0) { log_debug("rpc", "client change transmit interval to %d", @@ -133,7 +131,7 @@ client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, TAILQ_INSERT_TAIL(&ifs, iff, next); } - output_len = marshal_serialize(lldpd_interface_list, &ifs, output); + output_len = lldpd_interface_list_serialize(&ifs, output); if (output_len <= 0) { output_len = 0; *type = NONE; @@ -160,21 +158,19 @@ client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { char *name; - void *p; struct lldpd_hardware *hardware; /* Get name of the interface */ - if (marshal_unserialize(string, input, input_len, &p) <= 0) { + if (string_unserialize(input, input_len, &name) <= 0) { *type = NONE; return 0; } - name = p; /* Search appropriate hardware */ log_debug("rpc", "client request interface %s", name); TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) if (!strcmp(hardware->h_ifname, name)) { - int output_len = marshal_serialize(lldpd_hardware, hardware, output); + int output_len = lldpd_hardware_serialize(hardware, output); free(name); if (output_len <= 0) { *type = NONE; @@ -198,18 +194,16 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { int ret = 0; - void *p; struct lldpd_port_set *set = NULL; struct lldpd_hardware *hardware = NULL; #ifdef ENABLE_LLDPMED struct lldpd_med_loc *loc = NULL; #endif - if (marshal_unserialize(lldpd_port_set, input, input_len, &p) <= 0) { + if (lldpd_port_set_unserialize(input, input_len, &set) <= 0) { *type = NONE; return 0; } - set = p; if (!set->ifname) { log_warnx("rpc", "no interface provided"); goto set_port_finished; diff --git a/src/daemon/event.c b/src/daemon/event.c index d603c5bf..1871b3b2 100644 --- a/src/daemon/event.c +++ b/src/daemon/event.c @@ -255,8 +255,7 @@ levent_ctl_notify(char *ifname, int state, struct lldpd_port *neighbor) sizeof(backup_p_entries)); memset(&neighbor->p_entries, 0, sizeof(backup_p_entries)); - output_len = marshal_serialize(lldpd_neighbor_change, - &neigh, &output); + output_len = lldpd_neighbor_change_serialize(&neigh, &output); memcpy(&neighbor->p_entries, &backup_p_entries, sizeof(backup_p_entries)); diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 9957f039..2431d683 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -240,7 +240,7 @@ lldpd_reset_timer(struct lldpd *cfg) char save[offsetof(struct lldpd_port, p_id_subtype)]; memcpy(save, port, sizeof(save)); memset(port, 0, sizeof(save)); - output_len = marshal_serialize(lldpd_port, port, (void**)&output); + output_len = lldpd_port_serialize(port, (void**)&output); memcpy(port, save, sizeof(save)); if (output_len == -1) { log_warnx("localchassis", diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index 69e9fffb..f2d25add 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -50,7 +50,7 @@ struct lldpd_ppvid { }; MARSHAL_BEGIN(lldpd_ppvid) MARSHAL_TQE(lldpd_ppvid, p_entries) -MARSHAL_END; +MARSHAL_END(lldpd_ppvid); struct lldpd_vlan { TAILQ_ENTRY(lldpd_vlan) v_entries; @@ -60,7 +60,7 @@ struct lldpd_vlan { MARSHAL_BEGIN(lldpd_vlan) MARSHAL_TQE(lldpd_vlan, v_entries) MARSHAL_STR(lldpd_vlan, v_name) -MARSHAL_END; +MARSHAL_END(lldpd_vlan); struct lldpd_pi { TAILQ_ENTRY(lldpd_pi) p_entries; @@ -70,7 +70,7 @@ struct lldpd_pi { MARSHAL_BEGIN(lldpd_pi) MARSHAL_TQE(lldpd_pi, p_entries) MARSHAL_FSTR(lldpd_pi, p_pi, p_pi_len) -MARSHAL_END; +MARSHAL_END(lldpd_pi); #endif #ifdef ENABLE_LLDPMED @@ -93,7 +93,7 @@ struct lldpd_med_loc { }; MARSHAL_BEGIN(lldpd_med_loc) MARSHAL_FSTR(lldpd_med_loc, data, data_len) -MARSHAL_END; +MARSHAL_END(lldpd_med_loc); struct lldpd_med_power { u_int8_t devicetype; /* PD or PSE */ @@ -161,7 +161,7 @@ struct lldpd_mgmt { }; MARSHAL_BEGIN(lldpd_mgmt) MARSHAL_TQE(lldpd_mgmt, m_entries) -MARSHAL_END; +MARSHAL_END(lldpd_mgmt); struct lldpd_chassis { TAILQ_ENTRY(lldpd_chassis) c_entries; @@ -212,7 +212,7 @@ MARSHAL_STR(lldpd_chassis, c_med_manuf) MARSHAL_STR(lldpd_chassis, c_med_model) MARSHAL_STR(lldpd_chassis, c_med_asset) #endif -MARSHAL_END; +MARSHAL_END(lldpd_chassis); struct lldpd_port { @@ -270,7 +270,7 @@ MARSHAL_SUBTQ(lldpd_port, lldpd_vlan, p_vlans) MARSHAL_SUBTQ(lldpd_port, lldpd_ppvid, p_ppvids) MARSHAL_SUBTQ(lldpd_port, lldpd_pi, p_pids) #endif -MARSHAL_END; +MARSHAL_END(lldpd_port); /* Used to modify some port related settings */ struct lldpd_port_set { @@ -294,7 +294,7 @@ MARSHAL_POINTER(lldpd_port_set, lldpd_med_power, med_power) #ifdef ENABLE_DOT3 MARSHAL_POINTER(lldpd_port_set, lldpd_dot3_power, dot3_power) #endif -MARSHAL_END; +MARSHAL_END(lldpd_port_set); /* Smart mode / Hide mode */ #define SMART_INCOMING_FILTER (1<<0) /* Incoming filtering enabled */ @@ -339,7 +339,7 @@ MARSHAL_STR(lldpd_config, c_cid_pattern) MARSHAL_STR(lldpd_config, c_iface_pattern) MARSHAL_STR(lldpd_config, c_platform) MARSHAL_STR(lldpd_config, c_description) -MARSHAL_END; +MARSHAL_END(lldpd_config); struct lldpd_frame { int size; @@ -406,7 +406,7 @@ MARSHAL_IGNORE(lldpd_hardware, h_data) MARSHAL_IGNORE(lldpd_hardware, h_cfg) MARSHAL_SUBSTRUCT(lldpd_hardware, lldpd_port, h_lport) MARSHAL_SUBTQ(lldpd_hardware, lldpd_port, h_rports) -MARSHAL_END; +MARSHAL_END(lldpd_hardware); struct lldpd_interface { TAILQ_ENTRY(lldpd_interface) next; @@ -415,7 +415,7 @@ struct lldpd_interface { MARSHAL_BEGIN(lldpd_interface) MARSHAL_TQE(lldpd_interface, next) MARSHAL_STR(lldpd_interface, name) -MARSHAL_END; +MARSHAL_END(lldpd_interface); TAILQ_HEAD(lldpd_interface_list, lldpd_interface); MARSHAL_TQ(lldpd_interface_list, lldpd_interface); @@ -430,7 +430,7 @@ struct lldpd_neighbor_change { MARSHAL_BEGIN(lldpd_neighbor_change) MARSHAL_STR(lldpd_neighbor_change, ifname) MARSHAL_POINTER(lldpd_neighbor_change, lldpd_port, neighbor) -MARSHAL_END; +MARSHAL_END(lldpd_neighbor_change); /* Cleanup functions */ void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *); diff --git a/src/marshal.h b/src/marshal.h index 0c4ad69b..7c4f6310 100644 --- a/src/marshal.h +++ b/src/marshal.h @@ -57,6 +57,23 @@ extern struct marshal_info marshal_info_ignore; marshal. The marshalled type has to be a structure. */ #define MARSHAL_INFO(type) marshal_info_##type #ifdef MARSHAL_EXPORT +#define MARSHAL_HELPER_FUNCTIONS(type, ttype) \ + ssize_t \ + type ## _serialize(ttype *source, void *buffer) { \ + return marshal_serialize(type, \ + source, buffer); \ + } \ + size_t \ + type ## _unserialize(void *buffer, size_t len, \ + ttype **destination) { \ + void *p; \ + size_t rc; \ + rc = marshal_unserialize(type, \ + buffer, len, &p); \ + if (rc <= 0) return rc; \ + *destination = p; \ + return rc; \ + } #define MARSHAL_BEGIN(type) struct marshal_info MARSHAL_INFO(type) = \ { \ .name = #type, \ @@ -72,12 +89,16 @@ extern struct marshal_info marshal_info_ignore; .offset2 = offsetof(struct type, len), \ .kind = pointer, \ .mi = &marshal_info_fstring }, -#define MARSHAL_END MARSHAL_SUBINFO_NULL }} +#define MARSHAL_END(type) MARSHAL_SUBINFO_NULL }}; \ + MARSHAL_HELPER_FUNCTIONS(type, struct type) #else -#define MARSHAL_BEGIN(type) extern struct marshal_info MARSHAL_INFO(type) +#define MARSHAL_HELPER_FUNCTIONS(type, ttype) \ + ssize_t type ## _serialize(ttype*, void*); \ + size_t type ## _unserialize(void*, size_t, ttype**); +#define MARSHAL_BEGIN(type) extern struct marshal_info MARSHAL_INFO(type); #define MARSHAL_ADD(...) #define MARSHAL_FSTR(...) -#define MARSHAL_END +#define MARSHAL_END(type) MARSHAL_HELPER_FUNCTIONS(type, struct type) #endif /* Shortcuts */ #define MARSHAL_POINTER(...) MARSHAL_ADD(pointer, ##__VA_ARGS__) @@ -99,11 +120,11 @@ extern struct marshal_info marshal_info_ignore; MARSHAL_IGNORE(type, field.tqh_last) #define MARSHAL(type) \ MARSHAL_BEGIN(type) \ - MARSHAL_END + MARSHAL_END(type) #define MARSHAL_TQ(type, subtype) \ MARSHAL_BEGIN(type) \ MARSHAL_TQH(type, subtype) \ - MARSHAL_END + MARSHAL_END(type) /* Serialization */ ssize_t marshal_serialize_(struct marshal_info *, void *, void **, int, void *, int) @@ -116,4 +137,6 @@ size_t marshal_unserialize_(struct marshal_info *, void *, size_t, void **, voi #define marshal_unserialize(type, o, l, input) \ marshal_unserialize_(&MARSHAL_INFO(type), o, l, input, NULL, 0, 0) +MARSHAL_HELPER_FUNCTIONS(string, char) + #endif diff --git a/tests/check_marshal.c b/tests/check_marshal.c index 5dd40fc9..967f4e5d 100644 --- a/tests/check_marshal.c +++ b/tests/check_marshal.c @@ -33,16 +33,14 @@ START_TEST(test_simple_structure) { .a5 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G'}, }; struct struct_simple *destination; - void *p; void *buffer; size_t len, len2; - len = marshal_serialize(struct_simple, &source, &buffer); + len = struct_simple_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct struct_simple)); - len2 = marshal_unserialize(struct_simple, buffer, len, &p); + len2 = struct_simple_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); - destination = p; free(buffer); ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->a1, 78452); @@ -67,7 +65,7 @@ struct struct_sub { }; MARSHAL_BEGIN(struct_sub) MARSHAL_SUBSTRUCT(struct_sub, struct_simple, e2) -MARSHAL_END; +MARSHAL_END(struct_sub); START_TEST(test_substruct_structure) { struct struct_sub source = { @@ -83,17 +81,15 @@ START_TEST(test_substruct_structure) { }; struct struct_sub *destination; - void *p; void *buffer; size_t len, len2; - len = marshal_serialize(struct_sub, &source, &buffer); + len = struct_sub_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct struct_sub)); - len2 = marshal_unserialize(struct_sub, buffer, len, &p); + len2 = struct_sub_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->e1, -5122); ck_assert_int_eq(destination->e2.a1, 78452); @@ -121,7 +117,7 @@ struct struct_onepointer { }; MARSHAL_BEGIN(struct_onepointer) MARSHAL_POINTER(struct_onepointer, struct_simple, b4) -MARSHAL_END; +MARSHAL_END(struct_onepointer); START_TEST(test_pointer_structure) { struct struct_simple source_simple = { @@ -140,18 +136,16 @@ START_TEST(test_pointer_structure) { }; struct struct_onepointer *destination; - void *p; void *buffer; size_t len, len2; - len = marshal_serialize(struct_onepointer, &source, &buffer); + len = struct_onepointer_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source_simple, 0, sizeof(struct struct_simple)); memset(&source, 0, sizeof(struct struct_onepointer)); - len2 = marshal_unserialize(struct_onepointer, buffer, len, &p); + len2 = struct_onepointer_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->b1, 18); ck_assert_int_eq(destination->b2, 15454); @@ -182,7 +176,7 @@ struct struct_nestedpointers { MARSHAL_BEGIN(struct_nestedpointers) MARSHAL_POINTER(struct_nestedpointers, struct_simple, c3) MARSHAL_POINTER(struct_nestedpointers, struct_onepointer, c4) -MARSHAL_END; +MARSHAL_END(struct_nestedpointers); START_TEST(test_several_pointers_structure) { struct struct_simple source_simple1 = { @@ -215,20 +209,18 @@ START_TEST(test_several_pointers_structure) { }; struct struct_nestedpointers *destination; - void *p; void *buffer; size_t len, len2; - len = marshal_serialize(struct_nestedpointers, &source, &buffer); + len = struct_nestedpointers_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source_simple1, 0, sizeof(struct struct_simple)); memset(&source_simple2, 0, sizeof(struct struct_simple)); memset(&source_onepointer, 0, sizeof(struct struct_onepointer)); memset(&source, 0, sizeof(struct struct_nestedpointers)); - len2 = marshal_unserialize(struct_nestedpointers, buffer, len, &p); + len2 = struct_nestedpointers_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->c1, 4542); ck_assert_int_eq(destination->c2, 5665454); @@ -276,18 +268,16 @@ START_TEST(test_null_pointers) { }; struct struct_nestedpointers *destination; - void *p; void *buffer; size_t len, len2; - len = marshal_serialize(struct_nestedpointers, &source, &buffer); + len = struct_nestedpointers_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source_simple2, 0, sizeof(struct struct_simple)); memset(&source, 0, sizeof(struct struct_nestedpointers)); - len2 = marshal_unserialize(struct_nestedpointers, buffer, len, &p); + len2 = struct_nestedpointers_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->c1, 4542); ck_assert_int_eq(destination->c2, 5665454); @@ -313,7 +303,7 @@ MARSHAL_BEGIN(struct_multipleref) MARSHAL_POINTER(struct_multipleref, struct_simple, f2) MARSHAL_POINTER(struct_multipleref, struct_simple, f3) MARSHAL_POINTER(struct_multipleref, struct_nestedpointers, f4) -MARSHAL_END; +MARSHAL_END(struct_multipleref); START_TEST(test_multiple_references) { struct struct_simple source_simple = { @@ -335,20 +325,18 @@ START_TEST(test_multiple_references) { }; struct struct_multipleref *destination; - void *p; void *buffer = NULL; size_t len, len2; - len = marshal_serialize(struct_multipleref, &source, &buffer); + len = struct_multipleref_serialize(&source, &buffer); fail_unless(buffer != NULL, "Buffer is empty"); fail_unless(len > 0, "Unable to serialize"); memset(&source_simple, 0, sizeof(struct struct_simple)); memset(&source_nested, 0, sizeof(struct struct_nestedpointers)); memset(&source, 0, sizeof(struct struct_multipleref)); - len2 = marshal_unserialize(struct_multipleref, buffer, len, &p); + len2 = struct_multipleref_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->f1, 15); ck_assert_int_eq(destination->f2, destination->f3); @@ -368,7 +356,7 @@ struct struct_circularref { }; MARSHAL_BEGIN(struct_circularref) MARSHAL_POINTER(struct_circularref, struct_circularref, g2) -MARSHAL_END; +MARSHAL_END(struct_circularref); START_TEST(test_circular_references) { struct struct_circularref source = { @@ -377,17 +365,15 @@ START_TEST(test_circular_references) { }; struct struct_circularref *destination; - void *p; void *buffer = NULL; size_t len, len2; - len = marshal_serialize(struct_circularref, &source, &buffer); + len = struct_circularref_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct struct_circularref)); - len2 = marshal_unserialize(struct_circularref, buffer, len, &p); + len2 = struct_circularref_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->g1, 42); ck_assert_int_eq(destination->g2->g1, 42); @@ -407,14 +393,13 @@ START_TEST(test_too_small_unmarshal) { }; struct struct_nestedpointers *destination; - void *p; void *buffer; size_t len, len2; int i, j; log_register(donothing); - len = marshal_serialize(struct_nestedpointers, &source, &buffer); + len = struct_nestedpointers_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source_simple1, 0, sizeof(struct struct_simple)); memset(&source_onepointer, 0, sizeof(struct struct_onepointer)); @@ -422,15 +407,14 @@ START_TEST(test_too_small_unmarshal) { /* Loop 30 times to ease debugging leaks with valgrind */ for (j = 0; j < 30; j++) { for (i = 0; i < len; i++) { - len2 = marshal_unserialize(struct_nestedpointers, buffer, 1, &p); + len2 = struct_nestedpointers_unserialize(buffer, 1, &destination); fail_unless(len2 == 0, "Should not be able to deserialize, too small (%d<%d)", i, len); } } - len2 = marshal_unserialize(struct_nestedpointers, buffer, len + 5, &p); + len2 = struct_nestedpointers_unserialize(buffer, len + 5, &destination); fail_unless(len2 == len, "Deserialized too much"); - destination = p; free(destination->c3); free(destination->c4); free(destination); free(buffer); @@ -446,7 +430,7 @@ struct struct_simpleentry { MARSHAL_BEGIN(struct_simpleentry) MARSHAL_TQE(struct_simpleentry, s_entries) MARSHAL_POINTER(struct_simpleentry, struct_simple, g2) -MARSHAL_END; +MARSHAL_END(struct_simpleentry); TAILQ_HEAD(list_simple, struct_simpleentry); MARSHAL_TQ(list_simple, struct_simpleentry); @@ -477,7 +461,6 @@ START_TEST(test_simple_list) { .g2 = &source_simple, }; struct list_simple *destination; - void *p; void *buffer; size_t len, len2; struct struct_simpleentry *e1, *e2; @@ -489,18 +472,17 @@ START_TEST(test_simple_list) { TAILQ_INSERT_TAIL(&source, &entry3, s_entries); TAILQ_INSERT_TAIL(&source, &entry4, s_entries); - len = marshal_serialize(list_simple, &source, &buffer); + len = list_simple_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct list_simple)); memset(&entry1, 0, sizeof(struct struct_simpleentry)); memset(&entry2, 0, sizeof(struct struct_simpleentry)); memset(&entry3, 0, sizeof(struct struct_simpleentry)); memset(&entry4, 0, sizeof(struct struct_simpleentry)); - len2 = marshal_unserialize(list_simple, buffer, len, &p); + len2 = list_simple_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; e1 = TAILQ_FIRST(destination); ck_assert_int_eq(e1->g1, 47); s = e1->g2; @@ -531,7 +513,7 @@ struct struct_withlist { }; MARSHAL_BEGIN(struct_withlist) MARSHAL_SUBTQ(struct_withlist, struct_simpleentry, i2) -MARSHAL_END; +MARSHAL_END(struct_withlist); START_TEST(test_embedded_list) { struct struct_withlist source = { @@ -562,7 +544,6 @@ START_TEST(test_embedded_list) { .g2 = &source_simple, }; struct struct_withlist *destination; - void *p; void *buffer; size_t len, len2; struct struct_simpleentry *e1, *e2; @@ -574,18 +555,17 @@ START_TEST(test_embedded_list) { TAILQ_INSERT_TAIL(&source.i2, &entry3, s_entries); TAILQ_INSERT_TAIL(&source.i2, &entry4, s_entries); - len = marshal_serialize(struct_withlist, &source, &buffer); + len = struct_withlist_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct list_simple)); memset(&entry1, 0, sizeof(struct struct_simpleentry)); memset(&entry2, 0, sizeof(struct struct_simpleentry)); memset(&entry3, 0, sizeof(struct struct_simpleentry)); memset(&entry4, 0, sizeof(struct struct_simpleentry)); - len2 = marshal_unserialize(struct_withlist, buffer, len, &p); + len2 = struct_withlist_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(destination->i1, 45424); ck_assert_int_eq(destination->i3, 4542); e1 = TAILQ_FIRST(&destination->i2); @@ -620,7 +600,7 @@ struct struct_string { MARSHAL_BEGIN(struct_string) MARSHAL_STR(struct_string, s2) MARSHAL_STR(struct_string, s3) -MARSHAL_END; +MARSHAL_END(struct_string); START_TEST(test_string) { struct struct_string source = { @@ -629,17 +609,15 @@ START_TEST(test_string) { .s3 = "String 3", }; struct struct_string *destination; - void *p; void *buffer; size_t len, len2; - len = marshal_serialize(struct_string, &source, &buffer); + len = struct_string_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct struct_string)); - len2 = marshal_unserialize(struct_string, buffer, len, &p); + len2 = struct_string_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->s1, 44444); ck_assert_str_eq(destination->s2, "String 2"); @@ -658,7 +636,7 @@ struct struct_fixedstring { MARSHAL_BEGIN(struct_fixedstring) MARSHAL_FSTR(struct_fixedstring, s2, s2_len) MARSHAL_STR(struct_fixedstring, s3) -MARSHAL_END; +MARSHAL_END(struct_fixedstring); START_TEST(test_fixed_string) { struct struct_fixedstring source = { @@ -668,17 +646,15 @@ START_TEST(test_fixed_string) { .s3 = "String 3", }; struct struct_fixedstring *destination; - void *p; void *buffer; size_t len, len2; - len = marshal_serialize(struct_fixedstring, &source, &buffer); + len = struct_fixedstring_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct struct_fixedstring)); - len2 = marshal_unserialize(struct_fixedstring, buffer, len, &p); + len2 = struct_fixedstring_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->s1, 44444); ck_assert_int_eq(destination->s2_len, 8); @@ -702,7 +678,7 @@ struct struct_ignore { }; MARSHAL_BEGIN(struct_ignore) MARSHAL_IGNORE(struct_ignore, t2) -MARSHAL_END; +MARSHAL_END(struct_ignore); START_TEST(test_ignore) { struct struct_ignore source = { @@ -711,17 +687,15 @@ START_TEST(test_ignore) { .t3 = 11111, }; struct struct_ignore *destination; - void *p; void *buffer; size_t len, len2; - len = marshal_serialize(struct_ignore, &source, &buffer); + len = struct_ignore_serialize(&source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct struct_ignore)); - len2 = marshal_unserialize(struct_ignore, buffer, len, &p); + len2 = struct_ignore_unserialize(buffer, len, &destination); fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - destination = p; ck_assert_int_eq(len, len2); ck_assert_int_eq(destination->t1, 4544); ck_assert_int_eq(destination->t2, NULL); @@ -750,8 +724,8 @@ START_TEST(test_equality) { memcpy(&source_simple2, &source_simple1, sizeof(source_simple1)); memcpy(&entry2, &entry1, sizeof(entry1)); entry2.g2 = &source_simple2; - ssize_t len1 = marshal_serialize(struct_simpleentry, &entry1, &buffer1); - ssize_t len2 = marshal_serialize(struct_simpleentry, &entry2, &buffer2); + ssize_t len1 = struct_simpleentry_serialize(&entry1, &buffer1); + ssize_t len2 = struct_simpleentry_serialize(&entry2, &buffer2); fail_unless(len1 > 0, "Unable to serialize"); fail_unless(len2 > 0, "Unable to serialize"); ck_assert_int_eq(len1, len2); -- 2.39.5