summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6c079fa)
raw | patch | inline | side by side (parent: 6c079fa)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 22 Feb 2015 15:27:09 +0000 (16:27 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 22 Feb 2015 15:27:09 +0000 (16:27 +0100) |
src/include/utils/proto.h | patch | blob | history | |
src/utils/proto.c | patch | blob | history |
index b626781f9a1f70652bd0de5fa7a51455ff57c346..56715630524594a71e524932def3f1a01a9f7670 100644 (file)
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 13d91293d20a7c91da012c10e978c3295d8b4129..af47cdf11d51673684808bc206af14524dbec370 100644 (file)
--- a/src/utils/proto.c
+++ b/src/utils/proto.c
* 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)
{
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;
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)
{