summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e2258e6)
raw | patch | inline | side by side (parent: e2258e6)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 15 Dec 2014 09:46:08 +0000 (10:46 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 15 Dec 2014 09:46:08 +0000 (10:46 +0100) |
src/include/utils/proto.h | patch | blob | history | |
src/utils/proto.c | patch | blob | history |
index e76211965a416d4e06d6fa93bdfbcc3e1d32b2e9..6f0907feee2c2e5243e61e2c37ce47419a7539b2 100644 (file)
sdb_proto_marshal(char *buf, size_t buf_len, uint32_t code,
uint32_t msg_len, const char *msg);
+/*
+ * sdb_proto_unmarshal_header:
+ * Read and decode a message header from the specified string buffer.
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+int
+sdb_proto_unmarshal_header(sdb_strbuf_t *buf,
+ uint32_t *code, uint32_t *msg_len);
+
uint32_t
sdb_proto_get_int(sdb_strbuf_t *buf, size_t offset);
diff --git a/src/utils/proto.c b/src/utils/proto.c
index 16007f2e5bd48d1ebe9a6d2958cdf8624c52f4fb..35b19862b12e5ea1fe8258cf519713cfc9e8c7dc 100644 (file)
--- a/src/utils/proto.c
+++ b/src/utils/proto.c
return len;
} /* sdb_proto_marshal */
+int
+sdb_proto_unmarshal_header(sdb_strbuf_t *buf,
+ uint32_t *code, uint32_t *msg_len)
+{
+ uint32_t tmp;
+
+ if (sdb_strbuf_len(buf) < 2 * sizeof(uint32_t))
+ return -1;
+
+ tmp = sdb_proto_get_int(buf, 0);
+ if (code)
+ *code = tmp;
+ tmp = sdb_proto_get_int(buf, sizeof(uint32_t));
+ if (msg_len)
+ *msg_len = tmp;
+ return 0;
+} /* sdb_proto_unmarshal_header */
+
uint32_t
sdb_proto_get_int(sdb_strbuf_t *buf, size_t offset)
{