index 311162bb0682c09aa8acc11908e8b8bf2f7df4f1..fd842c1b0caf8c6f48b64b03a7c7d1c2db9f5488 100644 (file)
#ifndef SDB_UTILS_PROTO_H
#define SDB_UTILS_PROTO_H 1
#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>
#include <stdint.h>
#include <unistd.h>
extern "C" {
#endif
extern "C" {
#endif
+/*
+ * sdb_proto_host, sdb_proto_service, sdb_proto_metric:
+ * Protocol-specific representations of the basic information of stored
+ * objects.
+ */
+typedef struct {
+ sdb_time_t last_update;
+ const char *name;
+} sdb_proto_host_t;
+
+typedef struct {
+ sdb_time_t last_update;
+ const char *hostname;
+ const char *name;
+} sdb_proto_service_t;
+
+typedef struct {
+ sdb_time_t last_update;
+ const char *hostname;
+ const char *name;
+ const char *store_type; /* optional */
+ const char *store_id; /* optional */
+} sdb_proto_metric_t;
+
+typedef struct {
+ sdb_time_t last_update;
+ int parent_type;
+ const char *hostname; /* optional */
+ const char *parent;
+ const char *key;
+ const sdb_data_t *value;
+} sdb_proto_attribute_t;
+
/*
* sdb_proto_marshal:
* Encode the message into the wire format by adding an appropriate header.
/*
* sdb_proto_marshal:
* Encode the message into the wire format by adding an appropriate header.
* the header (64 bits) and the entire message.
*
* Returns:
* the header (64 bits) and the entire message.
*
* Returns:
- * - the number of bytes of the full encoded message on success (even if less
- * than that fit into and was written to the buffer)
+ * - 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_marshal(char *buf, size_t buf_len, uint32_t code,
uint32_t msg_len, const char *msg);
* - a negative value on error
*/
ssize_t
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_marshal_data(char *buf, size_t buf_len, const sdb_data_t *datum);
+
+/*
+ * sdb_proto_marshal_host, sdb_proto_marshal_service,
+ * sdb_proto_marshal_metric, sdb_proto_marshal_attribute:
+ * Encode the basic information of a stored object into the wire format and
+ * write it to buf. These functions are similar to the sdb_store_<type>
+ * functions. See their documentation for details about the arguments.
+ *
+ * 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_marshal_host(char *buf, size_t buf_len,
+ const sdb_proto_host_t *host);
+ssize_t
+sdb_proto_marshal_service(char *buf, size_t buf_len,
+ const sdb_proto_service_t *svc);
+ssize_t
+sdb_proto_marshal_metric(char *buf, size_t buf_len,
+ const sdb_proto_metric_t *metric);
+ssize_t
+sdb_proto_marshal_attribute(char *buf, size_t buf_len,
+ const sdb_proto_attribute_t *attr);
+
/*
* sdb_proto_unmarshal_header:
/*
* sdb_proto_unmarshal_header:
- * Read and decode a message header from the specified string buffer.
+ * Read and decode a message header from the specified string.
*
* Returns:
* - 0 on success
* - a negative value else
*/
int
*
* Returns:
* - 0 on success
* - a negative value else
*/
int
-sdb_proto_unmarshal_header(sdb_strbuf_t *buf,
+sdb_proto_unmarshal_header(const char *buf, size_t buf_len,
uint32_t *code, uint32_t *msg_len);
/*
uint32_t *code, uint32_t *msg_len);
/*
- * sdb_proto_unmarshal_int:
- * Read and decode an integer from the specified string buffer.
+ * sdb_proto_unmarshal_int32:
+ * Read and decode a 32-bit integer from the specified string.
*/
uint32_t
*/
uint32_t
-sdb_proto_unmarshal_int(sdb_strbuf_t *buf, size_t offset);
+sdb_proto_unmarshal_int32(const char *buf, size_t buf_len);
#ifdef __cplusplus
} /* extern "C" */
#ifdef __cplusplus
} /* extern "C" */