diff options
author | Harald Welte <laforge@gnumonks.org> | 2016-11-11 19:26:51 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2016-11-11 19:28:32 +0100 |
commit | 8593f1f57a5140a34cd4f7063c2e7fcb54e1837b (patch) | |
tree | 98c6317612ab04ae8cc98fc2e221be02aaa4a8ff | |
parent | 6176b6e0924f2bd7d212472bcba9dddf8ac32f51 (diff) |
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
-rw-r--r-- | include/osmocom/core/msgb.h | 30 |
1 files changed, 30 insertions, 0 deletions
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 |