aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv/pb-msg.h
diff options
context:
space:
mode:
authorThomasintAnker <thomasintanker1@gmail.com>2024-06-24 14:59:56 +0200
committerThomasintAnker <thomasintanker1@gmail.com>2024-06-24 14:59:56 +0200
commita0c664908b9112306c5858ccb106d1a0e5555df7 (patch)
tree8ca77d1210d1683a97f4da131c6ffac8123d4375 /lib/pbdrv/pb-msg.h
parent381149dd7a1f4d5f48dd5ac07186c73371ff3c04 (diff)
parentec7f5e970ed03acb33eb5dc3b67f3d52af52e6dc (diff)
merge main into wip/mc
Diffstat (limited to 'lib/pbdrv/pb-msg.h')
-rw-r--r--lib/pbdrv/pb-msg.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/pbdrv/pb-msg.h b/lib/pbdrv/pb-msg.h
index f27d4c4..ff5bcde 100644
--- a/lib/pbdrv/pb-msg.h
+++ b/lib/pbdrv/pb-msg.h
@@ -7,10 +7,53 @@
extern "C" {
#endif
+/**
+ * \ingroup pbdrv
+ * \ingroup pbdrv-mod
+ * \defgroup pb_msg Message
+ * \brief Message (de)serialization
+ * \{
+ */
+
+/**
+ * \brief Serialize a message into a binary buffer
+ *
+ * \note This function allocates a \c pb_buf_t that should be free'd using \c
+ * pb_buf_free()
+ *
+ * \param msg Message to serialize
+ *
+ * \warning The type of \c msg->cmd is inferred from \c msg->type. If the
+ * message is not correctly formatted, this function may cause undefined
+ * behavior. If possible, use functions from \ref pb_send instead.
+ *
+ * \return \c pb_buf_t containing the serialized message, or an empty struct if
+ * serialization failed
+ */
pb_buf_t pb_msg_write(const pb_msg_t * msg);
+/**
+ * \brief Read a binary buffer and attempt to deserialize it as a puzzle bus
+ * message
+ *
+ * \note This function allocates a \c pb_msg_t pointer that should be free'd
+ * using \c pb_msg_free()
+ *
+ * \param buf Binary data to interpret as puzzle bus message
+ *
+ * \return \c pb_msg_t pointer containing the deserialized message, or NULL if
+ * serialization failed
+ */
pb_msg_t * pb_msg_read(const pb_buf_t * buf);
+/**
+ * \brief Recursively free fields of a \c pb_msg_t
+ *
+ * \note The \p msg pointer itself is also free'd by this function. You should
+ * set it to NULL afterwards to avoid confusion.
+ */
void pb_msg_free(pb_msg_t * msg);
+/// \}
+
#ifdef __cplusplus
}
#endif