1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

ctdb-protocol: Add marshalling for uint8_t

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-06-29 22:24:20 +10:00 committed by Martin Schwenke
parent 62229f4c93
commit 5a2b2cc141
5 changed files with 43 additions and 0 deletions

View File

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

View File

@ -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,

View File

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

View File

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

View File

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