[PATCH] libosmocore[master]: msgb: add msgb_push_u{8, 16, 32}() functions

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Nov 11 18:28:35 UTC 2016


Review at  https://gerrit.osmocom.org/1237

msgb: add msgb_push_u{8,16,32}() functions

Those work analoguous to msgb_put_*() but pre-pend the given value
into the msg headroom, rather than appending it to the end.

Change-Id: I7de63e9d04c2d2b678f1f20eef37f9be2c4f5ec2
---
M include/osmocom/core/msgb.h
1 file changed, 30 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/37/1237/1

diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h
index 7c85771..9cb1c24 100644
--- a/include/osmocom/core/msgb.h
+++ b/include/osmocom/core/msgb.h
@@ -290,6 +290,36 @@
 	return msgb->data;
 }
 
+/*! \brief prepend a uint8 value to the head of the message
+ *  \param[in] msgb message buffer
+ *  \param[in] word unsigned 8bit byte to be prepended
+ */
+static inline void msgb_push_u8(struct msgb *msg, uint8_t word)
+{
+	uint8_t *space = msgb_push(msg, 1);
+	space[0] = word;
+}
+
+/*! \brief prepend a uint16 value to the head of the message
+ *  \param[in] msgb message buffer
+ *  \param[in] word unsigned 16bit byte to be prepended
+ */
+static inline void msgb_push_u16(struct msgb *msg, uint16_t word)
+{
+	uint16_t *space = (uint16_t *) msgb_push(msg, 2);
+	osmo_store16be(word, space);
+}
+
+/*! \brief prepend a uint32 value to the head of the message
+ *  \param[in] msgb message buffer
+ *  \param[in] word unsigned 32bit byte to be prepended
+ */
+static inline void msgb_push_u32(struct msgb *msg, uint32_t word)
+{
+	uint32_t *space = (uint32_t *) msgb_push(msg, 4);
+	osmo_store32be(word, space);
+}
+
 /*! \brief remove (pull) a header from the front of the message buffer
  *  \param[in] msgb message buffer
  *  \param[in] len number of octets to be pulled

-- 
To view, visit https://gerrit.osmocom.org/1237
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7de63e9d04c2d2b678f1f20eef37f9be2c4f5ec2
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list