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
14namespace BPackageKit {
15
16namespace BHPKG {
17
18namespace BPrivate {
19
20
21// header
22struct hpkg_header {
23	uint32	magic;							// "hpkg"
24	uint16	header_size;
25	uint16	version;
26	uint64	total_size;
27
28	// package attributes section
29	uint32	attributes_compression;
30	uint32	attributes_length_compressed;
31	uint32	attributes_length_uncompressed;
32	uint32	attributes_strings_length;
33	uint32	attributes_strings_count;
34
35	// TOC section
36	uint32	toc_compression;
37	uint64	toc_length_compressed;
38	uint64	toc_length_uncompressed;
39	uint64	toc_strings_length;
40	uint64	toc_strings_count;
41};
42
43
44// header
45struct hpkg_repo_header {
46	uint32	magic;							// "hpkr"
47	uint16	header_size;
48	uint16	version;
49	uint64	total_size;
50
51	// repository info section
52	uint32	info_compression;
53	uint32	info_length_compressed;
54	uint32	info_length_uncompressed;
55
56	// package attributes section
57	uint32	packages_compression;
58	uint64	packages_length_compressed;
59	uint64	packages_length_uncompressed;
60	uint64	packages_strings_length;
61	uint64	packages_strings_count;
62};
63
64
65// attribute tag arithmetics
66// (using 6 bits for id, 3 for type, 1 for hasChildren and 2 for encoding)
67#define HPKG_ATTRIBUTE_TAG_COMPOSE(id, type, encoding, hasChildren) 	\
68	(((uint16(encoding) << 10) | (uint16((hasChildren) ? 1 : 0) << 9)	\
69		| (uint16(type) << 6) | (uint16(id))) + 1)
70#define HPKG_ATTRIBUTE_TAG_ENCODING(tag)		\
71	((uint16((tag) - 1) >> 10) & 0x3)
72#define HPKG_ATTRIBUTE_TAG_HAS_CHILDREN(tag)	\
73	(((uint16((tag) - 1) >> 9) & 0x1) != 0)
74#define HPKG_ATTRIBUTE_TAG_TYPE(tag)			\
75	((uint16((tag) - 1) >> 6) & 0x7)
76#define HPKG_ATTRIBUTE_TAG_ID(tag)				\
77	(uint16((tag) - 1) & 0x3f)
78
79
80}	// namespace BPrivate
81
82}	// namespace BHPKG
83
84}	// namespace BPackageKit
85
86
87#endif	// _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
88