xref: /haiku/headers/private/package/hpkg/HPKGDefsPrivate.h (revision 1f633814fa347b0bd822f683af731615df600347)
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 
28 	// heap
29 	uint32	heap_compression;
30 	uint32	heap_chunk_size;
31 	uint64	heap_size_compressed;
32 	uint64	heap_size_uncompressed;
33 
34 	// package attributes section
35 	uint32	attributes_length;
36 	uint32	attributes_strings_length;
37 	uint32	attributes_strings_count;
38 
39 	// TOC section
40 	uint64	toc_length;
41 	uint64	toc_strings_length;
42 	uint64	toc_strings_count;
43 };
44 
45 
46 // repository file header
47 struct hpkg_repo_header {
48 	uint32	magic;							// "hpkr"
49 	uint16	header_size;
50 	uint16	version;
51 	uint64	total_size;
52 
53 	// heap
54 	uint32	heap_compression;
55 	uint32	heap_chunk_size;
56 	uint64	heap_size_compressed;
57 	uint64	heap_size_uncompressed;
58 
59 	// repository info section
60 	uint32	info_length;
61 
62 	// package attributes section
63 	uint64	packages_length;
64 	uint64	packages_strings_length;
65 	uint64	packages_strings_count;
66 };
67 
68 
69 // attribute tag arithmetics
70 // (using 6 bits for id, 3 for type, 1 for hasChildren and 2 for encoding)
71 static inline uint16
72 compose_attribute_tag(uint16 id, uint16 type, uint16 encoding, bool hasChildren)
73 {
74 	return ((encoding << 10) | (uint16(hasChildren ? 1 : 0) << 9) | (type << 6)
75 			| id)
76 		+ 1;
77 }
78 
79 
80 static inline uint16
81 attribute_tag_encoding(uint16 tag)
82 {
83 	return ((tag - 1) >> 10) & 0x3;
84 }
85 
86 
87 static inline bool
88 attribute_tag_has_children(uint16 tag)
89 {
90 	return (((tag - 1) >> 9) & 0x1) != 0;
91 }
92 
93 
94 static inline uint16
95 attribute_tag_type(uint16 tag)
96 {
97 	return ((tag - 1) >> 6) & 0x7;
98 }
99 
100 
101 static inline uint16
102 attribute_tag_id(uint16 tag)
103 {
104 	return (tag - 1) & 0x3f;
105 }
106 
107 
108 }	// namespace BPrivate
109 
110 }	// namespace BHPKG
111 
112 }	// namespace BPackageKit
113 
114 
115 #endif	// _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
116