hpkg attribute tags: use 7 bits for attribute ID

ATM the 6 bits suffice, but there isn't that much headroom.
This commit is contained in:
Ingo Weinhold 2013-05-23 21:17:29 +02:00
parent 4ffb923413
commit 5497f08e5e

View File

@ -71,11 +71,11 @@ struct hpkg_repo_header {
// attribute tag arithmetics // attribute tag arithmetics
// (using 6 bits for id, 3 for type, 1 for hasChildren and 2 for encoding) // (using 7 bits for id, 3 for type, 1 for hasChildren and 2 for encoding)
static inline uint16 static inline uint16
compose_attribute_tag(uint16 id, uint16 type, uint16 encoding, bool hasChildren) compose_attribute_tag(uint16 id, uint16 type, uint16 encoding, bool hasChildren)
{ {
return ((encoding << 10) | (uint16(hasChildren ? 1 : 0) << 9) | (type << 6) return ((encoding << 11) | (uint16(hasChildren ? 1 : 0) << 10) | (type << 7)
| id) | id)
+ 1; + 1;
} }
@ -84,28 +84,28 @@ compose_attribute_tag(uint16 id, uint16 type, uint16 encoding, bool hasChildren)
static inline uint16 static inline uint16
attribute_tag_encoding(uint16 tag) attribute_tag_encoding(uint16 tag)
{ {
return ((tag - 1) >> 10) & 0x3; return ((tag - 1) >> 11) & 0x3;
} }
static inline bool static inline bool
attribute_tag_has_children(uint16 tag) attribute_tag_has_children(uint16 tag)
{ {
return (((tag - 1) >> 9) & 0x1) != 0; return (((tag - 1) >> 10) & 0x1) != 0;
} }
static inline uint16 static inline uint16
attribute_tag_type(uint16 tag) attribute_tag_type(uint16 tag)
{ {
return ((tag - 1) >> 6) & 0x7; return ((tag - 1) >> 7) & 0x7;
} }
static inline uint16 static inline uint16
attribute_tag_id(uint16 tag) attribute_tag_id(uint16 tag)
{ {
return (tag - 1) & 0x3f; return (tag - 1) & 0x7f;
} }