1 #ifndef __DB___GWEATHER_GV__H__
2 #define __DB___GWEATHER_GV__H__
3 /* generated code for gweather.gv */
4 #include <string.h>
5 #include <glib.h>
6 
7 /********** Basic types *****************/
8 
9 typedef struct {
10  gconstpointer base;
11  gsize size;
12 } DbRef;
13 
14 #define DB_REF_READ_FRAME_OFFSET(_v, _index) Db_ref_read_unaligned_le ((guchar*)((_v).base) + (_v).size - (offset_size * ((_index) + 1)), offset_size)
15 #define DB_REF_ALIGN(_offset, _align_to) ((_offset + _align_to - 1) & ~(gsize)(_align_to - 1))
16 
17 /* Note: clz is undefinded for 0, so never call this size == 0 */
18 G_GNUC_CONST static inline guint
Db_ref_get_offset_size(gsize size)19 Db_ref_get_offset_size (gsize size)
20 {
21 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) && defined(__LP64__)
22   /* Instead of using a lookup table we use nibbles in a lookup word */
23   guint32 v = (guint32)0x88884421;
24   return (v >> (((__builtin_clzl(size) ^ 63) / 8) * 4)) & 0xf;
25 #else
26   if (size > G_MAXUINT16)
27     {
28       if (size > G_MAXUINT32)
29         return 8;
30       else
31         return 4;
32     }
33   else
34     {
35       if (size > G_MAXUINT8)
36          return 2;
37       else
38          return 1;
39     }
40 #endif
41 }
42 
43 G_GNUC_PURE static inline guint64
Db_ref_read_unaligned_le(guchar * bytes,guint size)44 Db_ref_read_unaligned_le (guchar *bytes, guint   size)
45 {
46   union
47   {
48     guchar bytes[8];
49     guint64 integer;
50   } tmpvalue;
51 
52   tmpvalue.integer = 0;
53   /* we unroll the size checks here so that memcpy gets constant args */
54   if (size >= 4)
55     {
56       if (size == 8)
57         memcpy (&tmpvalue.bytes, bytes, 8);
58       else
59         memcpy (&tmpvalue.bytes, bytes, 4);
60     }
61   else
62     {
63       if (size == 2)
64         memcpy (&tmpvalue.bytes, bytes, 2);
65       else
66         memcpy (&tmpvalue.bytes, bytes, 1);
67     }
68 
69   return GUINT64_FROM_LE (tmpvalue.integer);
70 }
71 
72 static inline void
__Db_gstring_append_double(GString * string,double d)73 __Db_gstring_append_double (GString *string, double d)
74 {
75   gchar buffer[100];
76   gint i;
77 
78   g_ascii_dtostr (buffer, sizeof buffer, d);
79   for (i = 0; buffer[i]; i++)
80     if (buffer[i] == '.' || buffer[i] == 'e' ||
81         buffer[i] == 'n' || buffer[i] == 'N')
82       break;
83 
84   /* if there is no '.' or 'e' in the float then add one */
85   if (buffer[i] == '\0')
86     {
87       buffer[i++] = '.';
88       buffer[i++] = '0';
89       buffer[i++] = '\0';
90     }
91    g_string_append (string, buffer);
92 }
93 
94 static inline void
__Db_gstring_append_string(GString * string,const char * str)95 __Db_gstring_append_string (GString *string, const char *str)
96 {
97   gunichar quote = strchr (str, '\'') ? '"' : '\'';
98 
99   g_string_append_c (string, quote);
100   while (*str)
101     {
102       gunichar c = g_utf8_get_char (str);
103 
104       if (c == quote || c == '\\')
105         g_string_append_c (string, '\\');
106 
107       if (g_unichar_isprint (c))
108         g_string_append_unichar (string, c);
109       else
110         {
111           g_string_append_c (string, '\\');
112           if (c < 0x10000)
113             switch (c)
114               {
115               case '\a':
116                 g_string_append_c (string, 'a');
117                 break;
118 
119               case '\b':
120                 g_string_append_c (string, 'b');
121                 break;
122 
123               case '\f':
124                 g_string_append_c (string, 'f');
125                 break;
126 
127               case '\n':
128                 g_string_append_c (string, 'n');
129                 break;
130 
131               case '\r':
132                 g_string_append_c (string, 'r');
133                 break;
134 
135               case '\t':
136                 g_string_append_c (string, 't');
137                 break;
138 
139               case '\v':
140                 g_string_append_c (string, 'v');
141                 break;
142 
143               default:
144                 g_string_append_printf (string, "u%04x", c);
145                 break;
146               }
147            else
148              g_string_append_printf (string, "U%08x", c);
149         }
150 
151       str = g_utf8_next_char (str);
152     }
153 
154   g_string_append_c (string, quote);
155 }
156 
157 /************** DbVariantRef *******************/
158 
159 typedef struct {
160  gconstpointer base;
161  gsize size;
162 } DbVariantRef;
163 
164 static inline DbRef
Db_variant_get_child(DbVariantRef v,const GVariantType ** out_type)165 Db_variant_get_child (DbVariantRef v, const GVariantType **out_type)
166 {
167   if (v.size)
168     {
169       guchar *base = (guchar *)v.base;
170       gsize size = v.size - 1;
171 
172       /* find '\0' character */
173       while (size > 0 && base[size] != 0)
174         size--;
175 
176       /* ensure we didn't just hit the start of the string */
177       if (base[size] == 0)
178        {
179           const char *type_string = (char *) base + size + 1;
180           const char *limit = (char *)base + v.size;
181           const char *end;
182 
183           if (g_variant_type_string_scan (type_string, limit, &end) && end == limit)
184             {
185               if (out_type)
186                 *out_type = (const GVariantType *)type_string;
187               return (DbRef) { v.base, size };
188             }
189        }
190     }
191   if (out_type)
192     *out_type = G_VARIANT_TYPE_UNIT;
193   return  (DbRef) { "\0", 1 };
194 }
195 
196 static inline const GVariantType *
Db_variant_get_type(DbVariantRef v)197 Db_variant_get_type (DbVariantRef v)
198 {
199   if (v.size)
200     {
201       guchar *base = (guchar *)v.base;
202       gsize size = v.size - 1;
203 
204       /* find '\0' character */
205       while (size > 0 && base[size] != 0)
206         size--;
207 
208       /* ensure we didn't just hit the start of the string */
209       if (base[size] == 0)
210        {
211           const char *type_string = (char *) base + size + 1;
212           const char *limit = (char *)base + v.size;
213           const char *end;
214 
215           if (g_variant_type_string_scan (type_string, limit, &end) && end == limit)
216              return (const GVariantType *)type_string;
217        }
218     }
219   return  G_VARIANT_TYPE_UNIT;
220 }
221 
222 static inline gboolean
Db_variant_is_type(DbVariantRef v,const GVariantType * type)223 Db_variant_is_type (DbVariantRef v, const GVariantType *type)
224 {
225    return g_variant_type_equal (Db_variant_get_type (v), type);
226 }
227 
228 static inline DbVariantRef
Db_variant_from_gvariant(GVariant * v)229 Db_variant_from_gvariant (GVariant *v)
230 {
231   g_assert (g_variant_type_equal (g_variant_get_type (v), G_VARIANT_TYPE_VARIANT));
232   return (DbVariantRef) { g_variant_get_data (v), g_variant_get_size (v) };
233 }
234 
235 static inline DbVariantRef
Db_variant_from_bytes(GBytes * b)236 Db_variant_from_bytes (GBytes *b)
237 {
238   return (DbVariantRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
239 }
240 
241 static inline DbVariantRef
Db_variant_from_data(gconstpointer data,gsize size)242 Db_variant_from_data (gconstpointer data, gsize size)
243 {
244   return (DbVariantRef) { data, size };
245 }
246 
247 static inline GVariant *
Db_variant_dup_to_gvariant(DbVariantRef v)248 Db_variant_dup_to_gvariant (DbVariantRef v)
249 {
250   return g_variant_new_from_data (G_VARIANT_TYPE_VARIANT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
251 }
252 
253 static inline GVariant *
Db_variant_to_gvariant(DbVariantRef v,GDestroyNotify notify,gpointer user_data)254 Db_variant_to_gvariant (DbVariantRef v,
255                               GDestroyNotify      notify,
256                               gpointer            user_data)
257 {
258   return g_variant_new_from_data (G_VARIANT_TYPE_VARIANT, g_memdup (v.base, v.size), v.size, TRUE, notify, user_data);
259 }
260 
261 static inline GVariant *
Db_variant_to_owned_gvariant(DbVariantRef v,GVariant * base)262 Db_variant_to_owned_gvariant (DbVariantRef v,
263                                      GVariant *base)
264 {
265   return Db_variant_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
266 }
267 
268 static inline GVariant *
Db_variant_peek_as_variant(DbVariantRef v)269 Db_variant_peek_as_variant (DbVariantRef v)
270 {
271   return g_variant_new_from_data (G_VARIANT_TYPE_VARIANT, v.base, v.size, TRUE, NULL, NULL);
272 }
273 
274 static inline DbVariantRef
Db_variant_from_variant(DbVariantRef v)275 Db_variant_from_variant (DbVariantRef v)
276 {
277   const GVariantType  *type;
278   DbRef child = Db_variant_get_child (v, &type);
279   g_assert (g_variant_type_equal(type, G_VARIANT_TYPE_VARIANT));
280   return Db_variant_from_data (child.base, child.size);
281 }
282 
283 static inline GVariant *
Db_variant_dup_child_to_gvariant(DbVariantRef v)284 Db_variant_dup_child_to_gvariant (DbVariantRef v)
285 {
286   const GVariantType  *type;
287   DbRef child = Db_variant_get_child (v, &type);
288   return g_variant_new_from_data (type, g_memdup (child.base, child.size), child.size, TRUE, g_free, NULL);
289 }
290 
291 static inline GVariant *
Db_variant_peek_child_as_variant(DbVariantRef v)292 Db_variant_peek_child_as_variant (DbVariantRef v)
293 {
294   const GVariantType  *type;
295   DbRef child = Db_variant_get_child (v, &type);
296   return g_variant_new_from_data (type, child.base, child.size, TRUE, NULL, NULL);
297 }
298 
299 static inline GString *
Db_variant_format(DbVariantRef v,GString * s,gboolean type_annotate)300 Db_variant_format (DbVariantRef v, GString *s, gboolean type_annotate)
301 {
302 #ifdef DB_DEEP_VARIANT_FORMAT
303   GVariant *gv = Db_variant_peek_as_variant (v);
304   return g_variant_print_string (gv, s, TRUE);
305 #else
306   const GVariantType  *type = Db_variant_get_type (v);
307   g_string_append_printf (s, "<@%.*s>", (int)g_variant_type_get_string_length (type), (const char *)type);
308   return s;
309 #endif
310 }
311 
312 static inline char *
Db_variant_print(DbVariantRef v,gboolean type_annotate)313 Db_variant_print (DbVariantRef v, gboolean type_annotate)
314 {
315   GString *s = g_string_new ("");
316   Db_variant_format (v, s, type_annotate);
317   return g_string_free (s, FALSE);
318 }
319 static inline gboolean
Db_variant_get_boolean(DbVariantRef v)320 Db_variant_get_boolean (DbVariantRef v)
321 {
322   return (gboolean)*((guint8 *)v.base);
323 }
324 static inline guint8
Db_variant_get_byte(DbVariantRef v)325 Db_variant_get_byte (DbVariantRef v)
326 {
327   return (guint8)*((guint8 *)v.base);
328 }
329 static inline gint16
Db_variant_get_int16(DbVariantRef v)330 Db_variant_get_int16 (DbVariantRef v)
331 {
332   return (gint16)*((gint16 *)v.base);
333 }
334 static inline guint16
Db_variant_get_uint16(DbVariantRef v)335 Db_variant_get_uint16 (DbVariantRef v)
336 {
337   return (guint16)*((guint16 *)v.base);
338 }
339 static inline gint32
Db_variant_get_int32(DbVariantRef v)340 Db_variant_get_int32 (DbVariantRef v)
341 {
342   return (gint32)*((gint32 *)v.base);
343 }
344 static inline guint32
Db_variant_get_uint32(DbVariantRef v)345 Db_variant_get_uint32 (DbVariantRef v)
346 {
347   return (guint32)*((guint32 *)v.base);
348 }
349 static inline gint64
Db_variant_get_int64(DbVariantRef v)350 Db_variant_get_int64 (DbVariantRef v)
351 {
352   return (gint64)*((gint64 *)v.base);
353 }
354 static inline guint64
Db_variant_get_uint64(DbVariantRef v)355 Db_variant_get_uint64 (DbVariantRef v)
356 {
357   return (guint64)*((guint64 *)v.base);
358 }
359 static inline guint32
Db_variant_get_handle(DbVariantRef v)360 Db_variant_get_handle (DbVariantRef v)
361 {
362   return (guint32)*((guint32 *)v.base);
363 }
364 static inline double
Db_variant_get_double(DbVariantRef v)365 Db_variant_get_double (DbVariantRef v)
366 {
367   return (double)*((double *)v.base);
368 }
369 static inline const char *
Db_variant_get_string(DbVariantRef v)370 Db_variant_get_string (DbVariantRef v)
371 {
372   return (const char *)v.base;
373 }
374 static inline const char *
Db_variant_get_objectpath(DbVariantRef v)375 Db_variant_get_objectpath (DbVariantRef v)
376 {
377   return (const char *)v.base;
378 }
379 static inline const char *
Db_variant_get_signature(DbVariantRef v)380 Db_variant_get_signature (DbVariantRef v)
381 {
382   return (const char *)v.base;
383 }
384 
385 /************** DbI18n *******************/
386 #define DB_I18N_TYPESTRING "(ss)"
387 #define DB_I18N_TYPEFORMAT ((const GVariantType *) DB_I18N_TYPESTRING)
388 
389 typedef struct {
390  gconstpointer base;
391  gsize size;
392 } DbI18nRef;
393 
394 
395 static inline DbI18nRef
db_i18n_from_gvariant(GVariant * v)396 db_i18n_from_gvariant (GVariant *v)
397 {
398   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_I18N_TYPESTRING));
399   return (DbI18nRef) { g_variant_get_data (v), g_variant_get_size (v) };
400 }
401 
402 static inline DbI18nRef
db_i18n_from_bytes(GBytes * b)403 db_i18n_from_bytes (GBytes *b)
404 {
405   return (DbI18nRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
406 }
407 
408 static inline DbI18nRef
db_i18n_from_data(gconstpointer data,gsize size)409 db_i18n_from_data (gconstpointer data, gsize size)
410 {
411   return (DbI18nRef) { data, size };
412 }
413 
414 static inline GVariant *
db_i18n_dup_to_gvariant(DbI18nRef v)415 db_i18n_dup_to_gvariant (DbI18nRef v)
416 {
417   return g_variant_new_from_data (DB_I18N_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
418 }
419 
420 static inline GVariant *
db_i18n_to_gvariant(DbI18nRef v,GDestroyNotify notify,gpointer user_data)421 db_i18n_to_gvariant (DbI18nRef v,
422                              GDestroyNotify      notify,
423                              gpointer            user_data)
424 {
425   return g_variant_new_from_data (DB_I18N_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
426 }
427 
428 static inline GVariant *
db_i18n_to_owned_gvariant(DbI18nRef v,GVariant * base)429 db_i18n_to_owned_gvariant (DbI18nRef v, GVariant *base)
430 {
431   return db_i18n_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
432 }
433 
434 static inline GVariant *
db_i18n_peek_as_gvariant(DbI18nRef v)435 db_i18n_peek_as_gvariant (DbI18nRef v)
436 {
437   return g_variant_new_from_data (DB_I18N_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
438 }
439 
440 static inline DbI18nRef
db_i18n_from_variant(DbVariantRef v)441 db_i18n_from_variant (DbVariantRef v)
442 {
443   const GVariantType  *type;
444   DbRef child = Db_variant_get_child (v, &type);
445   g_assert (g_variant_type_equal(type, DB_I18N_TYPESTRING));
446   return db_i18n_from_data (child.base, child.size);
447 }
448 
449 #define DB_I18N_INDEXOF_STR 0
450 
451 static inline const char *
db_i18n_get_str(DbI18nRef v)452 db_i18n_get_str (DbI18nRef v)
453 {
454   guint offset_size = Db_ref_get_offset_size (v.size);
455   guint offset = ((0) & (~(gsize)0)) + 0;
456   const char *base = (const char *)v.base;
457   gsize start = offset;
458   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
459   g_assert (start <= end);
460   g_assert (end <= v.size);
461   g_assert (base[end-1] == 0);
462   return &G_STRUCT_MEMBER(const char, v.base, start);
463 }
464 
465 #define DB_I18N_INDEXOF_MSGCTXT 1
466 
467 static inline const char *
db_i18n_get_msgctxt(DbI18nRef v)468 db_i18n_get_msgctxt (DbI18nRef v)
469 {
470   guint offset_size = Db_ref_get_offset_size (v.size);
471   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
472   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
473   const char *base = (const char *)v.base;
474   gsize start = offset;
475   G_GNUC_UNUSED gsize end = v.size - offset_size * 1;
476   g_assert (start <= end);
477   g_assert (end <= v.size);
478   g_assert (base[end-1] == 0);
479   return &G_STRUCT_MEMBER(const char, v.base, start);
480 }
481 
482 static inline GString *
db_i18n_format(DbI18nRef v,GString * s,gboolean type_annotate)483 db_i18n_format (DbI18nRef v, GString *s, gboolean type_annotate)
484 {
485   g_string_append (s, "(");
486   __Db_gstring_append_string (s, db_i18n_get_str (v));
487   g_string_append (s, ", ");
488   __Db_gstring_append_string (s, db_i18n_get_msgctxt (v));
489   g_string_append (s, ")");
490   return s;
491 }
492 
493 static inline char *
db_i18n_print(DbI18nRef v,gboolean type_annotate)494 db_i18n_print (DbI18nRef v, gboolean type_annotate)
495 {
496   GString *s = g_string_new ("");
497   db_i18n_format (v, s, type_annotate);
498   return g_string_free (s, FALSE);
499 }
500 
501 /************** DbArrayofstring *******************/
502 #define DB_ARRAYOFSTRING_TYPESTRING "as"
503 #define DB_ARRAYOFSTRING_TYPEFORMAT ((const GVariantType *) DB_ARRAYOFSTRING_TYPESTRING)
504 
505 typedef struct {
506  gconstpointer base;
507  gsize size;
508 } DbArrayofstringRef;
509 
510 
511 static inline DbArrayofstringRef
db_arrayofstring_from_gvariant(GVariant * v)512 db_arrayofstring_from_gvariant (GVariant *v)
513 {
514   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_ARRAYOFSTRING_TYPESTRING));
515   return (DbArrayofstringRef) { g_variant_get_data (v), g_variant_get_size (v) };
516 }
517 
518 static inline DbArrayofstringRef
db_arrayofstring_from_bytes(GBytes * b)519 db_arrayofstring_from_bytes (GBytes *b)
520 {
521   return (DbArrayofstringRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
522 }
523 
524 static inline DbArrayofstringRef
db_arrayofstring_from_data(gconstpointer data,gsize size)525 db_arrayofstring_from_data (gconstpointer data, gsize size)
526 {
527   return (DbArrayofstringRef) { data, size };
528 }
529 
530 static inline GVariant *
db_arrayofstring_dup_to_gvariant(DbArrayofstringRef v)531 db_arrayofstring_dup_to_gvariant (DbArrayofstringRef v)
532 {
533   return g_variant_new_from_data (DB_ARRAYOFSTRING_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
534 }
535 
536 static inline GVariant *
db_arrayofstring_to_gvariant(DbArrayofstringRef v,GDestroyNotify notify,gpointer user_data)537 db_arrayofstring_to_gvariant (DbArrayofstringRef v,
538                              GDestroyNotify      notify,
539                              gpointer            user_data)
540 {
541   return g_variant_new_from_data (DB_ARRAYOFSTRING_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
542 }
543 
544 static inline GVariant *
db_arrayofstring_to_owned_gvariant(DbArrayofstringRef v,GVariant * base)545 db_arrayofstring_to_owned_gvariant (DbArrayofstringRef v, GVariant *base)
546 {
547   return db_arrayofstring_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
548 }
549 
550 static inline GVariant *
db_arrayofstring_peek_as_gvariant(DbArrayofstringRef v)551 db_arrayofstring_peek_as_gvariant (DbArrayofstringRef v)
552 {
553   return g_variant_new_from_data (DB_ARRAYOFSTRING_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
554 }
555 
556 static inline DbArrayofstringRef
db_arrayofstring_from_variant(DbVariantRef v)557 db_arrayofstring_from_variant (DbVariantRef v)
558 {
559   const GVariantType  *type;
560   DbRef child = Db_variant_get_child (v, &type);
561   g_assert (g_variant_type_equal(type, DB_ARRAYOFSTRING_TYPESTRING));
562   return db_arrayofstring_from_data (child.base, child.size);
563 }
564 
565 static inline gsize
db_arrayofstring_get_length(DbArrayofstringRef v)566 db_arrayofstring_get_length (DbArrayofstringRef v)
567 {
568   if (v.size == 0)
569     return 0;
570   guint offset_size = Db_ref_get_offset_size (v.size);
571   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
572   gsize offsets_array_size;
573   if (last_end > v.size)
574     return 0;
575   offsets_array_size = v.size - last_end;
576   if (offsets_array_size % offset_size != 0)
577     return 0;
578   gsize length  = offsets_array_size / offset_size;
579   return length;
580 }
581 
582 static inline const char *
db_arrayofstring_get_at(DbArrayofstringRef v,gsize index)583 db_arrayofstring_get_at (DbArrayofstringRef v, gsize index)
584 {
585   guint offset_size = Db_ref_get_offset_size (v.size);
586   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
587   gsize len = (v.size - last_end) / offset_size;
588   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 1) : 0;
589   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, len - index - 1);
590   g_assert (start <= end);
591   g_assert (end <= last_end);
592   const char *base = (const char *)v.base;
593   g_assert (base[end-1] == 0);
594   return base + start;
595 }
596 
597 static inline const char **
db_arrayofstring_to_strv(DbArrayofstringRef v,gsize * length_out)598 db_arrayofstring_to_strv (DbArrayofstringRef v, gsize *length_out)
599 {
600   gsize length = db_arrayofstring_get_length (v);
601   gsize i;
602   const char **resv = g_new (const char *, length + 1);
603 
604   for (i = 0; i < length; i++)
605     resv[i] = db_arrayofstring_get_at (v, i);
606   resv[i] = NULL;
607 
608   if (length_out)
609     *length_out = length;
610 
611   return resv;
612 }
613 
614 static inline GString *
db_arrayofstring_format(DbArrayofstringRef v,GString * s,gboolean type_annotate)615 db_arrayofstring_format (DbArrayofstringRef v, GString *s, gboolean type_annotate)
616 {
617   gsize len = db_arrayofstring_get_length (v);
618   gsize i;
619   if (len == 0 && type_annotate)
620     g_string_append_printf (s, "@%s ", DB_ARRAYOFSTRING_TYPESTRING);
621   g_string_append_c (s, '[');
622   for (i = 0; i < len; i++)
623     {
624       if (i != 0)
625         g_string_append (s, ", ");
626       __Db_gstring_append_string (s, db_arrayofstring_get_at (v, i));
627     }
628   g_string_append_c (s, ']');
629   return s;
630 }
631 
632 static inline char *
db_arrayofstring_print(DbArrayofstringRef v,gboolean type_annotate)633 db_arrayofstring_print (DbArrayofstringRef v, gboolean type_annotate)
634 {
635   GString *s = g_string_new ("");
636   db_arrayofstring_format (v, s, type_annotate);
637   return g_string_free (s, FALSE);
638 }
639 
640 /************** DbTimezone *******************/
641 #define DB_TIMEZONE_TYPESTRING "((ss)as)"
642 #define DB_TIMEZONE_TYPEFORMAT ((const GVariantType *) DB_TIMEZONE_TYPESTRING)
643 
644 typedef struct {
645  gconstpointer base;
646  gsize size;
647 } DbTimezoneRef;
648 
649 
650 static inline DbTimezoneRef
db_timezone_from_gvariant(GVariant * v)651 db_timezone_from_gvariant (GVariant *v)
652 {
653   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_TIMEZONE_TYPESTRING));
654   return (DbTimezoneRef) { g_variant_get_data (v), g_variant_get_size (v) };
655 }
656 
657 static inline DbTimezoneRef
db_timezone_from_bytes(GBytes * b)658 db_timezone_from_bytes (GBytes *b)
659 {
660   return (DbTimezoneRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
661 }
662 
663 static inline DbTimezoneRef
db_timezone_from_data(gconstpointer data,gsize size)664 db_timezone_from_data (gconstpointer data, gsize size)
665 {
666   return (DbTimezoneRef) { data, size };
667 }
668 
669 static inline GVariant *
db_timezone_dup_to_gvariant(DbTimezoneRef v)670 db_timezone_dup_to_gvariant (DbTimezoneRef v)
671 {
672   return g_variant_new_from_data (DB_TIMEZONE_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
673 }
674 
675 static inline GVariant *
db_timezone_to_gvariant(DbTimezoneRef v,GDestroyNotify notify,gpointer user_data)676 db_timezone_to_gvariant (DbTimezoneRef v,
677                              GDestroyNotify      notify,
678                              gpointer            user_data)
679 {
680   return g_variant_new_from_data (DB_TIMEZONE_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
681 }
682 
683 static inline GVariant *
db_timezone_to_owned_gvariant(DbTimezoneRef v,GVariant * base)684 db_timezone_to_owned_gvariant (DbTimezoneRef v, GVariant *base)
685 {
686   return db_timezone_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
687 }
688 
689 static inline GVariant *
db_timezone_peek_as_gvariant(DbTimezoneRef v)690 db_timezone_peek_as_gvariant (DbTimezoneRef v)
691 {
692   return g_variant_new_from_data (DB_TIMEZONE_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
693 }
694 
695 static inline DbTimezoneRef
db_timezone_from_variant(DbVariantRef v)696 db_timezone_from_variant (DbVariantRef v)
697 {
698   const GVariantType  *type;
699   DbRef child = Db_variant_get_child (v, &type);
700   g_assert (g_variant_type_equal(type, DB_TIMEZONE_TYPESTRING));
701   return db_timezone_from_data (child.base, child.size);
702 }
703 
704 #define DB_TIMEZONE_INDEXOF_NAME 0
705 
706 static inline DbI18nRef
db_timezone_get_name(DbTimezoneRef v)707 db_timezone_get_name (DbTimezoneRef v)
708 {
709   guint offset_size = Db_ref_get_offset_size (v.size);
710   guint offset = ((0) & (~(gsize)0)) + 0;
711   gsize start = offset;
712   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
713   g_assert (start <= end);
714   g_assert (end <= v.size);
715   return (DbI18nRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
716 }
717 
718 #define DB_TIMEZONE_INDEXOF_OBSOLETES 1
719 
720 static inline DbArrayofstringRef
db_timezone_get_obsoletes(DbTimezoneRef v)721 db_timezone_get_obsoletes (DbTimezoneRef v)
722 {
723   guint offset_size = Db_ref_get_offset_size (v.size);
724   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
725   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
726   gsize start = offset;
727   gsize end = v.size - offset_size * 1;
728   g_assert (start <= end);
729   g_assert (end <= v.size);
730   return (DbArrayofstringRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
731 }
732 
733 static inline GString *
db_timezone_format(DbTimezoneRef v,GString * s,gboolean type_annotate)734 db_timezone_format (DbTimezoneRef v, GString *s, gboolean type_annotate)
735 {
736   g_string_append (s, "(");
737   db_i18n_format (db_timezone_get_name (v), s, type_annotate);
738   g_string_append (s, ", ");
739   db_arrayofstring_format (db_timezone_get_obsoletes (v), s, type_annotate);
740   g_string_append (s, ")");
741   return s;
742 }
743 
744 static inline char *
db_timezone_print(DbTimezoneRef v,gboolean type_annotate)745 db_timezone_print (DbTimezoneRef v, gboolean type_annotate)
746 {
747   GString *s = g_string_new ("");
748   db_timezone_format (v, s, type_annotate);
749   return g_string_free (s, FALSE);
750 }
751 
752 /************** DbCoordinate *******************/
753 #define DB_COORDINATE_TYPESTRING "(dd)"
754 #define DB_COORDINATE_TYPEFORMAT ((const GVariantType *) DB_COORDINATE_TYPESTRING)
755 
756 typedef struct {
757  gconstpointer base;
758  gsize size;
759 } DbCoordinateRef;
760 
761 typedef struct {
762   double lat;
763   double lon;
764 } DbCoordinate;
765 
766 static inline DbCoordinateRef
db_coordinate_from_gvariant(GVariant * v)767 db_coordinate_from_gvariant (GVariant *v)
768 {
769   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_COORDINATE_TYPESTRING));
770   return (DbCoordinateRef) { g_variant_get_data (v), g_variant_get_size (v) };
771 }
772 
773 static inline DbCoordinateRef
db_coordinate_from_bytes(GBytes * b)774 db_coordinate_from_bytes (GBytes *b)
775 {
776   g_assert (g_bytes_get_size (b) == 16);
777 
778   return (DbCoordinateRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
779 }
780 
781 static inline DbCoordinateRef
db_coordinate_from_data(gconstpointer data,gsize size)782 db_coordinate_from_data (gconstpointer data, gsize size)
783 {
784   g_assert (size == 16);
785 
786   return (DbCoordinateRef) { data, size };
787 }
788 
789 static inline GVariant *
db_coordinate_dup_to_gvariant(DbCoordinateRef v)790 db_coordinate_dup_to_gvariant (DbCoordinateRef v)
791 {
792   return g_variant_new_from_data (DB_COORDINATE_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
793 }
794 
795 static inline GVariant *
db_coordinate_to_gvariant(DbCoordinateRef v,GDestroyNotify notify,gpointer user_data)796 db_coordinate_to_gvariant (DbCoordinateRef v,
797                              GDestroyNotify      notify,
798                              gpointer            user_data)
799 {
800   return g_variant_new_from_data (DB_COORDINATE_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
801 }
802 
803 static inline GVariant *
db_coordinate_to_owned_gvariant(DbCoordinateRef v,GVariant * base)804 db_coordinate_to_owned_gvariant (DbCoordinateRef v, GVariant *base)
805 {
806   return db_coordinate_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
807 }
808 
809 static inline GVariant *
db_coordinate_peek_as_gvariant(DbCoordinateRef v)810 db_coordinate_peek_as_gvariant (DbCoordinateRef v)
811 {
812   return g_variant_new_from_data (DB_COORDINATE_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
813 }
814 
815 static inline DbCoordinateRef
db_coordinate_from_variant(DbVariantRef v)816 db_coordinate_from_variant (DbVariantRef v)
817 {
818   const GVariantType  *type;
819   DbRef child = Db_variant_get_child (v, &type);
820   g_assert (g_variant_type_equal(type, DB_COORDINATE_TYPESTRING));
821   return db_coordinate_from_data (child.base, child.size);
822 }
823 
824 static inline const DbCoordinate *
db_coordinate_peek(DbCoordinateRef v)825 db_coordinate_peek (DbCoordinateRef v) {
826   return (const DbCoordinate *)v.base;
827 }
828 
829 #define DB_COORDINATE_INDEXOF_LAT 0
830 
831 static inline double
db_coordinate_get_lat(DbCoordinateRef v)832 db_coordinate_get_lat (DbCoordinateRef v)
833 {
834   guint offset = ((7) & (~(gsize)7)) + 0;
835   return (double)G_STRUCT_MEMBER(double, v.base, offset);
836 }
837 
838 #define DB_COORDINATE_INDEXOF_LON 1
839 
840 static inline double
db_coordinate_get_lon(DbCoordinateRef v)841 db_coordinate_get_lon (DbCoordinateRef v)
842 {
843   guint offset = ((7) & (~(gsize)7)) + 8;
844   return (double)G_STRUCT_MEMBER(double, v.base, offset);
845 }
846 
847 static inline GString *
db_coordinate_format(DbCoordinateRef v,GString * s,gboolean type_annotate)848 db_coordinate_format (DbCoordinateRef v, GString *s, gboolean type_annotate)
849 {
850   g_string_append (s, "(");
851   __Db_gstring_append_double (s, db_coordinate_get_lat (v));
852   g_string_append (s, ", ");
853   __Db_gstring_append_double (s, db_coordinate_get_lon (v));
854   g_string_append (s, ")");
855   return s;
856 }
857 
858 static inline char *
db_coordinate_print(DbCoordinateRef v,gboolean type_annotate)859 db_coordinate_print (DbCoordinateRef v, gboolean type_annotate)
860 {
861   GString *s = g_string_new ("");
862   db_coordinate_format (v, s, type_annotate);
863   return g_string_free (s, FALSE);
864 }
865 
866 /************** DbArrayofuint16 *******************/
867 #define DB_ARRAYOFUINT16_TYPESTRING "aq"
868 #define DB_ARRAYOFUINT16_TYPEFORMAT ((const GVariantType *) DB_ARRAYOFUINT16_TYPESTRING)
869 
870 typedef struct {
871  gconstpointer base;
872  gsize size;
873 } DbArrayofuint16Ref;
874 
875 
876 static inline DbArrayofuint16Ref
db_arrayofuint16_from_gvariant(GVariant * v)877 db_arrayofuint16_from_gvariant (GVariant *v)
878 {
879   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_ARRAYOFUINT16_TYPESTRING));
880   return (DbArrayofuint16Ref) { g_variant_get_data (v), g_variant_get_size (v) };
881 }
882 
883 static inline DbArrayofuint16Ref
db_arrayofuint16_from_bytes(GBytes * b)884 db_arrayofuint16_from_bytes (GBytes *b)
885 {
886   return (DbArrayofuint16Ref) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
887 }
888 
889 static inline DbArrayofuint16Ref
db_arrayofuint16_from_data(gconstpointer data,gsize size)890 db_arrayofuint16_from_data (gconstpointer data, gsize size)
891 {
892   return (DbArrayofuint16Ref) { data, size };
893 }
894 
895 static inline GVariant *
db_arrayofuint16_dup_to_gvariant(DbArrayofuint16Ref v)896 db_arrayofuint16_dup_to_gvariant (DbArrayofuint16Ref v)
897 {
898   return g_variant_new_from_data (DB_ARRAYOFUINT16_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
899 }
900 
901 static inline GVariant *
db_arrayofuint16_to_gvariant(DbArrayofuint16Ref v,GDestroyNotify notify,gpointer user_data)902 db_arrayofuint16_to_gvariant (DbArrayofuint16Ref v,
903                              GDestroyNotify      notify,
904                              gpointer            user_data)
905 {
906   return g_variant_new_from_data (DB_ARRAYOFUINT16_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
907 }
908 
909 static inline GVariant *
db_arrayofuint16_to_owned_gvariant(DbArrayofuint16Ref v,GVariant * base)910 db_arrayofuint16_to_owned_gvariant (DbArrayofuint16Ref v, GVariant *base)
911 {
912   return db_arrayofuint16_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
913 }
914 
915 static inline GVariant *
db_arrayofuint16_peek_as_gvariant(DbArrayofuint16Ref v)916 db_arrayofuint16_peek_as_gvariant (DbArrayofuint16Ref v)
917 {
918   return g_variant_new_from_data (DB_ARRAYOFUINT16_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
919 }
920 
921 static inline DbArrayofuint16Ref
db_arrayofuint16_from_variant(DbVariantRef v)922 db_arrayofuint16_from_variant (DbVariantRef v)
923 {
924   const GVariantType  *type;
925   DbRef child = Db_variant_get_child (v, &type);
926   g_assert (g_variant_type_equal(type, DB_ARRAYOFUINT16_TYPESTRING));
927   return db_arrayofuint16_from_data (child.base, child.size);
928 }
929 
930 static inline gsize
db_arrayofuint16_get_length(DbArrayofuint16Ref v)931 db_arrayofuint16_get_length (DbArrayofuint16Ref v)
932 {
933   gsize length = v.size / 2;
934   return length;
935 }
936 
937 static inline guint16
db_arrayofuint16_get_at(DbArrayofuint16Ref v,gsize index)938 db_arrayofuint16_get_at (DbArrayofuint16Ref v, gsize index)
939 {
940   return (guint16)G_STRUCT_MEMBER(guint16, v.base, index * 2);
941 }
942 
943 static inline const guint16 *
db_arrayofuint16_peek(DbArrayofuint16Ref v)944 db_arrayofuint16_peek (DbArrayofuint16Ref v)
945 {
946   return (const guint16 *)v.base;
947 }
948 
949 static inline GString *
db_arrayofuint16_format(DbArrayofuint16Ref v,GString * s,gboolean type_annotate)950 db_arrayofuint16_format (DbArrayofuint16Ref v, GString *s, gboolean type_annotate)
951 {
952   gsize len = db_arrayofuint16_get_length (v);
953   gsize i;
954   if (len == 0 && type_annotate)
955     g_string_append_printf (s, "@%s ", DB_ARRAYOFUINT16_TYPESTRING);
956   g_string_append_c (s, '[');
957   for (i = 0; i < len; i++)
958     {
959       if (i != 0)
960         g_string_append (s, ", ");
961       g_string_append_printf (s, "%s%"G_GUINT16_FORMAT"", ((i == 0) ? type_annotate : FALSE) ? "uint16 " : "", db_arrayofuint16_get_at (v, i));
962     }
963   g_string_append_c (s, ']');
964   return s;
965 }
966 
967 static inline char *
db_arrayofuint16_print(DbArrayofuint16Ref v,gboolean type_annotate)968 db_arrayofuint16_print (DbArrayofuint16Ref v, gboolean type_annotate)
969 {
970   GString *s = g_string_new ("");
971   db_arrayofuint16_format (v, s, type_annotate);
972   return g_string_free (s, FALSE);
973 }
974 
975 /************** DbLocation *******************/
976 #define DB_LOCATION_TYPESTRING "((ss)ss(dd)ssqyqqaqaq)"
977 #define DB_LOCATION_TYPEFORMAT ((const GVariantType *) DB_LOCATION_TYPESTRING)
978 
979 typedef struct {
980  gconstpointer base;
981  gsize size;
982 } DbLocationRef;
983 
984 
985 static inline DbLocationRef
db_location_from_gvariant(GVariant * v)986 db_location_from_gvariant (GVariant *v)
987 {
988   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_LOCATION_TYPESTRING));
989   return (DbLocationRef) { g_variant_get_data (v), g_variant_get_size (v) };
990 }
991 
992 static inline DbLocationRef
db_location_from_bytes(GBytes * b)993 db_location_from_bytes (GBytes *b)
994 {
995   return (DbLocationRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
996 }
997 
998 static inline DbLocationRef
db_location_from_data(gconstpointer data,gsize size)999 db_location_from_data (gconstpointer data, gsize size)
1000 {
1001   return (DbLocationRef) { data, size };
1002 }
1003 
1004 static inline GVariant *
db_location_dup_to_gvariant(DbLocationRef v)1005 db_location_dup_to_gvariant (DbLocationRef v)
1006 {
1007   return g_variant_new_from_data (DB_LOCATION_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
1008 }
1009 
1010 static inline GVariant *
db_location_to_gvariant(DbLocationRef v,GDestroyNotify notify,gpointer user_data)1011 db_location_to_gvariant (DbLocationRef v,
1012                              GDestroyNotify      notify,
1013                              gpointer            user_data)
1014 {
1015   return g_variant_new_from_data (DB_LOCATION_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
1016 }
1017 
1018 static inline GVariant *
db_location_to_owned_gvariant(DbLocationRef v,GVariant * base)1019 db_location_to_owned_gvariant (DbLocationRef v, GVariant *base)
1020 {
1021   return db_location_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
1022 }
1023 
1024 static inline GVariant *
db_location_peek_as_gvariant(DbLocationRef v)1025 db_location_peek_as_gvariant (DbLocationRef v)
1026 {
1027   return g_variant_new_from_data (DB_LOCATION_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
1028 }
1029 
1030 static inline DbLocationRef
db_location_from_variant(DbVariantRef v)1031 db_location_from_variant (DbVariantRef v)
1032 {
1033   const GVariantType  *type;
1034   DbRef child = Db_variant_get_child (v, &type);
1035   g_assert (g_variant_type_equal(type, DB_LOCATION_TYPESTRING));
1036   return db_location_from_data (child.base, child.size);
1037 }
1038 
1039 #define DB_LOCATION_INDEXOF_NAME 0
1040 
1041 static inline DbI18nRef
db_location_get_name(DbLocationRef v)1042 db_location_get_name (DbLocationRef v)
1043 {
1044   guint offset_size = Db_ref_get_offset_size (v.size);
1045   guint offset = ((0) & (~(gsize)0)) + 0;
1046   gsize start = offset;
1047   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
1048   g_assert (start <= end);
1049   g_assert (end <= v.size);
1050   return (DbI18nRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
1051 }
1052 
1053 #define DB_LOCATION_INDEXOF_FORECAST_ZONE 1
1054 
1055 static inline const char *
db_location_get_forecast_zone(DbLocationRef v)1056 db_location_get_forecast_zone (DbLocationRef v)
1057 {
1058   guint offset_size = Db_ref_get_offset_size (v.size);
1059   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1060   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
1061   const char *base = (const char *)v.base;
1062   gsize start = offset;
1063   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 1);
1064   g_assert (start <= end);
1065   g_assert (end <= v.size);
1066   g_assert (base[end-1] == 0);
1067   return &G_STRUCT_MEMBER(const char, v.base, start);
1068 }
1069 
1070 #define DB_LOCATION_INDEXOF_RADAR 2
1071 
1072 static inline const char *
db_location_get_radar(DbLocationRef v)1073 db_location_get_radar (DbLocationRef v)
1074 {
1075   guint offset_size = Db_ref_get_offset_size (v.size);
1076   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 1);
1077   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
1078   const char *base = (const char *)v.base;
1079   gsize start = offset;
1080   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 2);
1081   g_assert (start <= end);
1082   g_assert (end <= v.size);
1083   g_assert (base[end-1] == 0);
1084   return &G_STRUCT_MEMBER(const char, v.base, start);
1085 }
1086 
1087 #define DB_LOCATION_INDEXOF_COORDINATES 3
1088 
1089 static inline DbCoordinateRef
db_location_get_coordinates(DbLocationRef v)1090 db_location_get_coordinates (DbLocationRef v)
1091 {
1092   guint offset_size = Db_ref_get_offset_size (v.size);
1093   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 2);
1094   guint offset = ((last_end + 7) & (~(gsize)7)) + 0;
1095   g_assert (offset + 16 < v.size);
1096   return (DbCoordinateRef) { G_STRUCT_MEMBER_P(v.base, offset), 16 };
1097 }
1098 
1099 static inline const DbCoordinate *
db_location_peek_coordinates(DbLocationRef v)1100 db_location_peek_coordinates (DbLocationRef v) {
1101   return (DbCoordinate *)db_location_get_coordinates (v).base;
1102 }
1103 
1104 #define DB_LOCATION_INDEXOF_COUNTRY_CODE 4
1105 
1106 static inline const char *
db_location_get_country_code(DbLocationRef v)1107 db_location_get_country_code (DbLocationRef v)
1108 {
1109   guint offset_size = Db_ref_get_offset_size (v.size);
1110   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 2);
1111   guint offset = ((last_end + 7) & (~(gsize)7)) + 16;
1112   const char *base = (const char *)v.base;
1113   gsize start = offset;
1114   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 3);
1115   g_assert (start <= end);
1116   g_assert (end <= v.size);
1117   g_assert (base[end-1] == 0);
1118   return &G_STRUCT_MEMBER(const char, v.base, start);
1119 }
1120 
1121 #define DB_LOCATION_INDEXOF_METAR_CODE 5
1122 
1123 static inline const char *
db_location_get_metar_code(DbLocationRef v)1124 db_location_get_metar_code (DbLocationRef v)
1125 {
1126   guint offset_size = Db_ref_get_offset_size (v.size);
1127   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 3);
1128   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
1129   const char *base = (const char *)v.base;
1130   gsize start = offset;
1131   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 4);
1132   g_assert (start <= end);
1133   g_assert (end <= v.size);
1134   g_assert (base[end-1] == 0);
1135   return &G_STRUCT_MEMBER(const char, v.base, start);
1136 }
1137 
1138 #define DB_LOCATION_INDEXOF_TZ_HINT 6
1139 
1140 static inline guint16
db_location_get_tz_hint(DbLocationRef v)1141 db_location_get_tz_hint (DbLocationRef v)
1142 {
1143   guint offset_size = Db_ref_get_offset_size (v.size);
1144   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
1145   guint offset = ((last_end + 1) & (~(gsize)1)) + 0;
1146   g_assert (offset + 2 < v.size);
1147   return (guint16)G_STRUCT_MEMBER(guint16, v.base, offset);
1148 }
1149 
1150 #define DB_LOCATION_INDEXOF_LEVEL 7
1151 
1152 static inline guint8
db_location_get_level(DbLocationRef v)1153 db_location_get_level (DbLocationRef v)
1154 {
1155   guint offset_size = Db_ref_get_offset_size (v.size);
1156   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
1157   guint offset = ((last_end + 1) & (~(gsize)1)) + 2;
1158   g_assert (offset + 1 < v.size);
1159   return (guint8)G_STRUCT_MEMBER(guint8, v.base, offset);
1160 }
1161 
1162 #define DB_LOCATION_INDEXOF_NEAREST 8
1163 
1164 static inline guint16
db_location_get_nearest(DbLocationRef v)1165 db_location_get_nearest (DbLocationRef v)
1166 {
1167   guint offset_size = Db_ref_get_offset_size (v.size);
1168   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
1169   guint offset = ((last_end + 1) & (~(gsize)1)) + 4;
1170   g_assert (offset + 2 < v.size);
1171   return (guint16)G_STRUCT_MEMBER(guint16, v.base, offset);
1172 }
1173 
1174 #define DB_LOCATION_INDEXOF_PARENT 9
1175 
1176 static inline guint16
db_location_get_parent(DbLocationRef v)1177 db_location_get_parent (DbLocationRef v)
1178 {
1179   guint offset_size = Db_ref_get_offset_size (v.size);
1180   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
1181   guint offset = ((last_end + 1) & (~(gsize)1)) + 6;
1182   g_assert (offset + 2 < v.size);
1183   return (guint16)G_STRUCT_MEMBER(guint16, v.base, offset);
1184 }
1185 
1186 #define DB_LOCATION_INDEXOF_CHILDREN 10
1187 
1188 static inline DbArrayofuint16Ref
db_location_get_children(DbLocationRef v)1189 db_location_get_children (DbLocationRef v)
1190 {
1191   guint offset_size = Db_ref_get_offset_size (v.size);
1192   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
1193   guint offset = ((last_end + 1) & (~(gsize)1)) + 8;
1194   gsize start = offset;
1195   gsize end = DB_REF_READ_FRAME_OFFSET(v, 5);
1196   g_assert (start <= end);
1197   g_assert (end <= v.size);
1198   return (DbArrayofuint16Ref) { G_STRUCT_MEMBER_P(v.base, start), end - start };
1199 }
1200 
1201 static inline const guint16 *
db_location_peek_children(DbLocationRef v,gsize * len)1202 db_location_peek_children (DbLocationRef v, gsize *len) {
1203   DbArrayofuint16Ref a = db_location_get_children (v);
1204   if (len != NULL)
1205     *len = db_arrayofuint16_get_length (a);
1206   return (const guint16 *)a.base;
1207 }
1208 
1209 #define DB_LOCATION_INDEXOF_TIMEZONES 11
1210 
1211 static inline DbArrayofuint16Ref
db_location_get_timezones(DbLocationRef v)1212 db_location_get_timezones (DbLocationRef v)
1213 {
1214   guint offset_size = Db_ref_get_offset_size (v.size);
1215   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 5);
1216   guint offset = ((last_end + 1) & (~(gsize)1)) + 0;
1217   gsize start = offset;
1218   gsize end = v.size - offset_size * 6;
1219   g_assert (start <= end);
1220   g_assert (end <= v.size);
1221   return (DbArrayofuint16Ref) { G_STRUCT_MEMBER_P(v.base, start), end - start };
1222 }
1223 
1224 static inline const guint16 *
db_location_peek_timezones(DbLocationRef v,gsize * len)1225 db_location_peek_timezones (DbLocationRef v, gsize *len) {
1226   DbArrayofuint16Ref a = db_location_get_timezones (v);
1227   if (len != NULL)
1228     *len = db_arrayofuint16_get_length (a);
1229   return (const guint16 *)a.base;
1230 }
1231 
1232 static inline GString *
db_location_format(DbLocationRef v,GString * s,gboolean type_annotate)1233 db_location_format (DbLocationRef v, GString *s, gboolean type_annotate)
1234 {
1235   g_string_append (s, "(");
1236   db_i18n_format (db_location_get_name (v), s, type_annotate);
1237   g_string_append (s, ", ");
1238   __Db_gstring_append_string (s, db_location_get_forecast_zone (v));
1239   g_string_append (s, ", ");
1240   __Db_gstring_append_string (s, db_location_get_radar (v));
1241   g_string_append (s, ", ");
1242   db_coordinate_format (db_location_get_coordinates (v), s, type_annotate);
1243   g_string_append (s, ", ");
1244   __Db_gstring_append_string (s, db_location_get_country_code (v));
1245   g_string_append (s, ", ");
1246   __Db_gstring_append_string (s, db_location_get_metar_code (v));
1247   g_string_append (s, ", ");
1248   g_string_append_printf (s, "%s%"G_GUINT16_FORMAT", %s0x%02x, %s%"G_GUINT16_FORMAT", %s%"G_GUINT16_FORMAT", ",
1249                    type_annotate ? "uint16 " : "",
1250                    db_location_get_tz_hint (v),
1251                    type_annotate ? "byte " : "",
1252                    db_location_get_level (v),
1253                    type_annotate ? "uint16 " : "",
1254                    db_location_get_nearest (v),
1255                    type_annotate ? "uint16 " : "",
1256                    db_location_get_parent (v));
1257   db_arrayofuint16_format (db_location_get_children (v), s, type_annotate);
1258   g_string_append (s, ", ");
1259   db_arrayofuint16_format (db_location_get_timezones (v), s, type_annotate);
1260   g_string_append (s, ")");
1261   return s;
1262 }
1263 
1264 static inline char *
db_location_print(DbLocationRef v,gboolean type_annotate)1265 db_location_print (DbLocationRef v, gboolean type_annotate)
1266 {
1267   GString *s = g_string_new ("");
1268   db_location_format (v, s, type_annotate);
1269   return g_string_free (s, FALSE);
1270 }
1271 
1272 /************** DbWorldLocByCountry *******************/
1273 #define DB_WORLD_LOC_BY_COUNTRY_TYPESTRING "a{sq}"
1274 #define DB_WORLD_LOC_BY_COUNTRY_TYPEFORMAT ((const GVariantType *) DB_WORLD_LOC_BY_COUNTRY_TYPESTRING)
1275 
1276 typedef struct {
1277  gconstpointer base;
1278  gsize size;
1279 } DbWorldLocByCountryRef;
1280 
1281 typedef struct {
1282  gconstpointer base;
1283  gsize size;
1284 } DbWorldLocByCountryEntryRef;
1285 
1286 
1287 static inline DbWorldLocByCountryRef
db_world_loc_by_country_from_gvariant(GVariant * v)1288 db_world_loc_by_country_from_gvariant (GVariant *v)
1289 {
1290   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_WORLD_LOC_BY_COUNTRY_TYPESTRING));
1291   return (DbWorldLocByCountryRef) { g_variant_get_data (v), g_variant_get_size (v) };
1292 }
1293 
1294 static inline DbWorldLocByCountryRef
db_world_loc_by_country_from_bytes(GBytes * b)1295 db_world_loc_by_country_from_bytes (GBytes *b)
1296 {
1297   return (DbWorldLocByCountryRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
1298 }
1299 
1300 static inline DbWorldLocByCountryRef
db_world_loc_by_country_from_data(gconstpointer data,gsize size)1301 db_world_loc_by_country_from_data (gconstpointer data, gsize size)
1302 {
1303   return (DbWorldLocByCountryRef) { data, size };
1304 }
1305 
1306 static inline GVariant *
db_world_loc_by_country_dup_to_gvariant(DbWorldLocByCountryRef v)1307 db_world_loc_by_country_dup_to_gvariant (DbWorldLocByCountryRef v)
1308 {
1309   return g_variant_new_from_data (DB_WORLD_LOC_BY_COUNTRY_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
1310 }
1311 
1312 static inline GVariant *
db_world_loc_by_country_to_gvariant(DbWorldLocByCountryRef v,GDestroyNotify notify,gpointer user_data)1313 db_world_loc_by_country_to_gvariant (DbWorldLocByCountryRef v,
1314                              GDestroyNotify      notify,
1315                              gpointer            user_data)
1316 {
1317   return g_variant_new_from_data (DB_WORLD_LOC_BY_COUNTRY_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
1318 }
1319 
1320 static inline GVariant *
db_world_loc_by_country_to_owned_gvariant(DbWorldLocByCountryRef v,GVariant * base)1321 db_world_loc_by_country_to_owned_gvariant (DbWorldLocByCountryRef v, GVariant *base)
1322 {
1323   return db_world_loc_by_country_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
1324 }
1325 
1326 static inline GVariant *
db_world_loc_by_country_peek_as_gvariant(DbWorldLocByCountryRef v)1327 db_world_loc_by_country_peek_as_gvariant (DbWorldLocByCountryRef v)
1328 {
1329   return g_variant_new_from_data (DB_WORLD_LOC_BY_COUNTRY_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
1330 }
1331 
1332 static inline DbWorldLocByCountryRef
db_world_loc_by_country_from_variant(DbVariantRef v)1333 db_world_loc_by_country_from_variant (DbVariantRef v)
1334 {
1335   const GVariantType  *type;
1336   DbRef child = Db_variant_get_child (v, &type);
1337   g_assert (g_variant_type_equal(type, DB_WORLD_LOC_BY_COUNTRY_TYPESTRING));
1338   return db_world_loc_by_country_from_data (child.base, child.size);
1339 }
1340 
1341 
1342 static inline gsize
db_world_loc_by_country_get_length(DbWorldLocByCountryRef v)1343 db_world_loc_by_country_get_length (DbWorldLocByCountryRef v)
1344 {
1345   if (v.size == 0)
1346     return 0;
1347   guint offset_size = Db_ref_get_offset_size (v.size);
1348   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1349   gsize offsets_array_size;
1350   if (last_end > v.size)
1351     return 0;
1352   offsets_array_size = v.size - last_end;
1353   if (offsets_array_size % offset_size != 0)
1354     return 0;
1355   gsize length = offsets_array_size / offset_size;
1356   return length;
1357 }
1358 
1359 static inline DbWorldLocByCountryEntryRef
db_world_loc_by_country_get_at(DbWorldLocByCountryRef v,gsize index)1360 db_world_loc_by_country_get_at (DbWorldLocByCountryRef v, gsize index)
1361 {
1362   DbWorldLocByCountryEntryRef res;
1363   guint offset_size = Db_ref_get_offset_size (v.size);
1364   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1365   gsize len = (v.size - last_end) / offset_size;
1366   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 2) : 0;
1367   gsize end = DB_REF_READ_FRAME_OFFSET(v, len - index - 1);
1368   g_assert (start <= end);
1369   g_assert (end <= last_end);
1370   res = (DbWorldLocByCountryEntryRef) { ((const char *)v.base) + start, end - start };
1371   return res;
1372 }
1373 
1374 static inline const char *
db_world_loc_by_country_entry_get_key(DbWorldLocByCountryEntryRef v)1375 db_world_loc_by_country_entry_get_key (DbWorldLocByCountryEntryRef v)
1376 {
1377   guint offset_size = Db_ref_get_offset_size (v.size);
1378   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
1379   const char *base = (const char *)v.base;
1380   g_assert (end < v.size);
1381   g_assert (base[end-1] == 0);
1382   return base;
1383 }
1384 
1385 static inline guint16
db_world_loc_by_country_entry_get_value(DbWorldLocByCountryEntryRef v)1386 db_world_loc_by_country_entry_get_value (DbWorldLocByCountryEntryRef v)
1387 {
1388   guint offset_size = Db_ref_get_offset_size (v.size);
1389   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
1390   gsize offset = DB_REF_ALIGN(end, 2);
1391   g_assert (offset == v.size - offset_size - 2);
1392   return (guint16)*((guint16 *)((char *)v.base + offset));
1393 }
1394 
1395 static inline gboolean
db_world_loc_by_country_lookup(DbWorldLocByCountryRef v,const char * key,gsize * index_out,guint16 * out)1396 db_world_loc_by_country_lookup (DbWorldLocByCountryRef v, const char * key, gsize *index_out, guint16 *out)
1397 {
1398   const char * canonical_key = key;
1399   guint offset_size = Db_ref_get_offset_size (v.size);
1400   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1401   if (last_end > v.size)
1402     return FALSE;
1403   gsize offsets_array_size = v.size - last_end;
1404   if (offsets_array_size % offset_size != 0)
1405     return FALSE;
1406   gsize len = offsets_array_size / offset_size;
1407   gsize start = 0;
1408   gsize end = len;
1409 
1410   while (start < end)
1411     {
1412       gsize mid = (end + start) / 2;
1413       gsize mid_end = DB_REF_READ_FRAME_OFFSET(v, len - mid - 1);
1414       gsize mid_start = mid == 0 ? 0 : DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - mid), 2);
1415       g_assert (mid_start <= mid_end);
1416       g_assert (mid_end <= last_end);
1417       DbWorldLocByCountryEntryRef e = { ((const char *)v.base) + mid_start, mid_end - mid_start };
1418       const char * e_key = db_world_loc_by_country_entry_get_key (e);
1419       gint32 cmp = strcmp(canonical_key, e_key);
1420       if (cmp == 0)
1421         {
1422            if (index_out)
1423              *index_out = mid;
1424            if (out)
1425              *out = db_world_loc_by_country_entry_get_value (e);
1426            return TRUE;
1427         }
1428       if (cmp < 0)
1429         end = mid; /* canonical_key < e_key */
1430       else
1431         start = mid + 1; /* canonical_key > e_key */
1432     }
1433     return FALSE;
1434 }
1435 
1436 static inline GString *
db_world_loc_by_country_format(DbWorldLocByCountryRef v,GString * s,gboolean type_annotate)1437 db_world_loc_by_country_format (DbWorldLocByCountryRef v, GString *s, gboolean type_annotate)
1438 {
1439   gsize len = db_world_loc_by_country_get_length (v);
1440   gsize i;
1441 
1442   if (len == 0 && type_annotate)
1443     g_string_append_printf (s, "@%s ", DB_WORLD_LOC_BY_COUNTRY_TYPESTRING);
1444 
1445   g_string_append_c (s, '{');
1446   for (i = 0; i < len; i++)
1447     {
1448       DbWorldLocByCountryEntryRef entry = db_world_loc_by_country_get_at (v, i);
1449       if (i != 0)
1450         g_string_append (s, ", ");
1451       __Db_gstring_append_string (s, db_world_loc_by_country_entry_get_key (entry));
1452       g_string_append (s, ": ");
1453       g_string_append_printf (s, "%s%"G_GUINT16_FORMAT"", type_annotate ? "uint16 " : "", db_world_loc_by_country_entry_get_value (entry));
1454     }
1455   g_string_append_c (s, '}');
1456   return s;
1457 }
1458 
1459 static inline char *
db_world_loc_by_country_print(DbWorldLocByCountryRef v,gboolean type_annotate)1460 db_world_loc_by_country_print (DbWorldLocByCountryRef v, gboolean type_annotate)
1461 {
1462   GString *s = g_string_new ("");
1463   db_world_loc_by_country_format (v, s, type_annotate);
1464   return g_string_free (s, FALSE);
1465 }
1466 
1467 /************** DbWorldLocByMetar *******************/
1468 #define DB_WORLD_LOC_BY_METAR_TYPESTRING "a{sq}"
1469 #define DB_WORLD_LOC_BY_METAR_TYPEFORMAT ((const GVariantType *) DB_WORLD_LOC_BY_METAR_TYPESTRING)
1470 
1471 typedef struct {
1472  gconstpointer base;
1473  gsize size;
1474 } DbWorldLocByMetarRef;
1475 
1476 typedef struct {
1477  gconstpointer base;
1478  gsize size;
1479 } DbWorldLocByMetarEntryRef;
1480 
1481 
1482 static inline DbWorldLocByMetarRef
db_world_loc_by_metar_from_gvariant(GVariant * v)1483 db_world_loc_by_metar_from_gvariant (GVariant *v)
1484 {
1485   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_WORLD_LOC_BY_METAR_TYPESTRING));
1486   return (DbWorldLocByMetarRef) { g_variant_get_data (v), g_variant_get_size (v) };
1487 }
1488 
1489 static inline DbWorldLocByMetarRef
db_world_loc_by_metar_from_bytes(GBytes * b)1490 db_world_loc_by_metar_from_bytes (GBytes *b)
1491 {
1492   return (DbWorldLocByMetarRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
1493 }
1494 
1495 static inline DbWorldLocByMetarRef
db_world_loc_by_metar_from_data(gconstpointer data,gsize size)1496 db_world_loc_by_metar_from_data (gconstpointer data, gsize size)
1497 {
1498   return (DbWorldLocByMetarRef) { data, size };
1499 }
1500 
1501 static inline GVariant *
db_world_loc_by_metar_dup_to_gvariant(DbWorldLocByMetarRef v)1502 db_world_loc_by_metar_dup_to_gvariant (DbWorldLocByMetarRef v)
1503 {
1504   return g_variant_new_from_data (DB_WORLD_LOC_BY_METAR_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
1505 }
1506 
1507 static inline GVariant *
db_world_loc_by_metar_to_gvariant(DbWorldLocByMetarRef v,GDestroyNotify notify,gpointer user_data)1508 db_world_loc_by_metar_to_gvariant (DbWorldLocByMetarRef v,
1509                              GDestroyNotify      notify,
1510                              gpointer            user_data)
1511 {
1512   return g_variant_new_from_data (DB_WORLD_LOC_BY_METAR_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
1513 }
1514 
1515 static inline GVariant *
db_world_loc_by_metar_to_owned_gvariant(DbWorldLocByMetarRef v,GVariant * base)1516 db_world_loc_by_metar_to_owned_gvariant (DbWorldLocByMetarRef v, GVariant *base)
1517 {
1518   return db_world_loc_by_metar_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
1519 }
1520 
1521 static inline GVariant *
db_world_loc_by_metar_peek_as_gvariant(DbWorldLocByMetarRef v)1522 db_world_loc_by_metar_peek_as_gvariant (DbWorldLocByMetarRef v)
1523 {
1524   return g_variant_new_from_data (DB_WORLD_LOC_BY_METAR_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
1525 }
1526 
1527 static inline DbWorldLocByMetarRef
db_world_loc_by_metar_from_variant(DbVariantRef v)1528 db_world_loc_by_metar_from_variant (DbVariantRef v)
1529 {
1530   const GVariantType  *type;
1531   DbRef child = Db_variant_get_child (v, &type);
1532   g_assert (g_variant_type_equal(type, DB_WORLD_LOC_BY_METAR_TYPESTRING));
1533   return db_world_loc_by_metar_from_data (child.base, child.size);
1534 }
1535 
1536 
1537 static inline gsize
db_world_loc_by_metar_get_length(DbWorldLocByMetarRef v)1538 db_world_loc_by_metar_get_length (DbWorldLocByMetarRef v)
1539 {
1540   if (v.size == 0)
1541     return 0;
1542   guint offset_size = Db_ref_get_offset_size (v.size);
1543   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1544   gsize offsets_array_size;
1545   if (last_end > v.size)
1546     return 0;
1547   offsets_array_size = v.size - last_end;
1548   if (offsets_array_size % offset_size != 0)
1549     return 0;
1550   gsize length = offsets_array_size / offset_size;
1551   return length;
1552 }
1553 
1554 static inline DbWorldLocByMetarEntryRef
db_world_loc_by_metar_get_at(DbWorldLocByMetarRef v,gsize index)1555 db_world_loc_by_metar_get_at (DbWorldLocByMetarRef v, gsize index)
1556 {
1557   DbWorldLocByMetarEntryRef res;
1558   guint offset_size = Db_ref_get_offset_size (v.size);
1559   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1560   gsize len = (v.size - last_end) / offset_size;
1561   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 2) : 0;
1562   gsize end = DB_REF_READ_FRAME_OFFSET(v, len - index - 1);
1563   g_assert (start <= end);
1564   g_assert (end <= last_end);
1565   res = (DbWorldLocByMetarEntryRef) { ((const char *)v.base) + start, end - start };
1566   return res;
1567 }
1568 
1569 static inline const char *
db_world_loc_by_metar_entry_get_key(DbWorldLocByMetarEntryRef v)1570 db_world_loc_by_metar_entry_get_key (DbWorldLocByMetarEntryRef v)
1571 {
1572   guint offset_size = Db_ref_get_offset_size (v.size);
1573   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
1574   const char *base = (const char *)v.base;
1575   g_assert (end < v.size);
1576   g_assert (base[end-1] == 0);
1577   return base;
1578 }
1579 
1580 static inline guint16
db_world_loc_by_metar_entry_get_value(DbWorldLocByMetarEntryRef v)1581 db_world_loc_by_metar_entry_get_value (DbWorldLocByMetarEntryRef v)
1582 {
1583   guint offset_size = Db_ref_get_offset_size (v.size);
1584   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
1585   gsize offset = DB_REF_ALIGN(end, 2);
1586   g_assert (offset == v.size - offset_size - 2);
1587   return (guint16)*((guint16 *)((char *)v.base + offset));
1588 }
1589 
1590 static inline gboolean
db_world_loc_by_metar_lookup(DbWorldLocByMetarRef v,const char * key,gsize * index_out,guint16 * out)1591 db_world_loc_by_metar_lookup (DbWorldLocByMetarRef v, const char * key, gsize *index_out, guint16 *out)
1592 {
1593   const char * canonical_key = key;
1594   guint offset_size = Db_ref_get_offset_size (v.size);
1595   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1596   if (last_end > v.size)
1597     return FALSE;
1598   gsize offsets_array_size = v.size - last_end;
1599   if (offsets_array_size % offset_size != 0)
1600     return FALSE;
1601   gsize len = offsets_array_size / offset_size;
1602   gsize start = 0;
1603   gsize end = len;
1604 
1605   while (start < end)
1606     {
1607       gsize mid = (end + start) / 2;
1608       gsize mid_end = DB_REF_READ_FRAME_OFFSET(v, len - mid - 1);
1609       gsize mid_start = mid == 0 ? 0 : DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - mid), 2);
1610       g_assert (mid_start <= mid_end);
1611       g_assert (mid_end <= last_end);
1612       DbWorldLocByMetarEntryRef e = { ((const char *)v.base) + mid_start, mid_end - mid_start };
1613       const char * e_key = db_world_loc_by_metar_entry_get_key (e);
1614       gint32 cmp = strcmp(canonical_key, e_key);
1615       if (cmp == 0)
1616         {
1617            if (index_out)
1618              *index_out = mid;
1619            if (out)
1620              *out = db_world_loc_by_metar_entry_get_value (e);
1621            return TRUE;
1622         }
1623       if (cmp < 0)
1624         end = mid; /* canonical_key < e_key */
1625       else
1626         start = mid + 1; /* canonical_key > e_key */
1627     }
1628     return FALSE;
1629 }
1630 
1631 static inline GString *
db_world_loc_by_metar_format(DbWorldLocByMetarRef v,GString * s,gboolean type_annotate)1632 db_world_loc_by_metar_format (DbWorldLocByMetarRef v, GString *s, gboolean type_annotate)
1633 {
1634   gsize len = db_world_loc_by_metar_get_length (v);
1635   gsize i;
1636 
1637   if (len == 0 && type_annotate)
1638     g_string_append_printf (s, "@%s ", DB_WORLD_LOC_BY_METAR_TYPESTRING);
1639 
1640   g_string_append_c (s, '{');
1641   for (i = 0; i < len; i++)
1642     {
1643       DbWorldLocByMetarEntryRef entry = db_world_loc_by_metar_get_at (v, i);
1644       if (i != 0)
1645         g_string_append (s, ", ");
1646       __Db_gstring_append_string (s, db_world_loc_by_metar_entry_get_key (entry));
1647       g_string_append (s, ": ");
1648       g_string_append_printf (s, "%s%"G_GUINT16_FORMAT"", type_annotate ? "uint16 " : "", db_world_loc_by_metar_entry_get_value (entry));
1649     }
1650   g_string_append_c (s, '}');
1651   return s;
1652 }
1653 
1654 static inline char *
db_world_loc_by_metar_print(DbWorldLocByMetarRef v,gboolean type_annotate)1655 db_world_loc_by_metar_print (DbWorldLocByMetarRef v, gboolean type_annotate)
1656 {
1657   GString *s = g_string_new ("");
1658   db_world_loc_by_metar_format (v, s, type_annotate);
1659   return g_string_free (s, FALSE);
1660 }
1661 
1662 /************** DbWorldTimezones *******************/
1663 #define DB_WORLD_TIMEZONES_TYPESTRING "a{s((ss)as)}"
1664 #define DB_WORLD_TIMEZONES_TYPEFORMAT ((const GVariantType *) DB_WORLD_TIMEZONES_TYPESTRING)
1665 
1666 typedef struct {
1667  gconstpointer base;
1668  gsize size;
1669 } DbWorldTimezonesRef;
1670 
1671 typedef struct {
1672  gconstpointer base;
1673  gsize size;
1674 } DbWorldTimezonesEntryRef;
1675 
1676 
1677 static inline DbWorldTimezonesRef
db_world_timezones_from_gvariant(GVariant * v)1678 db_world_timezones_from_gvariant (GVariant *v)
1679 {
1680   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_WORLD_TIMEZONES_TYPESTRING));
1681   return (DbWorldTimezonesRef) { g_variant_get_data (v), g_variant_get_size (v) };
1682 }
1683 
1684 static inline DbWorldTimezonesRef
db_world_timezones_from_bytes(GBytes * b)1685 db_world_timezones_from_bytes (GBytes *b)
1686 {
1687   return (DbWorldTimezonesRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
1688 }
1689 
1690 static inline DbWorldTimezonesRef
db_world_timezones_from_data(gconstpointer data,gsize size)1691 db_world_timezones_from_data (gconstpointer data, gsize size)
1692 {
1693   return (DbWorldTimezonesRef) { data, size };
1694 }
1695 
1696 static inline GVariant *
db_world_timezones_dup_to_gvariant(DbWorldTimezonesRef v)1697 db_world_timezones_dup_to_gvariant (DbWorldTimezonesRef v)
1698 {
1699   return g_variant_new_from_data (DB_WORLD_TIMEZONES_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
1700 }
1701 
1702 static inline GVariant *
db_world_timezones_to_gvariant(DbWorldTimezonesRef v,GDestroyNotify notify,gpointer user_data)1703 db_world_timezones_to_gvariant (DbWorldTimezonesRef v,
1704                              GDestroyNotify      notify,
1705                              gpointer            user_data)
1706 {
1707   return g_variant_new_from_data (DB_WORLD_TIMEZONES_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
1708 }
1709 
1710 static inline GVariant *
db_world_timezones_to_owned_gvariant(DbWorldTimezonesRef v,GVariant * base)1711 db_world_timezones_to_owned_gvariant (DbWorldTimezonesRef v, GVariant *base)
1712 {
1713   return db_world_timezones_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
1714 }
1715 
1716 static inline GVariant *
db_world_timezones_peek_as_gvariant(DbWorldTimezonesRef v)1717 db_world_timezones_peek_as_gvariant (DbWorldTimezonesRef v)
1718 {
1719   return g_variant_new_from_data (DB_WORLD_TIMEZONES_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
1720 }
1721 
1722 static inline DbWorldTimezonesRef
db_world_timezones_from_variant(DbVariantRef v)1723 db_world_timezones_from_variant (DbVariantRef v)
1724 {
1725   const GVariantType  *type;
1726   DbRef child = Db_variant_get_child (v, &type);
1727   g_assert (g_variant_type_equal(type, DB_WORLD_TIMEZONES_TYPESTRING));
1728   return db_world_timezones_from_data (child.base, child.size);
1729 }
1730 
1731 
1732 static inline gsize
db_world_timezones_get_length(DbWorldTimezonesRef v)1733 db_world_timezones_get_length (DbWorldTimezonesRef v)
1734 {
1735   if (v.size == 0)
1736     return 0;
1737   guint offset_size = Db_ref_get_offset_size (v.size);
1738   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1739   gsize offsets_array_size;
1740   if (last_end > v.size)
1741     return 0;
1742   offsets_array_size = v.size - last_end;
1743   if (offsets_array_size % offset_size != 0)
1744     return 0;
1745   gsize length = offsets_array_size / offset_size;
1746   return length;
1747 }
1748 
1749 static inline DbWorldTimezonesEntryRef
db_world_timezones_get_at(DbWorldTimezonesRef v,gsize index)1750 db_world_timezones_get_at (DbWorldTimezonesRef v, gsize index)
1751 {
1752   DbWorldTimezonesEntryRef res;
1753   guint offset_size = Db_ref_get_offset_size (v.size);
1754   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1755   gsize len = (v.size - last_end) / offset_size;
1756   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 1) : 0;
1757   gsize end = DB_REF_READ_FRAME_OFFSET(v, len - index - 1);
1758   g_assert (start <= end);
1759   g_assert (end <= last_end);
1760   res = (DbWorldTimezonesEntryRef) { ((const char *)v.base) + start, end - start };
1761   return res;
1762 }
1763 
1764 static inline const char *
db_world_timezones_entry_get_key(DbWorldTimezonesEntryRef v)1765 db_world_timezones_entry_get_key (DbWorldTimezonesEntryRef v)
1766 {
1767   guint offset_size = Db_ref_get_offset_size (v.size);
1768   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
1769   const char *base = (const char *)v.base;
1770   g_assert (end < v.size);
1771   g_assert (base[end-1] == 0);
1772   return base;
1773 }
1774 
1775 static inline DbTimezoneRef
db_world_timezones_entry_get_value(DbWorldTimezonesEntryRef v)1776 db_world_timezones_entry_get_value (DbWorldTimezonesEntryRef v)
1777 {
1778   guint offset_size = Db_ref_get_offset_size (v.size);
1779   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
1780   gsize offset = DB_REF_ALIGN(end, 1);
1781   g_assert (offset <= v.size);
1782   return (DbTimezoneRef) { (char *)v.base + offset, (v.size - offset_size) - offset };
1783 }
1784 
1785 static inline gboolean
db_world_timezones_lookup(DbWorldTimezonesRef v,const char * key,gsize * index_out,DbTimezoneRef * out)1786 db_world_timezones_lookup (DbWorldTimezonesRef v, const char * key, gsize *index_out, DbTimezoneRef *out)
1787 {
1788   const char * canonical_key = key;
1789   guint offset_size = Db_ref_get_offset_size (v.size);
1790   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1791   if (last_end > v.size)
1792     return FALSE;
1793   gsize offsets_array_size = v.size - last_end;
1794   if (offsets_array_size % offset_size != 0)
1795     return FALSE;
1796   gsize len = offsets_array_size / offset_size;
1797   gsize start = 0;
1798   gsize end = len;
1799 
1800   while (start < end)
1801     {
1802       gsize mid = (end + start) / 2;
1803       gsize mid_end = DB_REF_READ_FRAME_OFFSET(v, len - mid - 1);
1804       gsize mid_start = mid == 0 ? 0 : DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - mid), 1);
1805       g_assert (mid_start <= mid_end);
1806       g_assert (mid_end <= last_end);
1807       DbWorldTimezonesEntryRef e = { ((const char *)v.base) + mid_start, mid_end - mid_start };
1808       const char * e_key = db_world_timezones_entry_get_key (e);
1809       gint32 cmp = strcmp(canonical_key, e_key);
1810       if (cmp == 0)
1811         {
1812            if (index_out)
1813              *index_out = mid;
1814            if (out)
1815              *out = db_world_timezones_entry_get_value (e);
1816            return TRUE;
1817         }
1818       if (cmp < 0)
1819         end = mid; /* canonical_key < e_key */
1820       else
1821         start = mid + 1; /* canonical_key > e_key */
1822     }
1823     return FALSE;
1824 }
1825 
1826 static inline GString *
db_world_timezones_format(DbWorldTimezonesRef v,GString * s,gboolean type_annotate)1827 db_world_timezones_format (DbWorldTimezonesRef v, GString *s, gboolean type_annotate)
1828 {
1829   gsize len = db_world_timezones_get_length (v);
1830   gsize i;
1831 
1832   if (len == 0 && type_annotate)
1833     g_string_append_printf (s, "@%s ", DB_WORLD_TIMEZONES_TYPESTRING);
1834 
1835   g_string_append_c (s, '{');
1836   for (i = 0; i < len; i++)
1837     {
1838       DbWorldTimezonesEntryRef entry = db_world_timezones_get_at (v, i);
1839       if (i != 0)
1840         g_string_append (s, ", ");
1841       __Db_gstring_append_string (s, db_world_timezones_entry_get_key (entry));
1842       g_string_append (s, ": ");
1843       db_timezone_format (db_world_timezones_entry_get_value (entry), s, type_annotate);
1844     }
1845   g_string_append_c (s, '}');
1846   return s;
1847 }
1848 
1849 static inline char *
db_world_timezones_print(DbWorldTimezonesRef v,gboolean type_annotate)1850 db_world_timezones_print (DbWorldTimezonesRef v, gboolean type_annotate)
1851 {
1852   GString *s = g_string_new ("");
1853   db_world_timezones_format (v, s, type_annotate);
1854   return g_string_free (s, FALSE);
1855 }
1856 
1857 /************** DbArrayofLocation *******************/
1858 #define DB_ARRAYOF_LOCATION_TYPESTRING "a((ss)ss(dd)ssqyqqaqaq)"
1859 #define DB_ARRAYOF_LOCATION_TYPEFORMAT ((const GVariantType *) DB_ARRAYOF_LOCATION_TYPESTRING)
1860 
1861 typedef struct {
1862  gconstpointer base;
1863  gsize size;
1864 } DbArrayofLocationRef;
1865 
1866 
1867 static inline DbArrayofLocationRef
db_arrayof_location_from_gvariant(GVariant * v)1868 db_arrayof_location_from_gvariant (GVariant *v)
1869 {
1870   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_ARRAYOF_LOCATION_TYPESTRING));
1871   return (DbArrayofLocationRef) { g_variant_get_data (v), g_variant_get_size (v) };
1872 }
1873 
1874 static inline DbArrayofLocationRef
db_arrayof_location_from_bytes(GBytes * b)1875 db_arrayof_location_from_bytes (GBytes *b)
1876 {
1877   return (DbArrayofLocationRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
1878 }
1879 
1880 static inline DbArrayofLocationRef
db_arrayof_location_from_data(gconstpointer data,gsize size)1881 db_arrayof_location_from_data (gconstpointer data, gsize size)
1882 {
1883   return (DbArrayofLocationRef) { data, size };
1884 }
1885 
1886 static inline GVariant *
db_arrayof_location_dup_to_gvariant(DbArrayofLocationRef v)1887 db_arrayof_location_dup_to_gvariant (DbArrayofLocationRef v)
1888 {
1889   return g_variant_new_from_data (DB_ARRAYOF_LOCATION_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
1890 }
1891 
1892 static inline GVariant *
db_arrayof_location_to_gvariant(DbArrayofLocationRef v,GDestroyNotify notify,gpointer user_data)1893 db_arrayof_location_to_gvariant (DbArrayofLocationRef v,
1894                              GDestroyNotify      notify,
1895                              gpointer            user_data)
1896 {
1897   return g_variant_new_from_data (DB_ARRAYOF_LOCATION_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
1898 }
1899 
1900 static inline GVariant *
db_arrayof_location_to_owned_gvariant(DbArrayofLocationRef v,GVariant * base)1901 db_arrayof_location_to_owned_gvariant (DbArrayofLocationRef v, GVariant *base)
1902 {
1903   return db_arrayof_location_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
1904 }
1905 
1906 static inline GVariant *
db_arrayof_location_peek_as_gvariant(DbArrayofLocationRef v)1907 db_arrayof_location_peek_as_gvariant (DbArrayofLocationRef v)
1908 {
1909   return g_variant_new_from_data (DB_ARRAYOF_LOCATION_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
1910 }
1911 
1912 static inline DbArrayofLocationRef
db_arrayof_location_from_variant(DbVariantRef v)1913 db_arrayof_location_from_variant (DbVariantRef v)
1914 {
1915   const GVariantType  *type;
1916   DbRef child = Db_variant_get_child (v, &type);
1917   g_assert (g_variant_type_equal(type, DB_ARRAYOF_LOCATION_TYPESTRING));
1918   return db_arrayof_location_from_data (child.base, child.size);
1919 }
1920 
1921 static inline gsize
db_arrayof_location_get_length(DbArrayofLocationRef v)1922 db_arrayof_location_get_length (DbArrayofLocationRef v)
1923 {
1924   if (v.size == 0)
1925     return 0;
1926   guint offset_size = Db_ref_get_offset_size (v.size);
1927   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1928   gsize offsets_array_size;
1929   if (last_end > v.size)
1930     return 0;
1931   offsets_array_size = v.size - last_end;
1932   if (offsets_array_size % offset_size != 0)
1933     return 0;
1934   gsize length  = offsets_array_size / offset_size;
1935   return length;
1936 }
1937 
1938 static inline DbLocationRef
db_arrayof_location_get_at(DbArrayofLocationRef v,gsize index)1939 db_arrayof_location_get_at (DbArrayofLocationRef v, gsize index)
1940 {
1941   guint offset_size = Db_ref_get_offset_size (v.size);
1942   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
1943   gsize len = (v.size - last_end) / offset_size;
1944   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 8) : 0;
1945   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, len - index - 1);
1946   g_assert (start <= end);
1947   g_assert (end <= last_end);
1948   return (DbLocationRef) { ((const char *)v.base) + start, end - start };
1949 }
1950 
1951 static inline GString *
db_arrayof_location_format(DbArrayofLocationRef v,GString * s,gboolean type_annotate)1952 db_arrayof_location_format (DbArrayofLocationRef v, GString *s, gboolean type_annotate)
1953 {
1954   gsize len = db_arrayof_location_get_length (v);
1955   gsize i;
1956   if (len == 0 && type_annotate)
1957     g_string_append_printf (s, "@%s ", DB_ARRAYOF_LOCATION_TYPESTRING);
1958   g_string_append_c (s, '[');
1959   for (i = 0; i < len; i++)
1960     {
1961       if (i != 0)
1962         g_string_append (s, ", ");
1963       db_location_format (db_arrayof_location_get_at (v, i), s, ((i == 0) ? type_annotate : FALSE));
1964     }
1965   g_string_append_c (s, ']');
1966   return s;
1967 }
1968 
1969 static inline char *
db_arrayof_location_print(DbArrayofLocationRef v,gboolean type_annotate)1970 db_arrayof_location_print (DbArrayofLocationRef v, gboolean type_annotate)
1971 {
1972   GString *s = g_string_new ("");
1973   db_arrayof_location_format (v, s, type_annotate);
1974   return g_string_free (s, FALSE);
1975 }
1976 
1977 /************** DbWorld *******************/
1978 #define DB_WORLD_TYPESTRING "(ta{sq}a{sq}a{s((ss)as)}a((ss)ss(dd)ssqyqqaqaq))"
1979 #define DB_WORLD_TYPEFORMAT ((const GVariantType *) DB_WORLD_TYPESTRING)
1980 
1981 typedef struct {
1982  gconstpointer base;
1983  gsize size;
1984 } DbWorldRef;
1985 
1986 
1987 static inline DbWorldRef
db_world_from_gvariant(GVariant * v)1988 db_world_from_gvariant (GVariant *v)
1989 {
1990   g_assert (g_variant_type_equal (g_variant_get_type (v), DB_WORLD_TYPESTRING));
1991   return (DbWorldRef) { g_variant_get_data (v), g_variant_get_size (v) };
1992 }
1993 
1994 static inline DbWorldRef
db_world_from_bytes(GBytes * b)1995 db_world_from_bytes (GBytes *b)
1996 {
1997   return (DbWorldRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
1998 }
1999 
2000 static inline DbWorldRef
db_world_from_data(gconstpointer data,gsize size)2001 db_world_from_data (gconstpointer data, gsize size)
2002 {
2003   return (DbWorldRef) { data, size };
2004 }
2005 
2006 static inline GVariant *
db_world_dup_to_gvariant(DbWorldRef v)2007 db_world_dup_to_gvariant (DbWorldRef v)
2008 {
2009   return g_variant_new_from_data (DB_WORLD_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
2010 }
2011 
2012 static inline GVariant *
db_world_to_gvariant(DbWorldRef v,GDestroyNotify notify,gpointer user_data)2013 db_world_to_gvariant (DbWorldRef v,
2014                              GDestroyNotify      notify,
2015                              gpointer            user_data)
2016 {
2017   return g_variant_new_from_data (DB_WORLD_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
2018 }
2019 
2020 static inline GVariant *
db_world_to_owned_gvariant(DbWorldRef v,GVariant * base)2021 db_world_to_owned_gvariant (DbWorldRef v, GVariant *base)
2022 {
2023   return db_world_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
2024 }
2025 
2026 static inline GVariant *
db_world_peek_as_gvariant(DbWorldRef v)2027 db_world_peek_as_gvariant (DbWorldRef v)
2028 {
2029   return g_variant_new_from_data (DB_WORLD_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
2030 }
2031 
2032 static inline DbWorldRef
db_world_from_variant(DbVariantRef v)2033 db_world_from_variant (DbVariantRef v)
2034 {
2035   const GVariantType  *type;
2036   DbRef child = Db_variant_get_child (v, &type);
2037   g_assert (g_variant_type_equal(type, DB_WORLD_TYPESTRING));
2038   return db_world_from_data (child.base, child.size);
2039 }
2040 
2041 #define DB_WORLD_INDEXOF_MAGIC 0
2042 
2043 static inline guint64
db_world_get_magic(DbWorldRef v)2044 db_world_get_magic (DbWorldRef v)
2045 {
2046   guint offset = ((7) & (~(gsize)7)) + 0;
2047   g_assert (offset + 8 < v.size);
2048   return (guint64)G_STRUCT_MEMBER(guint64, v.base, offset);
2049 }
2050 
2051 #define DB_WORLD_INDEXOF_LOC_BY_COUNTRY 1
2052 
2053 static inline DbWorldLocByCountryRef
db_world_get_loc_by_country(DbWorldRef v)2054 db_world_get_loc_by_country (DbWorldRef v)
2055 {
2056   guint offset_size = Db_ref_get_offset_size (v.size);
2057   guint offset = ((7) & (~(gsize)7)) + 8;
2058   gsize start = offset;
2059   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
2060   g_assert (start <= end);
2061   g_assert (end <= v.size);
2062   return (DbWorldLocByCountryRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
2063 }
2064 
2065 #define DB_WORLD_INDEXOF_LOC_BY_METAR 2
2066 
2067 static inline DbWorldLocByMetarRef
db_world_get_loc_by_metar(DbWorldRef v)2068 db_world_get_loc_by_metar (DbWorldRef v)
2069 {
2070   guint offset_size = Db_ref_get_offset_size (v.size);
2071   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
2072   guint offset = ((last_end + 1) & (~(gsize)1)) + 0;
2073   gsize start = offset;
2074   gsize end = DB_REF_READ_FRAME_OFFSET(v, 1);
2075   g_assert (start <= end);
2076   g_assert (end <= v.size);
2077   return (DbWorldLocByMetarRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
2078 }
2079 
2080 #define DB_WORLD_INDEXOF_TIMEZONES 3
2081 
2082 static inline DbWorldTimezonesRef
db_world_get_timezones(DbWorldRef v)2083 db_world_get_timezones (DbWorldRef v)
2084 {
2085   guint offset_size = Db_ref_get_offset_size (v.size);
2086   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 1);
2087   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
2088   gsize start = offset;
2089   gsize end = DB_REF_READ_FRAME_OFFSET(v, 2);
2090   g_assert (start <= end);
2091   g_assert (end <= v.size);
2092   return (DbWorldTimezonesRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
2093 }
2094 
2095 #define DB_WORLD_INDEXOF_LOCATIONS 4
2096 
2097 static inline DbArrayofLocationRef
db_world_get_locations(DbWorldRef v)2098 db_world_get_locations (DbWorldRef v)
2099 {
2100   guint offset_size = Db_ref_get_offset_size (v.size);
2101   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 2);
2102   guint offset = ((last_end + 7) & (~(gsize)7)) + 0;
2103   gsize start = offset;
2104   gsize end = v.size - offset_size * 3;
2105   g_assert (start <= end);
2106   g_assert (end <= v.size);
2107   return (DbArrayofLocationRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
2108 }
2109 
2110 static inline GString *
db_world_format(DbWorldRef v,GString * s,gboolean type_annotate)2111 db_world_format (DbWorldRef v, GString *s, gboolean type_annotate)
2112 {
2113   g_string_append_printf (s, "(%s%"G_GUINT64_FORMAT", ",
2114                    type_annotate ? "uint64 " : "",
2115                    db_world_get_magic (v));
2116   db_world_loc_by_country_format (db_world_get_loc_by_country (v), s, type_annotate);
2117   g_string_append (s, ", ");
2118   db_world_loc_by_metar_format (db_world_get_loc_by_metar (v), s, type_annotate);
2119   g_string_append (s, ", ");
2120   db_world_timezones_format (db_world_get_timezones (v), s, type_annotate);
2121   g_string_append (s, ", ");
2122   db_arrayof_location_format (db_world_get_locations (v), s, type_annotate);
2123   g_string_append (s, ")");
2124   return s;
2125 }
2126 
2127 static inline char *
db_world_print(DbWorldRef v,gboolean type_annotate)2128 db_world_print (DbWorldRef v, gboolean type_annotate)
2129 {
2130   GString *s = g_string_new ("");
2131   db_world_format (v, s, type_annotate);
2132   return g_string_free (s, FALSE);
2133 }
2134 #endif
2135