Code

Add a suffix to integer marshal/unmarshal functions specifying the int size.
[sysdb.git] / src / include / utils / proto.h
index f3f1a871d83e48c28e96bee92fd8a40ac4e3188a..ab01cf5d1ed9cf53bf66fbbe8c29bf8003921631 100644 (file)
@@ -28,7 +28,7 @@
 #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
 
-enum {
-       SDB_PROTO_SELECTIN = 0,
-       SDB_PROTO_SELECTOUT,
-       SDB_PROTO_SELECTERR,
-};
-
 /*
- * sdb_proto_select:
- * Wait for a file-descriptor to become ready for I/O operations of the
- * specified type. This is a simple wrapper around the select() system call.
- * The type argument may be any of the SDB_PROTO_SELECT* constants.
+ * 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 file descriptors ready for I/O
+ *  - 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
  */
-int
-sdb_proto_select(int fd, int type);
-
 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" */