From 8593f1f57a5140a34cd4f7063c2e7fcb54e1837b Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 11 Nov 2016 19:26:51 +0100 Subject: 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 --- include/osmocom/core/msgb.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h index 7c857710..9cb1c24d 100644 --- a/include/osmocom/core/msgb.h +++ b/include/osmocom/core/msgb.h @@ -290,6 +290,36 @@ static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len) 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 -- cgit v1.2.3