• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2010 Codethink Limited
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  *
17  * Author: Ryan Lortie <desrt@desrt.ca>
18  */
19 
20 #ifndef __gvdb_format_h__
21 #define __gvdb_format_h__
22 
23 #include <glib.h>
24 
25 typedef struct { guint16 value; } guint16_le;
26 typedef struct { guint32 value; } guint32_le;
27 
28 struct gvdb_pointer {
29   guint32_le start;
30   guint32_le end;
31 };
32 
33 struct gvdb_hash_header {
34   guint32_le n_bloom_words;
35   guint32_le n_buckets;
36 };
37 
38 struct gvdb_hash_item {
39   guint32_le hash_value;
40   guint32_le parent;
41 
42   guint32_le key_start;
43   guint16_le key_size;
44   gchar type;
45   gchar unused;
46 
47   union
48   {
49     struct gvdb_pointer pointer;
50     gchar direct[8];
51   } value;
52 };
53 
54 struct gvdb_header {
55   guint32 signature[2];
56   guint32_le version;
57   guint32_le options;
58 
59   struct gvdb_pointer root;
60 };
61 
guint32_to_le(guint32 value)62 static inline guint32_le guint32_to_le (guint32 value) {
63   guint32_le result = { GUINT32_TO_LE (value) };
64   return result;
65 }
66 
guint32_from_le(guint32_le value)67 static inline guint32 guint32_from_le (guint32_le value) {
68   return GUINT32_FROM_LE (value.value);
69 }
70 
guint16_to_le(guint16 value)71 static inline guint16_le guint16_to_le (guint16 value) {
72   guint16_le result = { GUINT16_TO_LE (value) };
73   return result;
74 }
75 
guint16_from_le(guint16_le value)76 static inline guint16 guint16_from_le (guint16_le value) {
77   return GUINT16_FROM_LE (value.value);
78 }
79 
80 #define GVDB_SIGNATURE0 1918981703
81 #define GVDB_SIGNATURE1 1953390953
82 #define GVDB_SWAPPED_SIGNATURE0 GUINT32_SWAP_LE_BE (GVDB_SIGNATURE0)
83 #define GVDB_SWAPPED_SIGNATURE1 GUINT32_SWAP_LE_BE (GVDB_SIGNATURE1)
84 
85 #endif /* __gvdb_format_h__ */
86