1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _PACKAGE__HPKG__V1__PRIVATE__HAIKU_PACKAGE_H_ 6 #define _PACKAGE__HPKG__V1__PRIVATE__HAIKU_PACKAGE_H_ 7 8 9 #include <SupportDefs.h> 10 11 #include <package/hpkg/HPKGDefs.h> 12 13 14 namespace BPackageKit { 15 16 namespace BHPKG { 17 18 namespace V1 { 19 20 namespace BPrivate { 21 22 23 // header 24 struct hpkg_header { 25 uint32 magic; // "hpkg" 26 uint16 header_size; 27 uint16 version; 28 uint64 total_size; 29 30 // package attributes section 31 uint32 attributes_compression; 32 uint32 attributes_length_compressed; 33 uint32 attributes_length_uncompressed; 34 uint32 attributes_strings_length; 35 uint32 attributes_strings_count; 36 37 // TOC section 38 uint32 toc_compression; 39 uint64 toc_length_compressed; 40 uint64 toc_length_uncompressed; 41 uint64 toc_strings_length; 42 uint64 toc_strings_count; 43 }; 44 45 46 // header 47 struct hpkg_repo_header { 48 uint32 magic; // "hpkr" 49 uint16 header_size; 50 uint16 version; 51 uint64 total_size; 52 53 // repository info section 54 uint32 info_compression; 55 uint32 info_length_compressed; 56 uint32 info_length_uncompressed; 57 58 // package attributes section 59 uint32 packages_compression; 60 uint64 packages_length_compressed; 61 uint64 packages_length_uncompressed; 62 uint64 packages_strings_length; 63 uint64 packages_strings_count; 64 }; 65 66 67 // attribute tag arithmetics 68 // (using 6 bits for id, 3 for type, 1 for hasChildren and 2 for encoding) 69 static inline uint16 70 compose_attribute_tag(uint16 id, uint16 type, uint16 encoding, bool hasChildren) 71 { 72 return ((encoding << 10) | (uint16(hasChildren ? 1 : 0) << 9) | (type << 6) 73 | id) 74 + 1; 75 } 76 77 78 static inline uint16 79 attribute_tag_encoding(uint16 tag) 80 { 81 return ((tag - 1) >> 10) & 0x3; 82 } 83 84 85 static inline bool 86 attribute_tag_has_children(uint16 tag) 87 { 88 return (((tag - 1) >> 9) & 0x1) != 0; 89 } 90 91 92 static inline uint16 93 attribute_tag_type(uint16 tag) 94 { 95 return ((tag - 1) >> 6) & 0x7; 96 } 97 98 99 static inline uint16 100 attribute_tag_id(uint16 tag) 101 { 102 return (tag - 1) & 0x3f; 103 } 104 105 106 } // namespace BPrivate 107 108 } // namespace V1 109 110 } // namespace BHPKG 111 112 } // namespace BPackageKit 113 114 115 #endif // _PACKAGE__HPKG__V1__PRIVATE__HAIKU_PACKAGE_H_ 116