From 69bcd1d0babc5ab10a84555f29523d4f02119f67 Mon Sep 17 00:00:00 2001 From: gdamore Date: Wed, 1 Jan 2025 19:37:21 +0000 Subject: deploy: f8a2abaf931557030fd6e6683617c6a7877eebf7 --- ref/print.html | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'ref/print.html') diff --git a/ref/print.html b/ref/print.html index 3089c77a..c6027f55 100644 --- a/ref/print.html +++ b/ref/print.html @@ -983,11 +983,31 @@ properly.

The nng_msg_header_clear simply resets the total message header length to zero.

Append or Insert Header

+
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.

Consume from Header

+
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

Examples

Example 1: Preparing a message for use

-
    #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