From 69bcd1d0babc5ab10a84555f29523d4f02119f67 Mon Sep 17 00:00:00 2001
From: gdamore
The nng_msg_header_clear simply resets the total message header length to zero.
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 nng_msg_header_append functions,
and inserting data in the header is done using the nng_msg_header_insert functions.
These functions act just like the nng_msg_append and nng_msg_insert functions,
except that they operate on the message header rather than the message body.
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 nng_msg_header_trim functions remove data from the beginning of the message header,
and the nng_msg_header_chop functions remove data from the end of the message header.
These functions act just like the nng_msg_trim and nng_msg_chop functions,
@@ -1012,23 +1032,23 @@ either directly by the application, or when the message was received by the prot
#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
- 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
+ }
+}
--
cgit v1.2.3-70-g09d2