From 5637e2d8b66c64cb4ce2e205c0f6912cd8f9eb54 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 22 Feb 2015 16:27:09 +0100 Subject: [PATCH] proto: Make sdb_proto_marshal_int32 a public function. --- src/include/utils/proto.h | 14 ++++++++++++++ src/utils/proto.c | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/include/utils/proto.h b/src/include/utils/proto.h index b626781..5671563 100644 --- a/src/include/utils/proto.h +++ b/src/include/utils/proto.h @@ -91,6 +91,20 @@ ssize_t sdb_proto_marshal(char *buf, size_t buf_len, uint32_t code, uint32_t msg_len, const char *msg); +/* + * sdb_proto_marshal_int32: + * Encode the 32-bit integer into the wire format and write it to buf. + * + * Returns: + * - The number of bytes of the encoded value on success. The function does + * not write more than 'buf_len' bytes. If the output was truncated then + * the return value is the number of bytes which would have been written if + * enough space had been available. + * - a negative value else + */ +ssize_t +sdb_proto_marshal_int32(char *buf, size_t buf_len, uint32_t v); + /* * sdb_proto_marshal_data: * Encode a datum into the wire format and write it to buf. diff --git a/src/utils/proto.c b/src/utils/proto.c index 13d9129..af47cdf 100644 --- a/src/utils/proto.c +++ b/src/utils/proto.c @@ -80,16 +80,6 @@ memdup(const unsigned char *d, size_t length) * return the number of bytes that would have been written if enough space had * been available. */ -static ssize_t -marshal_int32(char *buf, size_t buf_len, uint32_t v) -{ - if (buf_len >= sizeof(v)) { - v = htonl(v); - memcpy(buf, &v, sizeof(v)); - } - return sizeof(v); -} /* marshal_int32 */ - static ssize_t marshal_int64(char *buf, size_t buf_len, int64_t v) { @@ -229,7 +219,7 @@ marshal_obj_header(char *buf, size_t buf_len, if (buf_len < OBJ_HEADER_LEN) return OBJ_HEADER_LEN; - n = marshal_int32(buf, buf_len, (uint32_t)type); + n = sdb_proto_marshal_int32(buf, buf_len, (uint32_t)type); buf += n; buf_len -= n; marshal_datetime(buf, buf_len, last_update); return OBJ_HEADER_LEN; @@ -277,6 +267,16 @@ sdb_proto_marshal(char *buf, size_t buf_len, uint32_t code, return len; } /* sdb_proto_marshal */ +ssize_t +sdb_proto_marshal_int32(char *buf, size_t buf_len, uint32_t v) +{ + if (buf_len >= sizeof(v)) { + v = htonl(v); + memcpy(buf, &v, sizeof(v)); + } + return sizeof(v); +} /* sdb_proto_marshal_int32 */ + ssize_t sdb_proto_marshal_data(char *buf, size_t buf_len, const sdb_data_t *datum) { -- 2.30.2