mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
ctdb-protocol: Add marshalling for uint16_t
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
5a2b2cc141
commit
453ff93bb3
@ -52,6 +52,28 @@ int ctdb_uint8_pull(uint8_t *buf, size_t buflen, uint8_t *out, size_t *npull)
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ctdb_uint16_len(uint16_t *in)
|
||||
{
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
void ctdb_uint16_push(uint16_t *in, uint8_t *buf, size_t *npush)
|
||||
{
|
||||
memcpy(buf, in, sizeof(uint16_t));
|
||||
*npush = sizeof(uint16_t);
|
||||
}
|
||||
|
||||
int ctdb_uint16_pull(uint8_t *buf, size_t buflen, uint16_t *out, size_t *npull)
|
||||
{
|
||||
if (buflen < sizeof(uint16_t)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
memcpy(out, buf, sizeof(uint16_t));
|
||||
*npull = sizeof(uint16_t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ctdb_int32_len(int32_t val)
|
||||
{
|
||||
return sizeof(int32_t);
|
||||
|
@ -30,6 +30,11 @@ 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_uint16_len(uint16_t *in);
|
||||
void ctdb_uint16_push(uint16_t *in, uint8_t *buf, size_t *npush);
|
||||
int ctdb_uint16_pull(uint8_t *buf, size_t buflen, uint16_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,
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
|
||||
PROTOCOL_TYPE1_TEST(uint8_t, ctdb_uint8);
|
||||
PROTOCOL_TYPE1_TEST(uint16_t, ctdb_uint16);
|
||||
|
||||
static void test_ctdb_int32(void)
|
||||
{
|
||||
@ -137,6 +138,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
TEST_FUNC(ctdb_uint8)();
|
||||
TEST_FUNC(ctdb_uint16)();
|
||||
|
||||
test_ctdb_int32();
|
||||
test_ctdb_uint32();
|
||||
|
@ -43,6 +43,12 @@ uint8_t rand8(void)
|
||||
return val;
|
||||
}
|
||||
|
||||
uint16_t rand16(void)
|
||||
{
|
||||
uint16_t val = rand_int(0xffff) & 0xffff;
|
||||
return val;
|
||||
}
|
||||
|
||||
int32_t rand32i(void)
|
||||
{
|
||||
return INT_MIN + random();
|
||||
@ -92,6 +98,16 @@ void verify_ctdb_uint8(uint8_t *p1, uint8_t *p2)
|
||||
assert(*p1 == *p2);
|
||||
}
|
||||
|
||||
void fill_ctdb_uint16(uint16_t *p)
|
||||
{
|
||||
*p = rand16();
|
||||
}
|
||||
|
||||
void verify_ctdb_uint16(uint16_t *p1, uint16_t *p2)
|
||||
{
|
||||
assert(*p1 == *p2);
|
||||
}
|
||||
|
||||
void fill_ctdb_string(TALLOC_CTX *mem_ctx, const char **out)
|
||||
{
|
||||
char *p;
|
||||
|
@ -143,6 +143,7 @@ extern uint8_t BUFFER[1024*1024];
|
||||
|
||||
int rand_int(int max);
|
||||
uint8_t rand8(void);
|
||||
uint16_t rand16(void);
|
||||
int32_t rand32i(void);
|
||||
uint32_t rand32(void);
|
||||
uint64_t rand64(void);
|
||||
@ -154,6 +155,9 @@ 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_uint16(uint16_t *p);
|
||||
void verify_ctdb_uint16(uint16_t *p1, uint16_t *p2);
|
||||
|
||||
void fill_ctdb_string(TALLOC_CTX *mem_ctx, const char **out);
|
||||
void verify_ctdb_string(const char *p1, const char *p2);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user