Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a TLV::Tag for TLV tags. #10162

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/lib/core/CHIPTLVTags.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
namespace chip {
namespace TLV {

typedef uint64_t Tag;

enum TLVCommonProfiles
{
/**
Expand Down Expand Up @@ -86,7 +88,7 @@ enum
* @param[in] tagNum The profile-specific tag number assigned to the tag.
* @return A 64-bit integer representing the tag.
*/
inline constexpr uint64_t ProfileTag(uint32_t profileId, uint32_t tagNum)
inline constexpr Tag ProfileTag(uint32_t profileId, uint32_t tagNum)
{
return ((static_cast<uint64_t>(profileId)) << kProfileIdShift) | tagNum;
}
Expand All @@ -99,7 +101,7 @@ inline constexpr uint64_t ProfileTag(uint32_t profileId, uint32_t tagNum)
* @param[in] tagNum The profile-specific tag number assigned to the tag.
* @return A 64-bit integer representing the tag.
*/
inline uint64_t ProfileTag(uint16_t vendorId, uint16_t profileNum, uint32_t tagNum)
inline Tag ProfileTag(uint16_t vendorId, uint16_t profileNum, uint32_t tagNum)
{
return ((static_cast<uint64_t>(vendorId)) << kVendorIdShift) | ((static_cast<uint64_t>(profileNum)) << kProfileNumShift) |
tagNum;
Expand All @@ -111,7 +113,7 @@ inline uint64_t ProfileTag(uint16_t vendorId, uint16_t profileNum, uint32_t tagN
* @param[in] tagNum The context-specific tag number assigned to the tag.
* @return A 64-bit integer representing the tag.
*/
inline constexpr uint64_t ContextTag(uint8_t tagNum)
inline constexpr Tag ContextTag(uint8_t tagNum)
{
return kSpecialTagMarker | tagNum;
}
Expand All @@ -122,7 +124,7 @@ inline constexpr uint64_t ContextTag(uint8_t tagNum)
* @param[in] tagNum The common profile tag number assigned to the tag.
* @return A 64-bit integer representing the tag.
*/
inline uint64_t CommonTag(uint32_t tagNum)
inline Tag CommonTag(uint32_t tagNum)
{
return ProfileTag(kCommonProfileId, tagNum);
}
Expand All @@ -146,7 +148,7 @@ enum
* @param[in] tag The API representation of a profile-specific TLV tag.
* @return The profile id.
*/
inline uint32_t ProfileIdFromTag(uint64_t tag)
inline uint32_t ProfileIdFromTag(Tag tag)
{
return static_cast<uint32_t>((tag & kProfileIdMask) >> kProfileIdShift);
}
Expand All @@ -159,7 +161,7 @@ inline uint32_t ProfileIdFromTag(uint64_t tag)
* @param[in] tag The API representation of a profile-specific TLV tag.
* @return The associated profile number.
*/
inline uint16_t ProfileNumFromTag(uint64_t tag)
inline uint16_t ProfileNumFromTag(Tag tag)
{
return static_cast<uint16_t>((tag & kProfileIdMask) >> kProfileIdShift);
}
Expand All @@ -175,7 +177,7 @@ inline uint16_t ProfileNumFromTag(uint64_t tag)
* @param[in] tag The API representation of a profile-specific or context-specific TLV tag.
* @return The associated tag number.
*/
inline uint32_t TagNumFromTag(uint64_t tag)
inline uint32_t TagNumFromTag(Tag tag)
{
return static_cast<uint32_t>(tag & kTagNumMask);
}
Expand All @@ -188,29 +190,29 @@ inline uint32_t TagNumFromTag(uint64_t tag)
* @param[in] tag The API representation of a profile-specific TLV tag.
* @return The associated vendor id.
*/
inline uint16_t VendorIdFromTag(uint64_t tag)
inline uint16_t VendorIdFromTag(Tag tag)
{
return static_cast<uint16_t>((tag & kProfileIdMask) >> kVendorIdShift);
}

/**
* Returns true of the supplied tag is a profile-specific tag.
*/
inline bool IsProfileTag(uint64_t tag)
inline bool IsProfileTag(Tag tag)
{
return (tag & kProfileIdMask) != kSpecialTagMarker;
}

/**
* Returns true if the supplied tag is a context-specific tag.
*/
inline bool IsContextTag(uint64_t tag)
inline bool IsContextTag(Tag tag)
{
return (tag & kProfileIdMask) == kSpecialTagMarker && TagNumFromTag(tag) < kContextTagMaxNum;
}

// TODO: move to private namespace
inline bool IsSpecialTag(uint64_t tag)
inline bool IsSpecialTag(Tag tag)
{
return (tag & kProfileIdMask) == kSpecialTagMarker;
}
Expand Down