aboutsummaryrefslogtreecommitdiff
path: root/docs/ref/api/msg.md
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-01-01 11:24:29 -0800
committerGarrett D'Amore <garrett@damore.org>2025-01-01 11:24:29 -0800
commit0bb1ee96b6323dea250fa2eba9d40810a61b9c12 (patch)
tree3c4b2c96778299bc3a6e4c455c3c438e2e42b8a5 /docs/ref/api/msg.md
parentf9aeee4d6761adfebd5fc9594247ee98ff8ffb83 (diff)
downloadnng-0bb1ee96b6323dea250fa2eba9d40810a61b9c12.tar.gz
nng-0bb1ee96b6323dea250fa2eba9d40810a61b9c12.tar.bz2
nng-0bb1ee96b6323dea250fa2eba9d40810a61b9c12.zip
docs: add missing msg header prototypes
Diffstat (limited to 'docs/ref/api/msg.md')
-rw-r--r--docs/ref/api/msg.md52
1 files changed, 38 insertions, 14 deletions
diff --git a/docs/ref/api/msg.md b/docs/ref/api/msg.md
index 319fa1e4..1cea98e6 100644
--- a/docs/ref/api/msg.md
+++ b/docs/ref/api/msg.md
@@ -201,6 +201,18 @@ The {{i:`nng_msg_header_clear`}} simply resets the total message header length t
### Append or Insert Header
+```c
+int nng_msg_header_append(nng_msg *msg, const void *val, size_t size);
+int nng_msg_header_append_u16(nng_msg *msg, uint16_t val16);
+int nng_msg_header_append_u32(nng_msg *msg, uint32_t val32);
+int nng_msg_header_append_u64(nng_msg *msg, uint64_t val64);
+
+int nng_msg_header_insert(nng_msg *msg, const void *val, size_t size);
+int nng_msg_header_insert_u16(nng_msg *msg, uint16_t val16);
+int nng_msg_header_insert_u32(nng_msg *msg, uint32_t val32);
+int nng_msg_header_insert_u64(nng_msg *msg, uint64_t val64);
+```
+
Appending data to a message header is done by using the {{i:`nng_msg_header_append`}} functions,
and inserting data in the header is done using the {{i:`nng_msg_header_insert`}} functions.
@@ -209,6 +221,18 @@ except that they operate on the message header rather than the message body.
### Consume from Header
+```c
+int nng_msg_header_chop(nng_msg *msg, size_t size);
+int nng_msg_header_chop_u16(nng_msg *msg, uint16_t *val16);
+int nng_msg_header_chop_u32(nng_msg *msg, uint32_t *val32);
+int nng_msg_header_chop_u64(nng_msg *msg, uint64_t *val64);
+
+int nng_msg_header_trim(nng_msg *msg, size_t size);
+int nng_msg_header_trim_u16(nng_msg *msg, uint16_t *val16);
+int nng_msg_header_trim_u32(nng_msg *msg, uint32_t *val32);
+int nng_msg_header_trim_u64(nng_msg *msg, uint64_t *val64);
+```
+
The {{i:`nng_msg_header_trim`}} functions remove data from the beginning of the message header,
and the {{i:`nng_msg_header_chop`}} functions remove data from the end of the message header.
@@ -239,26 +263,26 @@ either directly by the application, or when the message was received by the prot
### Example 1: Preparing a message for use
```c
- #include <nng/nng.h>
+#include <nng/nng.h>
- nng_msg *m;
- if (nng_msg_alloc(&m, strlen("content") + 1) != 0) {
- // handle error
- }
- strcpy(nng_msg_body(m), "content");
+nng_msg *m;
+if (nng_msg_alloc(&m, strlen("content") + 1) != 0) {
+ // handle error
+}
+strcpy(nng_msg_body(m), "content");
```
### Example 2: Preallocating message content
```c
- if (nng_msg_alloc(&m, 1024) != 0) {
- // handle error
- }
- while ((val64 = next_datum()) != 0) P
- if (nng_msg_append_u64(m, val64) != 0) {
- // handle error
- }
- }
+if (nng_msg_alloc(&m, 1024) != 0) {
+ // handle error
+}
+while ((val64 = next_datum()) != 0) P
+ if (nng_msg_append_u64(m, val64) != 0) {
+ // handle error
+ }
+}
```
{{#include ../xref.md}}