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