summaryrefslogtreecommitdiff
path: root/src/core/message.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-10 18:14:27 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-10 22:47:43 -0700
commitdbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292 (patch)
treec5b94f14fd95725077d2b4e9cd0d3d4d166aa7e2 /src/core/message.h
parent34ceda3c2dd4990d15e0341e86861dd291003f63 (diff)
downloadnng-dbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292.tar.gz
nng-dbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292.tar.bz2
nng-dbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292.zip
Unify the msg API.
This makes the operations that work on headers start with nni_msg_header or nng_msg_header. It also renames _trunc to _chop (same strlen as _trim), and renames prepend to insert. We add a shorthand for clearing message content, and make better use of the endian safe 32-bit accessors too. This also fixes a bug in inserting large headers into messages. A test suite for message handling is included.
Diffstat (limited to 'src/core/message.h')
-rw-r--r--src/core/message.h29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/core/message.h b/src/core/message.h
index 4bc15321..00d31436 100644
--- a/src/core/message.h
+++ b/src/core/message.h
@@ -12,35 +12,38 @@
#define CORE_MESSAGE_H
// Internally used message API. Again, this is not part of our public API.
+// "trim" operations work from the front, and "chop" work from the end.
extern int nni_msg_alloc(nni_msg **, size_t);
extern void nni_msg_free(nni_msg *);
extern int nni_msg_realloc(nni_msg *, size_t);
extern int nni_msg_dup(nni_msg **, const nni_msg *);
extern void * nni_msg_header(nni_msg *);
-extern size_t nni_msg_header_len(nni_msg *);
+extern size_t nni_msg_header_len(const nni_msg *);
extern void * nni_msg_body(nni_msg *);
-extern size_t nni_msg_len(nni_msg *);
+extern size_t nni_msg_len(const nni_msg *);
extern int nni_msg_append(nni_msg *, const void *, size_t);
-extern int nni_msg_prepend(nni_msg *, const void *, size_t);
-extern int nni_msg_append_header(nni_msg *, const void *, size_t);
-extern int nni_msg_prepend_header(nni_msg *, const void *, size_t);
+extern int nni_msg_insert(nni_msg *, const void *, size_t);
+extern int nni_msg_header_append(nni_msg *, const void *, size_t);
+extern int nni_msg_header_insert(nni_msg *, const void *, size_t);
extern int nni_msg_trim(nni_msg *, size_t);
-extern int nni_msg_trunc(nni_msg *, size_t);
-extern int nni_msg_trim_header(nni_msg *, size_t);
-extern int nni_msg_trunc_header(nni_msg *, size_t);
+extern int nni_msg_chop(nni_msg *, size_t);
+extern void nni_msg_clear(nni_msg *);
+extern void nni_msg_header_clear(nni_msg *);
+extern int nni_msg_header_trim(nni_msg *, size_t);
+extern int nni_msg_header_chop(nni_msg *, size_t);
extern int nni_msg_setopt(nni_msg *, int, const void *, size_t);
extern int nni_msg_getopt(nni_msg *, int, void *, size_t *);
extern void nni_msg_dump(const char *, const nni_msg *);
extern int nni_msg_append_u32(nni_msg *, uint32_t);
-extern int nni_msg_prepend_u32(nni_msg *, uint32_t);
+extern int nni_msg_insert_u32(nni_msg *, uint32_t);
extern int nni_msg_header_append_u32(nni_msg *, uint32_t);
-extern int nni_msg_header_prepend_u32(nni_msg *, uint32_t);
+extern int nni_msg_header_insert_u32(nni_msg *, uint32_t);
extern uint32_t nni_msg_trim_u32(nni_msg *);
-extern uint32_t nni_msg_trunc_u32(nni_msg *);
+extern uint32_t nni_msg_chop_u32(nni_msg *);
extern uint32_t nni_msg_header_trim_u32(nni_msg *);
-extern uint32_t nni_msg_header_trunc_u32(nni_msg *);
+extern uint32_t nni_msg_header_chop_u32(nni_msg *);
extern void nni_msg_set_pipe(nni_msg *, uint32_t);
-extern uint32_t nni_msg_get_pipe(nni_msg *);
+extern uint32_t nni_msg_get_pipe(const nni_msg *);
#endif // CORE_SOCKET_H