diff --git a/ctdb/protocol/protocol_basic.c b/ctdb/protocol/protocol_basic.c index 75c786d9675..ef69fc76c44 100644 --- a/ctdb/protocol/protocol_basic.c +++ b/ctdb/protocol/protocol_basic.c @@ -30,6 +30,28 @@ * Basic data types */ +size_t ctdb_uint8_len(uint8_t *in) +{ + return sizeof(uint8_t); +} + +void ctdb_uint8_push(uint8_t *in, uint8_t *buf, size_t *npush) +{ + *buf = *in; + *npush = sizeof(uint8_t); +} + +int ctdb_uint8_pull(uint8_t *buf, size_t buflen, uint8_t *out, size_t *npull) +{ + if (buflen < sizeof(uint8_t)) { + return EMSGSIZE; + } + + *out = *buf; + *npull = sizeof(uint8_t); + return 0; +} + size_t ctdb_int32_len(int32_t val) { return sizeof(int32_t); diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h index 2bdf48b93f8..b01224b5294 100644 --- a/ctdb/protocol/protocol_private.h +++ b/ctdb/protocol/protocol_private.h @@ -26,6 +26,10 @@ * From protocol/protocol_basic.c */ +size_t ctdb_uint8_len(uint8_t *in); +void ctdb_uint8_push(uint8_t *in, uint8_t *buf, size_t *npush); +int ctdb_uint8_pull(uint8_t *buf, size_t buflen, uint8_t *out, size_t *npull); + size_t ctdb_int32_len(int32_t val); void ctdb_int32_push(int32_t val, uint8_t *buf); int ctdb_int32_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, diff --git a/ctdb/tests/src/protocol_basic_test.c b/ctdb/tests/src/protocol_basic_test.c index dfc2796baec..9df485ca126 100644 --- a/ctdb/tests/src/protocol_basic_test.c +++ b/ctdb/tests/src/protocol_basic_test.c @@ -25,6 +25,8 @@ #include "tests/src/protocol_common.h" +PROTOCOL_TYPE1_TEST(uint8_t, ctdb_uint8); + static void test_ctdb_int32(void) { int32_t p1, p2; @@ -134,6 +136,8 @@ int main(int argc, char *argv[]) srandom(seed); } + TEST_FUNC(ctdb_uint8)(); + test_ctdb_int32(); test_ctdb_uint32(); test_ctdb_uint64(); diff --git a/ctdb/tests/src/protocol_common.c b/ctdb/tests/src/protocol_common.c index 83fb32dfb00..67b26fb55a1 100644 --- a/ctdb/tests/src/protocol_common.c +++ b/ctdb/tests/src/protocol_common.c @@ -82,6 +82,16 @@ void verify_buffer(void *p1, void *p2, size_t len) } } +void fill_ctdb_uint8(uint8_t *p) +{ + *p = rand8(); +} + +void verify_ctdb_uint8(uint8_t *p1, uint8_t *p2) +{ + assert(*p1 == *p2); +} + void fill_ctdb_string(TALLOC_CTX *mem_ctx, const char **out) { char *p; diff --git a/ctdb/tests/src/protocol_common.h b/ctdb/tests/src/protocol_common.h index 63a7d66026c..24badc00d42 100644 --- a/ctdb/tests/src/protocol_common.h +++ b/ctdb/tests/src/protocol_common.h @@ -151,6 +151,9 @@ double rand_double(void); void fill_buffer(void *p, size_t len); void verify_buffer(void *p1, void *p2, size_t len); +void fill_ctdb_uint8(uint8_t *p); +void verify_ctdb_uint8(uint8_t *p1, uint8_t *p2); + void fill_ctdb_string(TALLOC_CTX *mem_ctx, const char **out); void verify_ctdb_string(const char *p1, const char *p2);