mirror of https://gerrit.osmocom.org/libosmocore
TLV: add convenience function for 1-byte values
Similar to existing 16 and 32 bit value helpers but simpler because we don't have to worry about alingment and endianness. Change-Id: Ic0a148bd04b8860e321f509fdcd913f688c8e920
This commit is contained in:
parent
e6f63f22c5
commit
bd6d5c10db
|
@ -495,6 +495,22 @@ void tlv_def_patch(struct tlv_definition *dst, const struct tlv_definition *src)
|
|||
(TLVP_PRES_LEN(_tp, tag, min_len)? (_tp)->lv[tag].val : NULL)
|
||||
|
||||
|
||||
/*! Obtain 1-byte TLV element.
|
||||
* \param[in] tp pointer to \ref tlv_parsed
|
||||
* \param[in] tag the Tag to look for
|
||||
* \param[in] default_val default value to use if tag not available
|
||||
* \returns the 1st byte of value with a given tag or default_val if tag was not found
|
||||
*/
|
||||
static inline uint8_t tlvp_val8(const struct tlv_parsed *tp, uint8_t tag, uint8_t default_val)
|
||||
{
|
||||
const uint8_t *res = TLVP_VAL_MINLEN(tp, tag, 1);
|
||||
|
||||
if (res)
|
||||
return res[0];
|
||||
|
||||
return default_val;
|
||||
}
|
||||
|
||||
/*! Align given TLV element with 16 bit value to an even address
|
||||
* \param[in] tp pointer to \ref tlv_parsed
|
||||
* \param[in] pos element to return
|
||||
|
|
Loading…
Reference in New Issue