Change in libosmocore[master]: TLV: add convenience function for 1-byte values

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/.

Max gerrit-no-reply at lists.osmocom.org
Wed Dec 19 18:04:15 UTC 2018


Max has uploaded this change for review. ( https://gerrit.osmocom.org/12373


Change subject: TLV: add convenience function for 1-byte values
......................................................................

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
---
M include/osmocom/gsm/tlv.h
1 file changed, 16 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/73/12373/1

diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h
index 4c39264..621a282 100644
--- a/include/osmocom/gsm/tlv.h
+++ b/include/osmocom/gsm/tlv.h
@@ -495,6 +495,22 @@
 	(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

-- 
To view, visit https://gerrit.osmocom.org/12373
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0a148bd04b8860e321f509fdcd913f688c8e920
Gerrit-Change-Number: 12373
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181219/a387df0c/attachment.htm>


More information about the gerrit-log mailing list