index 372e34d474b7be20dd5fc13ce6c04025748bc0a8..ab01cf5d1ed9cf53bf66fbbe8c29bf8003921631 100644 (file)
#ifndef SDB_UTILS_PROTO_H
#define SDB_UTILS_PROTO_H 1
-#include "utils/strbuf.h"
+#include "core/data.h"
#include <stdint.h>
#include <unistd.h>
extern "C" {
#endif
+/*
+ * sdb_proto_marshal:
+ * Encode the message into the wire format by adding an appropriate header.
+ * The encoded message is written to buf which has to be large enough to store
+ * the header (64 bits) and the entire message.
+ *
+ * Returns:
+ * - The number of bytes of the full encoded message 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 on error
+ */
ssize_t
-sdb_proto_send(int fd, size_t msg_len, const char *msg);
+sdb_proto_marshal(char *buf, size_t buf_len, uint32_t code,
+ uint32_t msg_len, const char *msg);
+/*
+ * sdb_proto_marshal_data:
+ * Encode a datum into the wire format and write it to buf.
+ *
+ * Returns:
+ * - The number of bytes of the full encoded datum 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_send_msg(int fd, uint32_t code,
- uint32_t msg_len, const char *msg);
+sdb_proto_marshal_data(char *buf, size_t buf_len, sdb_data_t *datum);
+/*
+ * sdb_proto_unmarshal_header:
+ * Read and decode a message header from the specified string.
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+int
+sdb_proto_unmarshal_header(const char *buf, size_t buf_len,
+ uint32_t *code, uint32_t *msg_len);
+
+/*
+ * sdb_proto_unmarshal_int32:
+ * Read and decode a 32-bit integer from the specified string.
+ */
uint32_t
-sdb_proto_get_int(sdb_strbuf_t *buf, size_t offset);
+sdb_proto_unmarshal_int32(const char *buf, size_t buf_len);
#ifdef __cplusplus
} /* extern "C" */