diff options
author | Max <msuraev@sysmocom.de> | 2018-12-03 15:33:52 +0100 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2018-12-04 10:26:42 +0100 |
commit | d82070c3838f1d7290b3047e0287e3eac141adf1 (patch) | |
tree | 35bedc83c8b4e07d495f3f3b9ba7f7bc359f2e53 /include/osmocom | |
parent | 30b2e348dfcfafe9eecf9a7d265f4e01fd0d373e (diff) |
Add msgb_tl_put() helper
When adding complex TLV structures where length of V is not known in
advance it's handy to be able to simply add Tag and save the pointer to
the Length field so it can be updated once entire Value is added and its
length is known.
Change-Id: I8dc1e4880352833a0a49c1dd0d7cb4148ac43aff
Diffstat (limited to 'include/osmocom')
-rw-r--r-- | include/osmocom/gsm/tlv.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h index 1ab964ad..51bedd64 100644 --- a/include/osmocom/gsm/tlv.h +++ b/include/osmocom/gsm/tlv.h @@ -324,6 +324,18 @@ static inline uint8_t *msgb_v_put(struct msgb *msg, uint8_t val) return v_put(buf, val); } +/*! put (append) a TL fields to a \ref msgb + * \returns pointer to the length field so it can be updated after adding new information under specified tag */ +static inline uint8_t *msgb_tl_put(struct msgb *msg, uint8_t tag) +{ + uint8_t *len = msgb_v_put(msg, tag); + + /* reserve space for length, len points to this reserved space already */ + msgb_v_put(msg, 0); + + return len; +} + /*! put (append) a TV16 field to a \ref msgb * \returns pointer to first byte after newly-put information */ static inline uint8_t *msgb_tv16_put(struct msgb *msg, uint8_t tag, uint16_t val) |