[libgweather/benzea/wip-variant-backend: 5/15] Stop using maybe types



commit 9a0970021ac9b7eebf9ef2b5bfe6a567d8b82641
Author: Benjamin Berg <bberg redhat com>
Date:   Sun Apr 26 13:31:05 2020 +0200

    Stop using maybe types
    
    Just use NaN and 0xffff to mark invalid entries instead. Also stop
    byteswapping (for now at least) to avoid uneccessary tuple nesting.

 data/gen-locations-variant.py   |  36 +-
 libgweather/gweather-db.h       | 741 ++++++++++++----------------------------
 libgweather/gweather-location.c |  67 ++--
 libgweather/gweather-private.h  |   2 +
 libgweather/gweather.gv         |  24 +-
 5 files changed, 278 insertions(+), 592 deletions(-)
---
diff --git a/data/gen-locations-variant.py b/data/gen-locations-variant.py
index 28bd9c4..82278c3 100755
--- a/data/gen-locations-variant.py
+++ b/data/gen-locations-variant.py
@@ -13,6 +13,9 @@ root = tree.getroot()
 assert root.tag == "gweather"
 assert root.attrib['format'] == "1.0"
 
+# Maybe types are annyoing, so use an invalid idx
+INVALID_IDX = 0xffff
+
 levels = {
   'gweather' : 0,
   'region' : 1,
@@ -47,7 +50,7 @@ def get_coordinates(elem):
     if coordinates:
         return tuple(float(c) * math.pi / 180.0 for c in coordinates.split())
     else:
-        return None
+        return float("NaN"), float("NaN")
 
 def calc_distance(loc_a, loc_b):
     # average earth radius
@@ -95,7 +98,7 @@ def loc_variant(loc):
     if tz_hint:
         for i, tz in enumerate(timezones):
             if tz.get('id') == tz_hint:
-                tz_hint = (i,)
+                tz_hint = i
                 break
         else:
             assert "Should not be reached"
@@ -106,8 +109,7 @@ def loc_variant(loc):
     try:
         parent_idx = locations.index(parent)
     except:
-        # point to self
-        parent_idx = locations.index(loc)
+        parent_idx = None
 
     nearest_idx = None
     if loc.tag == 'city' and len(children) == 0:
@@ -123,21 +125,21 @@ def loc_variant(loc):
                 nearest_dist = dist
 
         if nearest:
-            nearest_idx = (locations.index(nearest), )
+            nearest_idx = locations.index(nearest)
 
-    return GLib.Variant('((ss)ssm(dd)ssm(q)ym(q)(q)a(q)a(q))', (
+    return GLib.Variant('((ss)ss(dd)ssqyqqaqaq)', (
             name,
             loc.findtext('zone', default=''),
             loc.findtext('radar', default=''),
             coordinate,
             loc.findtext('iso-code', default=''),
             loc.findtext('code', default=''),
-            tz_hint,
+            tz_hint if tz_hint is not None else INVALID_IDX,
             levels[loc.tag],
-            nearest_idx,
-            (parent_idx, ),
-            [(c,) for c in children],
-            [(z,) for z in zones]
+            nearest_idx if nearest_idx is not None else INVALID_IDX,
+            parent_idx if parent_idx is not None else INVALID_IDX,
+            children,
+            zones,
         ))
 
 locations.append(root)
@@ -172,13 +174,13 @@ timezones.sort(key=lambda tz: tz.get('id'))
 loc_by_country.sort(key=lambda loc: loc.findtext('iso-code'))
 loc_by_metar.sort(key=lambda loc: loc.findtext('code'))
 
-loc_by_country_var = [(loc.findtext('iso-code'), (locations.index(loc),)) for loc in loc_by_country]
-loc_by_metar_var = [(loc.findtext('code'), (locations.index(loc),)) for loc in loc_by_metar]
+loc_by_country_var = [(loc.findtext('iso-code'), locations.index(loc)) for loc in loc_by_country]
+loc_by_metar_var = [(loc.findtext('code'), locations.index(loc)) for loc in loc_by_metar]
 
 timezones_var = [(tz.get('id'), tz_variant(tz)) for tz in timezones]
 locations_var = [loc_variant(loc) for loc in locations]
 
-res = GLib.Variant("(a{s(q)}a{s(q)}a{s((ss)as)}a((ss)ssm(dd)ssm(q)ym(q)(q)a(q)a(q)))", (
+res = GLib.Variant("(a{sq}a{sq}a{s((ss)as)}a((ss)ss(dd)ssqyqqaqaq))", (
     loc_by_country_var,
     loc_by_metar_var,
     timezones_var,
@@ -186,8 +188,10 @@ res = GLib.Variant("(a{s(q)}a{s(q)}a{s((ss)as)}a((ss)ssm(dd)ssm(q)ym(q)(q)a(q)a(
     ))
 
 if struct.pack('h', 0x01)[0]:
-    # byteswap on little endian
-    res = res.byteswap()
+    # byteswap on little endian; not currently, we might do this again if the
+    # schema compiler improves
+    #res = res.byteswap()
+    pass
 
 data = res.get_data_as_bytes().get_data()
 open(sys.argv[2], 'bw').write(data)
diff --git a/libgweather/gweather-db.h b/libgweather/gweather-db.h
index 37386ba..51b2a92 100644
--- a/libgweather/gweather-db.h
+++ b/libgweather/gweather-db.h
@@ -11,12 +11,12 @@ typedef struct {
  gsize size;
 } DbRef;
 
-#define DB_REF_READ_FRAME_OFFSET(_v, _index) db_ref_read_unaligned_le ((guchar*)((_v).base) + (_v).size - 
(offset_size * ((_index) + 1)), offset_size)
+#define DB_REF_READ_FRAME_OFFSET(_v, _index) Db_ref_read_unaligned_le ((guchar*)((_v).base) + (_v).size - 
(offset_size * ((_index) + 1)), offset_size)
 #define DB_REF_ALIGN(_offset, _align_to) ((_offset + _align_to - 1) & ~(gsize)(_align_to - 1))
 
 /* Note: clz is undefinded for 0, so never call this size == 0 */
 G_GNUC_CONST static inline guint
-db_ref_get_offset_size (gsize size)
+Db_ref_get_offset_size (gsize size)
 {
 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) && defined(__LP64__)
   /* Instead of using a lookup table we use nibbles in a lookup word */
@@ -41,7 +41,7 @@ db_ref_get_offset_size (gsize size)
 }
 
 G_GNUC_PURE static inline guint64
-db_ref_read_unaligned_le (guchar *bytes, guint   size)
+Db_ref_read_unaligned_le (guchar *bytes, guint   size)
 {
   union
   {
@@ -70,7 +70,7 @@ db_ref_read_unaligned_le (guchar *bytes, guint   size)
 }
 
 static inline void
-__db_gstring_append_double (GString *string, double d)
+__Db_gstring_append_double (GString *string, double d)
 {
   gchar buffer[100];
   gint i;
@@ -92,7 +92,7 @@ __db_gstring_append_double (GString *string, double d)
 }
 
 static inline void
-__db_gstring_append_string (GString *string, const char *str)
+__Db_gstring_append_string (GString *string, const char *str)
 {
   gunichar quote = strchr (str, '\'') ? '"' : '\'';
 
@@ -162,7 +162,7 @@ typedef struct {
 } DbVariantRef;
 
 static inline DbRef
-db_variant_get_child (DbVariantRef v, const GVariantType **out_type)
+Db_variant_get_child (DbVariantRef v, const GVariantType **out_type)
 {
   if (v.size)
     {
@@ -194,7 +194,7 @@ db_variant_get_child (DbVariantRef v, const GVariantType **out_type)
 }
 
 static inline const GVariantType *
-db_variant_get_type (DbVariantRef v)
+Db_variant_get_type (DbVariantRef v)
 {
   if (v.size)
     {
@@ -220,38 +220,38 @@ db_variant_get_type (DbVariantRef v)
 }
 
 static inline gboolean
-db_variant_is_type (DbVariantRef v, const GVariantType *type)
+Db_variant_is_type (DbVariantRef v, const GVariantType *type)
 {
-   return g_variant_type_equal (db_variant_get_type (v), type);
+   return g_variant_type_equal (Db_variant_get_type (v), type);
 }
 
 static inline DbVariantRef
-db_variant_from_gvariant (GVariant *v)
+Db_variant_from_gvariant (GVariant *v)
 {
   g_assert (g_variant_type_equal (g_variant_get_type (v), G_VARIANT_TYPE_VARIANT));
   return (DbVariantRef) { g_variant_get_data (v), g_variant_get_size (v) };
 }
 
 static inline DbVariantRef
-db_variant_from_bytes (GBytes *b)
+Db_variant_from_bytes (GBytes *b)
 {
   return (DbVariantRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
 }
 
 static inline DbVariantRef
-db_variant_from_data (gconstpointer data, gsize size)
+Db_variant_from_data (gconstpointer data, gsize size)
 {
   return (DbVariantRef) { data, size };
 }
 
 static inline GVariant *
-db_variant_dup_to_gvariant (DbVariantRef v)
+Db_variant_dup_to_gvariant (DbVariantRef v)
 {
   return g_variant_new_from_data (G_VARIANT_TYPE_VARIANT, g_memdup (v.base, v.size), v.size, TRUE, g_free, 
NULL);
 }
 
 static inline GVariant *
-db_variant_to_gvariant (DbVariantRef v,
+Db_variant_to_gvariant (DbVariantRef v,
                               GDestroyNotify      notify,
                               gpointer            user_data)
 {
@@ -259,231 +259,129 @@ db_variant_to_gvariant (DbVariantRef v,
 }
 
 static inline GVariant *
-db_variant_to_owned_gvariant (DbVariantRef v,
+Db_variant_to_owned_gvariant (DbVariantRef v,
                                      GVariant *base)
 {
-  return db_variant_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
+  return Db_variant_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
 }
 
 static inline GVariant *
-db_variant_peek_as_variant (DbVariantRef v)
+Db_variant_peek_as_variant (DbVariantRef v)
 {
   return g_variant_new_from_data (G_VARIANT_TYPE_VARIANT, v.base, v.size, TRUE, NULL, NULL);
 }
 
 static inline DbVariantRef
-db_variant_from_variant (DbVariantRef v)
+Db_variant_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, G_VARIANT_TYPE_VARIANT));
-  return db_variant_from_data (child.base, child.size);
+  return Db_variant_from_data (child.base, child.size);
 }
 
 static inline GVariant *
-db_variant_dup_child_to_gvariant (DbVariantRef v)
+Db_variant_dup_child_to_gvariant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   return g_variant_new_from_data (type, g_memdup (child.base, child.size), child.size, TRUE, g_free, NULL);
 }
 
 static inline GVariant *
-db_variant_peek_child_as_variant (DbVariantRef v)
+Db_variant_peek_child_as_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   return g_variant_new_from_data (type, child.base, child.size, TRUE, NULL, NULL);
 }
 
 static inline GString *
-db_variant_format (DbVariantRef v, GString *s, gboolean type_annotate)
+Db_variant_format (DbVariantRef v, GString *s, gboolean type_annotate)
 {
 #ifdef DB_DEEP_VARIANT_FORMAT
-  GVariant *gv = db_variant_peek_as_variant (v);
+  GVariant *gv = Db_variant_peek_as_variant (v);
   return g_variant_print_string (gv, s, TRUE);
 #else
-  const GVariantType  *type = db_variant_get_type (v);
+  const GVariantType  *type = Db_variant_get_type (v);
   g_string_append_printf (s, "<@%.*s>", (int)g_variant_type_get_string_length (type), (const char *)type);
   return s;
 #endif
 }
 
 static inline char *
-db_variant_print (DbVariantRef v, gboolean type_annotate)
+Db_variant_print (DbVariantRef v, gboolean type_annotate)
 {
   GString *s = g_string_new ("");
-  db_variant_format (v, s, type_annotate);
+  Db_variant_format (v, s, type_annotate);
   return g_string_free (s, FALSE);
 }
 static inline gboolean
-db_variant_get_boolean (DbVariantRef v)
+Db_variant_get_boolean (DbVariantRef v)
 {
   return (gboolean)*((guint8 *)v.base);
 }
 static inline guint8
-db_variant_get_byte (DbVariantRef v)
+Db_variant_get_byte (DbVariantRef v)
 {
   return (guint8)*((guint8 *)v.base);
 }
 static inline gint16
-db_variant_get_int16 (DbVariantRef v)
+Db_variant_get_int16 (DbVariantRef v)
 {
   return (gint16)*((gint16 *)v.base);
 }
 static inline guint16
-db_variant_get_uint16 (DbVariantRef v)
+Db_variant_get_uint16 (DbVariantRef v)
 {
   return (guint16)*((guint16 *)v.base);
 }
 static inline gint32
-db_variant_get_int32 (DbVariantRef v)
+Db_variant_get_int32 (DbVariantRef v)
 {
   return (gint32)*((gint32 *)v.base);
 }
 static inline guint32
-db_variant_get_uint32 (DbVariantRef v)
+Db_variant_get_uint32 (DbVariantRef v)
 {
   return (guint32)*((guint32 *)v.base);
 }
 static inline gint64
-db_variant_get_int64 (DbVariantRef v)
+Db_variant_get_int64 (DbVariantRef v)
 {
   return (gint64)*((gint64 *)v.base);
 }
 static inline guint64
-db_variant_get_uint64 (DbVariantRef v)
+Db_variant_get_uint64 (DbVariantRef v)
 {
   return (guint64)*((guint64 *)v.base);
 }
 static inline guint32
-db_variant_get_handle (DbVariantRef v)
+Db_variant_get_handle (DbVariantRef v)
 {
   return (guint32)*((guint32 *)v.base);
 }
 static inline double
-db_variant_get_double (DbVariantRef v)
+Db_variant_get_double (DbVariantRef v)
 {
   return (double)*((double *)v.base);
 }
 static inline const char *
-db_variant_get_string (DbVariantRef v)
+Db_variant_get_string (DbVariantRef v)
 {
   return (const char *)v.base;
 }
 static inline const char *
-db_variant_get_objectpath (DbVariantRef v)
+Db_variant_get_objectpath (DbVariantRef v)
 {
   return (const char *)v.base;
 }
 static inline const char *
-db_variant_get_signature (DbVariantRef v)
+Db_variant_get_signature (DbVariantRef v)
 {
   return (const char *)v.base;
 }
 
-/************** DbIdx *******************/
-#define DB_IDX_TYPESTRING "(q)"
-#define DB_IDX_TYPEFORMAT ((const GVariantType *) DB_IDX_TYPESTRING)
-
-typedef struct {
- gconstpointer base;
- gsize size;
-} DbIdxRef;
-
-typedef struct {
-  guint16 idx;/* big endian */
-} DbIdx;
-
-static inline DbIdxRef
-db_idx_from_gvariant (GVariant *v)
-{
-  g_assert (g_variant_type_equal (g_variant_get_type (v), DB_IDX_TYPESTRING));
-  return (DbIdxRef) { g_variant_get_data (v), g_variant_get_size (v) };
-}
-
-static inline DbIdxRef
-db_idx_from_bytes (GBytes *b)
-{
-  g_assert (g_bytes_get_size (b) == 2);
-
-  return (DbIdxRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
-}
-
-static inline DbIdxRef
-db_idx_from_data (gconstpointer data, gsize size)
-{
-  g_assert (size == 2);
-
-  return (DbIdxRef) { data, size };
-}
-
-static inline GVariant *
-db_idx_dup_to_gvariant (DbIdxRef v)
-{
-  return g_variant_new_from_data (DB_IDX_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, NULL);
-}
-
-static inline GVariant *
-db_idx_to_gvariant (DbIdxRef v,
-                             GDestroyNotify      notify,
-                             gpointer            user_data)
-{
-  return g_variant_new_from_data (DB_IDX_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
-}
-
-static inline GVariant *
-db_idx_to_owned_gvariant (DbIdxRef v, GVariant *base)
-{
-  return db_idx_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
-}
-
-static inline GVariant *
-db_idx_peek_as_gvariant (DbIdxRef v)
-{
-  return g_variant_new_from_data (DB_IDX_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
-}
-
-static inline DbIdxRef
-db_idx_from_variant (DbVariantRef v)
-{
-  const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
-  g_assert (g_variant_type_equal(type, DB_IDX_TYPESTRING));
-  return db_idx_from_data (child.base, child.size);
-}
-
-static inline const DbIdx *
-db_idx_peek (DbIdxRef v) {
-  return (const DbIdx *)v.base;
-}
-
-#define DB_IDX_INDEXOF_IDX 0
-
-static inline guint16
-db_idx_get_idx (DbIdxRef v)
-{
-  guint offset = ((1) & (~(gsize)1)) + 0;
-  return GUINT16_FROM_BE((guint16)G_STRUCT_MEMBER(guint16, v.base, offset));
-}
-
-static inline GString *
-db_idx_format (DbIdxRef v, GString *s, gboolean type_annotate)
-{
-  g_string_append_printf (s, "(%s%"G_GUINT16_FORMAT",)",
-                   type_annotate ? "uint16 " : "",
-                   db_idx_get_idx (v));
-  return s;
-}
-
-static inline char *
-db_idx_print (DbIdxRef v, gboolean type_annotate)
-{
-  GString *s = g_string_new ("");
-  db_idx_format (v, s, type_annotate);
-  return g_string_free (s, FALSE);
-}
-
 /************** DbI18n *******************/
 #define DB_I18N_TYPESTRING "(ss)"
 #define DB_I18N_TYPEFORMAT ((const GVariantType *) DB_I18N_TYPESTRING)
@@ -543,7 +441,7 @@ static inline DbI18nRef
 db_i18n_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_I18N_TYPESTRING));
   return db_i18n_from_data (child.base, child.size);
 }
@@ -553,7 +451,7 @@ db_i18n_from_variant (DbVariantRef v)
 static inline const char *
 db_i18n_get_str (DbI18nRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   guint offset = ((0) & (~(gsize)0)) + 0;
   const char *base = (const char *)v.base;
   gsize start = offset;
@@ -569,7 +467,7 @@ db_i18n_get_str (DbI18nRef v)
 static inline const char *
 db_i18n_get_msgctxt (DbI18nRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
   const char *base = (const char *)v.base;
@@ -585,9 +483,9 @@ static inline GString *
 db_i18n_format (DbI18nRef v, GString *s, gboolean type_annotate)
 {
   g_string_append (s, "(");
-  __db_gstring_append_string (s, db_i18n_get_str (v));
+  __Db_gstring_append_string (s, db_i18n_get_str (v));
   g_string_append (s, ", ");
-  __db_gstring_append_string (s, db_i18n_get_msgctxt (v));
+  __Db_gstring_append_string (s, db_i18n_get_msgctxt (v));
   g_string_append (s, ")");
   return s;
 }
@@ -659,7 +557,7 @@ static inline DbArrayofstringRef
 db_arrayofstring_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_ARRAYOFSTRING_TYPESTRING));
   return db_arrayofstring_from_data (child.base, child.size);
 }
@@ -669,7 +567,7 @@ db_arrayofstring_get_length (DbArrayofstringRef v)
 {
   if (v.size == 0)
     return 0;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize offsets_array_size;
   if (last_end > v.size)
@@ -684,7 +582,7 @@ db_arrayofstring_get_length (DbArrayofstringRef v)
 static inline const char *
 db_arrayofstring_get_at (DbArrayofstringRef v, gsize index)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize len = (v.size - last_end) / offset_size;
   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 1) : 0;
@@ -725,7 +623,7 @@ db_arrayofstring_format (DbArrayofstringRef v, GString *s, gboolean type_annotat
     {
       if (i != 0)
         g_string_append (s, ", ");
-      __db_gstring_append_string (s, db_arrayofstring_get_at (v, i));
+      __Db_gstring_append_string (s, db_arrayofstring_get_at (v, i));
     }
   g_string_append_c (s, ']');
   return s;
@@ -798,7 +696,7 @@ static inline DbTimezoneRef
 db_timezone_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_TIMEZONE_TYPESTRING));
   return db_timezone_from_data (child.base, child.size);
 }
@@ -808,7 +706,7 @@ db_timezone_from_variant (DbVariantRef v)
 static inline DbI18nRef
 db_timezone_get_name (DbTimezoneRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   guint offset = ((0) & (~(gsize)0)) + 0;
   gsize start = offset;
   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
@@ -822,7 +720,7 @@ db_timezone_get_name (DbTimezoneRef v)
 static inline DbArrayofstringRef
 db_timezone_get_obsoletes (DbTimezoneRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
   gsize start = offset;
@@ -861,8 +759,8 @@ typedef struct {
 } DbCoordinateRef;
 
 typedef struct {
-  double lat;/* big endian */
-  double lon;/* big endian */
+  double lat;
+  double lon;
 } DbCoordinate;
 
 static inline DbCoordinateRef
@@ -918,7 +816,7 @@ static inline DbCoordinateRef
 db_coordinate_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_COORDINATE_TYPESTRING));
   return db_coordinate_from_data (child.base, child.size);
 }
@@ -934,7 +832,7 @@ static inline double
 db_coordinate_get_lat (DbCoordinateRef v)
 {
   guint offset = ((7) & (~(gsize)7)) + 0;
-  return DOUBLE_FROM_BE((double)G_STRUCT_MEMBER(double, v.base, offset));
+  return (double)G_STRUCT_MEMBER(double, v.base, offset);
 }
 
 #define DB_COORDINATE_INDEXOF_LON 1
@@ -943,16 +841,16 @@ static inline double
 db_coordinate_get_lon (DbCoordinateRef v)
 {
   guint offset = ((7) & (~(gsize)7)) + 8;
-  return DOUBLE_FROM_BE((double)G_STRUCT_MEMBER(double, v.base, offset));
+  return (double)G_STRUCT_MEMBER(double, v.base, offset);
 }
 
 static inline GString *
 db_coordinate_format (DbCoordinateRef v, GString *s, gboolean type_annotate)
 {
   g_string_append (s, "(");
-  __db_gstring_append_double (s, db_coordinate_get_lat (v));
+  __Db_gstring_append_double (s, db_coordinate_get_lat (v));
   g_string_append (s, ", ");
-  __db_gstring_append_double (s, db_coordinate_get_lon (v));
+  __Db_gstring_append_double (s, db_coordinate_get_lon (v));
   g_string_append (s, ")");
   return s;
 }
@@ -965,315 +863,117 @@ db_coordinate_print (DbCoordinateRef v, gboolean type_annotate)
   return g_string_free (s, FALSE);
 }
 
-/************** DbMaybeCoordinate *******************/
-#define DB_MAYBE_COORDINATE_TYPESTRING "m(dd)"
-#define DB_MAYBE_COORDINATE_TYPEFORMAT ((const GVariantType *) DB_MAYBE_COORDINATE_TYPESTRING)
-
-typedef struct {
- gconstpointer base;
- gsize size;
-} DbMaybeCoordinateRef;
-
-
-static inline DbMaybeCoordinateRef
-db_maybe_coordinate_from_gvariant (GVariant *v)
-{
-  g_assert (g_variant_type_equal (g_variant_get_type (v), DB_MAYBE_COORDINATE_TYPESTRING));
-  return (DbMaybeCoordinateRef) { g_variant_get_data (v), g_variant_get_size (v) };
-}
-
-static inline DbMaybeCoordinateRef
-db_maybe_coordinate_from_bytes (GBytes *b)
-{
-  return (DbMaybeCoordinateRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
-}
-
-static inline DbMaybeCoordinateRef
-db_maybe_coordinate_from_data (gconstpointer data, gsize size)
-{
-  return (DbMaybeCoordinateRef) { data, size };
-}
-
-static inline GVariant *
-db_maybe_coordinate_dup_to_gvariant (DbMaybeCoordinateRef v)
-{
-  return g_variant_new_from_data (DB_MAYBE_COORDINATE_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, 
g_free, NULL);
-}
-
-static inline GVariant *
-db_maybe_coordinate_to_gvariant (DbMaybeCoordinateRef v,
-                             GDestroyNotify      notify,
-                             gpointer            user_data)
-{
-  return g_variant_new_from_data (DB_MAYBE_COORDINATE_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
-}
-
-static inline GVariant *
-db_maybe_coordinate_to_owned_gvariant (DbMaybeCoordinateRef v, GVariant *base)
-{
-  return db_maybe_coordinate_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
-}
-
-static inline GVariant *
-db_maybe_coordinate_peek_as_gvariant (DbMaybeCoordinateRef v)
-{
-  return g_variant_new_from_data (DB_MAYBE_COORDINATE_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
-}
-
-static inline DbMaybeCoordinateRef
-db_maybe_coordinate_from_variant (DbVariantRef v)
-{
-  const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
-  g_assert (g_variant_type_equal(type, DB_MAYBE_COORDINATE_TYPESTRING));
-  return db_maybe_coordinate_from_data (child.base, child.size);
-}
-
-static inline gboolean
-db_maybe_coordinate_has_value(DbMaybeCoordinateRef v)
-{
-  return v.size != 0;
-}
-static inline DbCoordinateRef
-db_maybe_coordinate_get_value (DbMaybeCoordinateRef v)
-{
-  g_assert (v.size == 16);
-  return (DbCoordinateRef) { v.base, v.size };
-}
-static inline GString *
-db_maybe_coordinate_format (DbMaybeCoordinateRef v, GString *s, gboolean type_annotate)
-{
-  if (type_annotate)
-    g_string_append_printf (s, "@%s ", DB_MAYBE_COORDINATE_TYPESTRING);
-  if (v.size != 0)
-    {
-      db_coordinate_format (db_maybe_coordinate_get_value (v), s, FALSE);
-    }
-  else
-    {
-      g_string_append (s, "nothing");
-    }
-  return s;
-}
-
-static inline char *
-db_maybe_coordinate_print (DbMaybeCoordinateRef v, gboolean type_annotate)
-{
-  GString *s = g_string_new ("");
-  db_maybe_coordinate_format (v, s, type_annotate);
-  return g_string_free (s, FALSE);
-}
-
-/************** DbMaybeIdx *******************/
-#define DB_MAYBE_IDX_TYPESTRING "m(q)"
-#define DB_MAYBE_IDX_TYPEFORMAT ((const GVariantType *) DB_MAYBE_IDX_TYPESTRING)
-
-typedef struct {
- gconstpointer base;
- gsize size;
-} DbMaybeIdxRef;
-
-
-static inline DbMaybeIdxRef
-db_maybe_idx_from_gvariant (GVariant *v)
-{
-  g_assert (g_variant_type_equal (g_variant_get_type (v), DB_MAYBE_IDX_TYPESTRING));
-  return (DbMaybeIdxRef) { g_variant_get_data (v), g_variant_get_size (v) };
-}
-
-static inline DbMaybeIdxRef
-db_maybe_idx_from_bytes (GBytes *b)
-{
-  return (DbMaybeIdxRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
-}
-
-static inline DbMaybeIdxRef
-db_maybe_idx_from_data (gconstpointer data, gsize size)
-{
-  return (DbMaybeIdxRef) { data, size };
-}
-
-static inline GVariant *
-db_maybe_idx_dup_to_gvariant (DbMaybeIdxRef v)
-{
-  return g_variant_new_from_data (DB_MAYBE_IDX_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, g_free, 
NULL);
-}
-
-static inline GVariant *
-db_maybe_idx_to_gvariant (DbMaybeIdxRef v,
-                             GDestroyNotify      notify,
-                             gpointer            user_data)
-{
-  return g_variant_new_from_data (DB_MAYBE_IDX_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
-}
-
-static inline GVariant *
-db_maybe_idx_to_owned_gvariant (DbMaybeIdxRef v, GVariant *base)
-{
-  return db_maybe_idx_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
-}
-
-static inline GVariant *
-db_maybe_idx_peek_as_gvariant (DbMaybeIdxRef v)
-{
-  return g_variant_new_from_data (DB_MAYBE_IDX_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
-}
-
-static inline DbMaybeIdxRef
-db_maybe_idx_from_variant (DbVariantRef v)
-{
-  const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
-  g_assert (g_variant_type_equal(type, DB_MAYBE_IDX_TYPESTRING));
-  return db_maybe_idx_from_data (child.base, child.size);
-}
-
-static inline gboolean
-db_maybe_idx_has_value(DbMaybeIdxRef v)
-{
-  return v.size != 0;
-}
-static inline DbIdxRef
-db_maybe_idx_get_value (DbMaybeIdxRef v)
-{
-  g_assert (v.size == 2);
-  return (DbIdxRef) { v.base, v.size };
-}
-static inline GString *
-db_maybe_idx_format (DbMaybeIdxRef v, GString *s, gboolean type_annotate)
-{
-  if (type_annotate)
-    g_string_append_printf (s, "@%s ", DB_MAYBE_IDX_TYPESTRING);
-  if (v.size != 0)
-    {
-      db_idx_format (db_maybe_idx_get_value (v), s, FALSE);
-    }
-  else
-    {
-      g_string_append (s, "nothing");
-    }
-  return s;
-}
-
-static inline char *
-db_maybe_idx_print (DbMaybeIdxRef v, gboolean type_annotate)
-{
-  GString *s = g_string_new ("");
-  db_maybe_idx_format (v, s, type_annotate);
-  return g_string_free (s, FALSE);
-}
-
-/************** DbArrayofIdx *******************/
-#define DB_ARRAYOF_IDX_TYPESTRING "a(q)"
-#define DB_ARRAYOF_IDX_TYPEFORMAT ((const GVariantType *) DB_ARRAYOF_IDX_TYPESTRING)
+/************** DbArrayofuint16 *******************/
+#define DB_ARRAYOFUINT16_TYPESTRING "aq"
+#define DB_ARRAYOFUINT16_TYPEFORMAT ((const GVariantType *) DB_ARRAYOFUINT16_TYPESTRING)
 
 typedef struct {
  gconstpointer base;
  gsize size;
-} DbArrayofIdxRef;
+} DbArrayofuint16Ref;
 
 
-static inline DbArrayofIdxRef
-db_arrayof_idx_from_gvariant (GVariant *v)
+static inline DbArrayofuint16Ref
+db_arrayofuint16_from_gvariant (GVariant *v)
 {
-  g_assert (g_variant_type_equal (g_variant_get_type (v), DB_ARRAYOF_IDX_TYPESTRING));
-  return (DbArrayofIdxRef) { g_variant_get_data (v), g_variant_get_size (v) };
+  g_assert (g_variant_type_equal (g_variant_get_type (v), DB_ARRAYOFUINT16_TYPESTRING));
+  return (DbArrayofuint16Ref) { g_variant_get_data (v), g_variant_get_size (v) };
 }
 
-static inline DbArrayofIdxRef
-db_arrayof_idx_from_bytes (GBytes *b)
+static inline DbArrayofuint16Ref
+db_arrayofuint16_from_bytes (GBytes *b)
 {
-  return (DbArrayofIdxRef) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
+  return (DbArrayofuint16Ref) { g_bytes_get_data (b, NULL), g_bytes_get_size (b) };
 }
 
-static inline DbArrayofIdxRef
-db_arrayof_idx_from_data (gconstpointer data, gsize size)
+static inline DbArrayofuint16Ref
+db_arrayofuint16_from_data (gconstpointer data, gsize size)
 {
-  return (DbArrayofIdxRef) { data, size };
+  return (DbArrayofuint16Ref) { data, size };
 }
 
 static inline GVariant *
-db_arrayof_idx_dup_to_gvariant (DbArrayofIdxRef v)
+db_arrayofuint16_dup_to_gvariant (DbArrayofuint16Ref v)
 {
-  return g_variant_new_from_data (DB_ARRAYOF_IDX_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, 
g_free, NULL);
+  return g_variant_new_from_data (DB_ARRAYOFUINT16_TYPEFORMAT, g_memdup (v.base, v.size), v.size, TRUE, 
g_free, NULL);
 }
 
 static inline GVariant *
-db_arrayof_idx_to_gvariant (DbArrayofIdxRef v,
+db_arrayofuint16_to_gvariant (DbArrayofuint16Ref v,
                              GDestroyNotify      notify,
                              gpointer            user_data)
 {
-  return g_variant_new_from_data (DB_ARRAYOF_IDX_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
+  return g_variant_new_from_data (DB_ARRAYOFUINT16_TYPEFORMAT, v.base, v.size, TRUE, notify, user_data);
 }
 
 static inline GVariant *
-db_arrayof_idx_to_owned_gvariant (DbArrayofIdxRef v, GVariant *base)
+db_arrayofuint16_to_owned_gvariant (DbArrayofuint16Ref v, GVariant *base)
 {
-  return db_arrayof_idx_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
+  return db_arrayofuint16_to_gvariant (v, (GDestroyNotify)g_variant_unref, g_variant_ref (base));
 }
 
 static inline GVariant *
-db_arrayof_idx_peek_as_gvariant (DbArrayofIdxRef v)
+db_arrayofuint16_peek_as_gvariant (DbArrayofuint16Ref v)
 {
-  return g_variant_new_from_data (DB_ARRAYOF_IDX_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
+  return g_variant_new_from_data (DB_ARRAYOFUINT16_TYPEFORMAT, v.base, v.size, TRUE, NULL, NULL);
 }
 
-static inline DbArrayofIdxRef
-db_arrayof_idx_from_variant (DbVariantRef v)
+static inline DbArrayofuint16Ref
+db_arrayofuint16_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
-  g_assert (g_variant_type_equal(type, DB_ARRAYOF_IDX_TYPESTRING));
-  return db_arrayof_idx_from_data (child.base, child.size);
+  DbRef child = Db_variant_get_child (v, &type);
+  g_assert (g_variant_type_equal(type, DB_ARRAYOFUINT16_TYPESTRING));
+  return db_arrayofuint16_from_data (child.base, child.size);
 }
 
 static inline gsize
-db_arrayof_idx_get_length (DbArrayofIdxRef v)
+db_arrayofuint16_get_length (DbArrayofuint16Ref v)
 {
   gsize length = v.size / 2;
   return length;
 }
 
-static inline DbIdxRef
-db_arrayof_idx_get_at (DbArrayofIdxRef v, gsize index)
+static inline guint16
+db_arrayofuint16_get_at (DbArrayofuint16Ref v, gsize index)
 {
-  return (DbIdxRef) { G_STRUCT_MEMBER_P(v.base, index * 2), 2};
+  return (guint16)G_STRUCT_MEMBER(guint16, v.base, index * 2);
 }
 
-static inline const DbIdx *
-db_arrayof_idx_peek (DbArrayofIdxRef v)
+static inline const guint16 *
+db_arrayofuint16_peek (DbArrayofuint16Ref v)
 {
-  return (const DbIdx *)v.base;
+  return (const guint16 *)v.base;
 }
 
 static inline GString *
-db_arrayof_idx_format (DbArrayofIdxRef v, GString *s, gboolean type_annotate)
+db_arrayofuint16_format (DbArrayofuint16Ref v, GString *s, gboolean type_annotate)
 {
-  gsize len = db_arrayof_idx_get_length (v);
+  gsize len = db_arrayofuint16_get_length (v);
   gsize i;
   if (len == 0 && type_annotate)
-    g_string_append_printf (s, "@%s ", DB_ARRAYOF_IDX_TYPESTRING);
+    g_string_append_printf (s, "@%s ", DB_ARRAYOFUINT16_TYPESTRING);
   g_string_append_c (s, '[');
   for (i = 0; i < len; i++)
     {
       if (i != 0)
         g_string_append (s, ", ");
-      db_idx_format (db_arrayof_idx_get_at (v, i), s, ((i == 0) ? type_annotate : FALSE));
+      g_string_append_printf (s, "%s%"G_GUINT16_FORMAT"", ((i == 0) ? type_annotate : FALSE) ? "uint16 " : 
"", db_arrayofuint16_get_at (v, i));
     }
   g_string_append_c (s, ']');
   return s;
 }
 
 static inline char *
-db_arrayof_idx_print (DbArrayofIdxRef v, gboolean type_annotate)
+db_arrayofuint16_print (DbArrayofuint16Ref v, gboolean type_annotate)
 {
   GString *s = g_string_new ("");
-  db_arrayof_idx_format (v, s, type_annotate);
+  db_arrayofuint16_format (v, s, type_annotate);
   return g_string_free (s, FALSE);
 }
 
 /************** DbLocation *******************/
-#define DB_LOCATION_TYPESTRING "((ss)ssm(dd)ssm(q)ym(q)(q)a(q)a(q))"
+#define DB_LOCATION_TYPESTRING "((ss)ss(dd)ssqyqqaqaq)"
 #define DB_LOCATION_TYPEFORMAT ((const GVariantType *) DB_LOCATION_TYPESTRING)
 
 typedef struct {
@@ -1331,7 +1031,7 @@ static inline DbLocationRef
 db_location_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_LOCATION_TYPESTRING));
   return db_location_from_data (child.base, child.size);
 }
@@ -1341,7 +1041,7 @@ db_location_from_variant (DbVariantRef v)
 static inline DbI18nRef
 db_location_get_name (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   guint offset = ((0) & (~(gsize)0)) + 0;
   gsize start = offset;
   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
@@ -1355,7 +1055,7 @@ db_location_get_name (DbLocationRef v)
 static inline const char *
 db_location_get_forecast_zone (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
   const char *base = (const char *)v.base;
@@ -1372,7 +1072,7 @@ db_location_get_forecast_zone (DbLocationRef v)
 static inline const char *
 db_location_get_radar (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 1);
   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
   const char *base = (const char *)v.base;
@@ -1386,17 +1086,19 @@ db_location_get_radar (DbLocationRef v)
 
 #define DB_LOCATION_INDEXOF_COORDINATES 3
 
-static inline DbMaybeCoordinateRef
+static inline DbCoordinateRef
 db_location_get_coordinates (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 2);
   guint offset = ((last_end + 7) & (~(gsize)7)) + 0;
-  gsize start = offset;
-  gsize end = DB_REF_READ_FRAME_OFFSET(v, 3);
-  g_assert (start <= end);
-  g_assert (end <= v.size);
-  return (DbMaybeCoordinateRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
+  g_assert (offset + 16 < v.size);
+  return (DbCoordinateRef) { G_STRUCT_MEMBER_P(v.base, offset), 16 };
+}
+
+static inline const DbCoordinate *
+db_location_peek_coordinates (DbLocationRef v) {
+  return (DbCoordinate *)db_location_get_coordinates (v).base;
 }
 
 #define DB_LOCATION_INDEXOF_COUNTRY_CODE 4
@@ -1404,12 +1106,12 @@ db_location_get_coordinates (DbLocationRef v)
 static inline const char *
 db_location_get_country_code (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
-  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 3);
-  guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
+  guint offset_size = Db_ref_get_offset_size (v.size);
+  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 2);
+  guint offset = ((last_end + 7) & (~(gsize)7)) + 16;
   const char *base = (const char *)v.base;
   gsize start = offset;
-  G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 4);
+  G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 3);
   g_assert (start <= end);
   g_assert (end <= v.size);
   g_assert (base[end-1] == 0);
@@ -1421,12 +1123,12 @@ db_location_get_country_code (DbLocationRef v)
 static inline const char *
 db_location_get_metar_code (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
-  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
+  guint offset_size = Db_ref_get_offset_size (v.size);
+  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 3);
   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
   const char *base = (const char *)v.base;
   gsize start = offset;
-  G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 5);
+  G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 4);
   g_assert (start <= end);
   g_assert (end <= v.size);
   g_assert (base[end-1] == 0);
@@ -1435,17 +1137,14 @@ db_location_get_metar_code (DbLocationRef v)
 
 #define DB_LOCATION_INDEXOF_TZ_HINT 6
 
-static inline DbMaybeIdxRef
+static inline guint16
 db_location_get_tz_hint (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
-  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 5);
+  guint offset_size = Db_ref_get_offset_size (v.size);
+  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
   guint offset = ((last_end + 1) & (~(gsize)1)) + 0;
-  gsize start = offset;
-  gsize end = DB_REF_READ_FRAME_OFFSET(v, 6);
-  g_assert (start <= end);
-  g_assert (end <= v.size);
-  return (DbMaybeIdxRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
+  g_assert (offset + 2 < v.size);
+  return (guint16)G_STRUCT_MEMBER(guint16, v.base, offset);
 }
 
 #define DB_LOCATION_INDEXOF_LEVEL 7
@@ -1453,89 +1152,81 @@ db_location_get_tz_hint (DbLocationRef v)
 static inline guint8
 db_location_get_level (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
-  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 6);
-  guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
+  guint offset_size = Db_ref_get_offset_size (v.size);
+  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
+  guint offset = ((last_end + 1) & (~(gsize)1)) + 2;
   g_assert (offset + 1 < v.size);
   return (guint8)G_STRUCT_MEMBER(guint8, v.base, offset);
 }
 
 #define DB_LOCATION_INDEXOF_NEAREST 8
 
-static inline DbMaybeIdxRef
+static inline guint16
 db_location_get_nearest (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
-  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 6);
-  guint offset = ((last_end + 2) & (~(gsize)1)) + 0;
-  gsize start = offset;
-  gsize end = DB_REF_READ_FRAME_OFFSET(v, 7);
-  g_assert (start <= end);
-  g_assert (end <= v.size);
-  return (DbMaybeIdxRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
+  guint offset_size = Db_ref_get_offset_size (v.size);
+  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
+  guint offset = ((last_end + 1) & (~(gsize)1)) + 4;
+  g_assert (offset + 2 < v.size);
+  return (guint16)G_STRUCT_MEMBER(guint16, v.base, offset);
 }
 
 #define DB_LOCATION_INDEXOF_PARENT 9
 
-static inline DbIdxRef
+static inline guint16
 db_location_get_parent (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
-  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 7);
-  guint offset = ((last_end + 1) & (~(gsize)1)) + 0;
+  guint offset_size = Db_ref_get_offset_size (v.size);
+  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
+  guint offset = ((last_end + 1) & (~(gsize)1)) + 6;
   g_assert (offset + 2 < v.size);
-  return (DbIdxRef) { G_STRUCT_MEMBER_P(v.base, offset), 2 };
-}
-
-static inline const DbIdx *
-db_location_peek_parent (DbLocationRef v) {
-  return (DbIdx *)db_location_get_parent (v).base;
+  return (guint16)G_STRUCT_MEMBER(guint16, v.base, offset);
 }
 
 #define DB_LOCATION_INDEXOF_CHILDREN 10
 
-static inline DbArrayofIdxRef
+static inline DbArrayofuint16Ref
 db_location_get_children (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
-  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 7);
-  guint offset = ((last_end + 1) & (~(gsize)1)) + 2;
+  guint offset_size = Db_ref_get_offset_size (v.size);
+  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 4);
+  guint offset = ((last_end + 1) & (~(gsize)1)) + 8;
   gsize start = offset;
-  gsize end = DB_REF_READ_FRAME_OFFSET(v, 8);
+  gsize end = DB_REF_READ_FRAME_OFFSET(v, 5);
   g_assert (start <= end);
   g_assert (end <= v.size);
-  return (DbArrayofIdxRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
+  return (DbArrayofuint16Ref) { G_STRUCT_MEMBER_P(v.base, start), end - start };
 }
 
-static inline const DbIdx *
+static inline const guint16 *
 db_location_peek_children (DbLocationRef v, gsize *len) {
-  DbArrayofIdxRef a = db_location_get_children (v);
+  DbArrayofuint16Ref a = db_location_get_children (v);
   if (len != NULL)
-    *len = db_arrayof_idx_get_length (a);
-  return (const DbIdx *)a.base;
+    *len = db_arrayofuint16_get_length (a);
+  return (const guint16 *)a.base;
 }
 
 #define DB_LOCATION_INDEXOF_TIMEZONES 11
 
-static inline DbArrayofIdxRef
+static inline DbArrayofuint16Ref
 db_location_get_timezones (DbLocationRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
-  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 8);
+  guint offset_size = Db_ref_get_offset_size (v.size);
+  gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 5);
   guint offset = ((last_end + 1) & (~(gsize)1)) + 0;
   gsize start = offset;
-  gsize end = v.size - offset_size * 9;
+  gsize end = v.size - offset_size * 6;
   g_assert (start <= end);
   g_assert (end <= v.size);
-  return (DbArrayofIdxRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
+  return (DbArrayofuint16Ref) { G_STRUCT_MEMBER_P(v.base, start), end - start };
 }
 
-static inline const DbIdx *
+static inline const guint16 *
 db_location_peek_timezones (DbLocationRef v, gsize *len) {
-  DbArrayofIdxRef a = db_location_get_timezones (v);
+  DbArrayofuint16Ref a = db_location_get_timezones (v);
   if (len != NULL)
-    *len = db_arrayof_idx_get_length (a);
-  return (const DbIdx *)a.base;
+    *len = db_arrayofuint16_get_length (a);
+  return (const guint16 *)a.base;
 }
 
 static inline GString *
@@ -1544,28 +1235,28 @@ db_location_format (DbLocationRef v, GString *s, gboolean type_annotate)
   g_string_append (s, "(");
   db_i18n_format (db_location_get_name (v), s, type_annotate);
   g_string_append (s, ", ");
-  __db_gstring_append_string (s, db_location_get_forecast_zone (v));
-  g_string_append (s, ", ");
-  __db_gstring_append_string (s, db_location_get_radar (v));
+  __Db_gstring_append_string (s, db_location_get_forecast_zone (v));
   g_string_append (s, ", ");
-  db_maybe_coordinate_format (db_location_get_coordinates (v), s, type_annotate);
+  __Db_gstring_append_string (s, db_location_get_radar (v));
   g_string_append (s, ", ");
-  __db_gstring_append_string (s, db_location_get_country_code (v));
+  db_coordinate_format (db_location_get_coordinates (v), s, type_annotate);
   g_string_append (s, ", ");
-  __db_gstring_append_string (s, db_location_get_metar_code (v));
+  __Db_gstring_append_string (s, db_location_get_country_code (v));
   g_string_append (s, ", ");
-  db_maybe_idx_format (db_location_get_tz_hint (v), s, type_annotate);
+  __Db_gstring_append_string (s, db_location_get_metar_code (v));
   g_string_append (s, ", ");
-  g_string_append_printf (s, "%s0x%02x, ",
+  g_string_append_printf (s, "%s%"G_GUINT16_FORMAT", %s0x%02x, %s%"G_GUINT16_FORMAT", %s%"G_GUINT16_FORMAT", 
",
+                   type_annotate ? "uint16 " : "",
+                   db_location_get_tz_hint (v),
                    type_annotate ? "byte " : "",
-                   db_location_get_level (v));
-  db_maybe_idx_format (db_location_get_nearest (v), s, type_annotate);
-  g_string_append (s, ", ");
-  db_idx_format (db_location_get_parent (v), s, type_annotate);
-  g_string_append (s, ", ");
-  db_arrayof_idx_format (db_location_get_children (v), s, type_annotate);
+                   db_location_get_level (v),
+                   type_annotate ? "uint16 " : "",
+                   db_location_get_nearest (v),
+                   type_annotate ? "uint16 " : "",
+                   db_location_get_parent (v));
+  db_arrayofuint16_format (db_location_get_children (v), s, type_annotate);
   g_string_append (s, ", ");
-  db_arrayof_idx_format (db_location_get_timezones (v), s, type_annotate);
+  db_arrayofuint16_format (db_location_get_timezones (v), s, type_annotate);
   g_string_append (s, ")");
   return s;
 }
@@ -1579,7 +1270,7 @@ db_location_print (DbLocationRef v, gboolean type_annotate)
 }
 
 /************** DbWorldLocByCountry *******************/
-#define DB_WORLD_LOC_BY_COUNTRY_TYPESTRING "a{s(q)}"
+#define DB_WORLD_LOC_BY_COUNTRY_TYPESTRING "a{sq}"
 #define DB_WORLD_LOC_BY_COUNTRY_TYPEFORMAT ((const GVariantType *) DB_WORLD_LOC_BY_COUNTRY_TYPESTRING)
 
 typedef struct {
@@ -1642,7 +1333,7 @@ static inline DbWorldLocByCountryRef
 db_world_loc_by_country_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_WORLD_LOC_BY_COUNTRY_TYPESTRING));
   return db_world_loc_by_country_from_data (child.base, child.size);
 }
@@ -1653,7 +1344,7 @@ db_world_loc_by_country_get_length (DbWorldLocByCountryRef v)
 {
   if (v.size == 0)
     return 0;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize offsets_array_size;
   if (last_end > v.size)
@@ -1669,7 +1360,7 @@ static inline DbWorldLocByCountryEntryRef
 db_world_loc_by_country_get_at (DbWorldLocByCountryRef v, gsize index)
 {
   DbWorldLocByCountryEntryRef res;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize len = (v.size - last_end) / offset_size;
   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 2) : 0;
@@ -1683,7 +1374,7 @@ db_world_loc_by_country_get_at (DbWorldLocByCountryRef v, gsize index)
 static inline const char *
 db_world_loc_by_country_entry_get_key (DbWorldLocByCountryEntryRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
   const char *base = (const char *)v.base;
   g_assert (end < v.size);
@@ -1691,21 +1382,21 @@ db_world_loc_by_country_entry_get_key (DbWorldLocByCountryEntryRef v)
   return base;
 }
 
-static inline DbIdxRef
+static inline guint16
 db_world_loc_by_country_entry_get_value (DbWorldLocByCountryEntryRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize offset = DB_REF_ALIGN(end, 2);
   g_assert (offset == v.size - offset_size - 2);
-  return (DbIdxRef) { (char *)v.base + offset, (v.size - offset_size) - offset };
+  return (guint16)*((guint16 *)((char *)v.base + offset));
 }
 
 static inline gboolean
-db_world_loc_by_country_lookup (DbWorldLocByCountryRef v, const char * key, gsize *index_out, DbIdxRef *out)
+db_world_loc_by_country_lookup (DbWorldLocByCountryRef v, const char * key, gsize *index_out, guint16 *out)
 {
   const char * canonical_key = key;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   if (last_end > v.size)
     return FALSE;
@@ -1757,9 +1448,9 @@ db_world_loc_by_country_format (DbWorldLocByCountryRef v, GString *s, gboolean t
       DbWorldLocByCountryEntryRef entry = db_world_loc_by_country_get_at (v, i);
       if (i != 0)
         g_string_append (s, ", ");
-      __db_gstring_append_string (s, db_world_loc_by_country_entry_get_key (entry));
+      __Db_gstring_append_string (s, db_world_loc_by_country_entry_get_key (entry));
       g_string_append (s, ": ");
-      db_idx_format (db_world_loc_by_country_entry_get_value (entry), s, type_annotate);
+      g_string_append_printf (s, "%s%"G_GUINT16_FORMAT"", type_annotate ? "uint16 " : "", 
db_world_loc_by_country_entry_get_value (entry));
     }
   g_string_append_c (s, '}');
   return s;
@@ -1774,7 +1465,7 @@ db_world_loc_by_country_print (DbWorldLocByCountryRef v, gboolean type_annotate)
 }
 
 /************** DbWorldLocByMetar *******************/
-#define DB_WORLD_LOC_BY_METAR_TYPESTRING "a{s(q)}"
+#define DB_WORLD_LOC_BY_METAR_TYPESTRING "a{sq}"
 #define DB_WORLD_LOC_BY_METAR_TYPEFORMAT ((const GVariantType *) DB_WORLD_LOC_BY_METAR_TYPESTRING)
 
 typedef struct {
@@ -1837,7 +1528,7 @@ static inline DbWorldLocByMetarRef
 db_world_loc_by_metar_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_WORLD_LOC_BY_METAR_TYPESTRING));
   return db_world_loc_by_metar_from_data (child.base, child.size);
 }
@@ -1848,7 +1539,7 @@ db_world_loc_by_metar_get_length (DbWorldLocByMetarRef v)
 {
   if (v.size == 0)
     return 0;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize offsets_array_size;
   if (last_end > v.size)
@@ -1864,7 +1555,7 @@ static inline DbWorldLocByMetarEntryRef
 db_world_loc_by_metar_get_at (DbWorldLocByMetarRef v, gsize index)
 {
   DbWorldLocByMetarEntryRef res;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize len = (v.size - last_end) / offset_size;
   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 2) : 0;
@@ -1878,7 +1569,7 @@ db_world_loc_by_metar_get_at (DbWorldLocByMetarRef v, gsize index)
 static inline const char *
 db_world_loc_by_metar_entry_get_key (DbWorldLocByMetarEntryRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
   const char *base = (const char *)v.base;
   g_assert (end < v.size);
@@ -1886,21 +1577,21 @@ db_world_loc_by_metar_entry_get_key (DbWorldLocByMetarEntryRef v)
   return base;
 }
 
-static inline DbIdxRef
+static inline guint16
 db_world_loc_by_metar_entry_get_value (DbWorldLocByMetarEntryRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize offset = DB_REF_ALIGN(end, 2);
   g_assert (offset == v.size - offset_size - 2);
-  return (DbIdxRef) { (char *)v.base + offset, (v.size - offset_size) - offset };
+  return (guint16)*((guint16 *)((char *)v.base + offset));
 }
 
 static inline gboolean
-db_world_loc_by_metar_lookup (DbWorldLocByMetarRef v, const char * key, gsize *index_out, DbIdxRef *out)
+db_world_loc_by_metar_lookup (DbWorldLocByMetarRef v, const char * key, gsize *index_out, guint16 *out)
 {
   const char * canonical_key = key;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   if (last_end > v.size)
     return FALSE;
@@ -1952,9 +1643,9 @@ db_world_loc_by_metar_format (DbWorldLocByMetarRef v, GString *s, gboolean type_
       DbWorldLocByMetarEntryRef entry = db_world_loc_by_metar_get_at (v, i);
       if (i != 0)
         g_string_append (s, ", ");
-      __db_gstring_append_string (s, db_world_loc_by_metar_entry_get_key (entry));
+      __Db_gstring_append_string (s, db_world_loc_by_metar_entry_get_key (entry));
       g_string_append (s, ": ");
-      db_idx_format (db_world_loc_by_metar_entry_get_value (entry), s, type_annotate);
+      g_string_append_printf (s, "%s%"G_GUINT16_FORMAT"", type_annotate ? "uint16 " : "", 
db_world_loc_by_metar_entry_get_value (entry));
     }
   g_string_append_c (s, '}');
   return s;
@@ -2032,7 +1723,7 @@ static inline DbWorldTimezonesRef
 db_world_timezones_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_WORLD_TIMEZONES_TYPESTRING));
   return db_world_timezones_from_data (child.base, child.size);
 }
@@ -2043,7 +1734,7 @@ db_world_timezones_get_length (DbWorldTimezonesRef v)
 {
   if (v.size == 0)
     return 0;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize offsets_array_size;
   if (last_end > v.size)
@@ -2059,7 +1750,7 @@ static inline DbWorldTimezonesEntryRef
 db_world_timezones_get_at (DbWorldTimezonesRef v, gsize index)
 {
   DbWorldTimezonesEntryRef res;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize len = (v.size - last_end) / offset_size;
   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 1) : 0;
@@ -2073,7 +1764,7 @@ db_world_timezones_get_at (DbWorldTimezonesRef v, gsize index)
 static inline const char *
 db_world_timezones_entry_get_key (DbWorldTimezonesEntryRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   G_GNUC_UNUSED gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
   const char *base = (const char *)v.base;
   g_assert (end < v.size);
@@ -2084,7 +1775,7 @@ db_world_timezones_entry_get_key (DbWorldTimezonesEntryRef v)
 static inline DbTimezoneRef
 db_world_timezones_entry_get_value (DbWorldTimezonesEntryRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize offset = DB_REF_ALIGN(end, 1);
   g_assert (offset <= v.size);
@@ -2095,7 +1786,7 @@ static inline gboolean
 db_world_timezones_lookup (DbWorldTimezonesRef v, const char * key, gsize *index_out, DbTimezoneRef *out)
 {
   const char * canonical_key = key;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   if (last_end > v.size)
     return FALSE;
@@ -2147,7 +1838,7 @@ db_world_timezones_format (DbWorldTimezonesRef v, GString *s, gboolean type_anno
       DbWorldTimezonesEntryRef entry = db_world_timezones_get_at (v, i);
       if (i != 0)
         g_string_append (s, ", ");
-      __db_gstring_append_string (s, db_world_timezones_entry_get_key (entry));
+      __Db_gstring_append_string (s, db_world_timezones_entry_get_key (entry));
       g_string_append (s, ": ");
       db_timezone_format (db_world_timezones_entry_get_value (entry), s, type_annotate);
     }
@@ -2164,7 +1855,7 @@ db_world_timezones_print (DbWorldTimezonesRef v, gboolean type_annotate)
 }
 
 /************** DbArrayofLocation *******************/
-#define DB_ARRAYOF_LOCATION_TYPESTRING "a((ss)ssm(dd)ssm(q)ym(q)(q)a(q)a(q))"
+#define DB_ARRAYOF_LOCATION_TYPESTRING "a((ss)ss(dd)ssqyqqaqaq)"
 #define DB_ARRAYOF_LOCATION_TYPEFORMAT ((const GVariantType *) DB_ARRAYOF_LOCATION_TYPESTRING)
 
 typedef struct {
@@ -2222,7 +1913,7 @@ static inline DbArrayofLocationRef
 db_arrayof_location_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_ARRAYOF_LOCATION_TYPESTRING));
   return db_arrayof_location_from_data (child.base, child.size);
 }
@@ -2232,7 +1923,7 @@ db_arrayof_location_get_length (DbArrayofLocationRef v)
 {
   if (v.size == 0)
     return 0;
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize offsets_array_size;
   if (last_end > v.size)
@@ -2247,7 +1938,7 @@ db_arrayof_location_get_length (DbArrayofLocationRef v)
 static inline DbLocationRef
 db_arrayof_location_get_at (DbArrayofLocationRef v, gsize index)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   gsize len = (v.size - last_end) / offset_size;
   gsize start = (index > 0) ? DB_REF_ALIGN(DB_REF_READ_FRAME_OFFSET(v, len - index), 8) : 0;
@@ -2284,7 +1975,7 @@ db_arrayof_location_print (DbArrayofLocationRef v, gboolean type_annotate)
 }
 
 /************** DbWorld *******************/
-#define DB_WORLD_TYPESTRING "(a{s(q)}a{s(q)}a{s((ss)as)}a((ss)ssm(dd)ssm(q)ym(q)(q)a(q)a(q)))"
+#define DB_WORLD_TYPESTRING "(a{sq}a{sq}a{s((ss)as)}a((ss)ss(dd)ssqyqqaqaq))"
 #define DB_WORLD_TYPEFORMAT ((const GVariantType *) DB_WORLD_TYPESTRING)
 
 typedef struct {
@@ -2342,7 +2033,7 @@ static inline DbWorldRef
 db_world_from_variant (DbVariantRef v)
 {
   const GVariantType  *type;
-  DbRef child = db_variant_get_child (v, &type);
+  DbRef child = Db_variant_get_child (v, &type);
   g_assert (g_variant_type_equal(type, DB_WORLD_TYPESTRING));
   return db_world_from_data (child.base, child.size);
 }
@@ -2352,7 +2043,7 @@ db_world_from_variant (DbVariantRef v)
 static inline DbWorldLocByCountryRef
 db_world_get_loc_by_country (DbWorldRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   guint offset = ((1) & (~(gsize)1)) + 0;
   gsize start = offset;
   gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
@@ -2366,7 +2057,7 @@ db_world_get_loc_by_country (DbWorldRef v)
 static inline DbWorldLocByMetarRef
 db_world_get_loc_by_metar (DbWorldRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 0);
   guint offset = ((last_end + 1) & (~(gsize)1)) + 0;
   gsize start = offset;
@@ -2381,7 +2072,7 @@ db_world_get_loc_by_metar (DbWorldRef v)
 static inline DbWorldTimezonesRef
 db_world_get_timezones (DbWorldRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 1);
   guint offset = ((last_end + 0) & (~(gsize)0)) + 0;
   gsize start = offset;
@@ -2396,7 +2087,7 @@ db_world_get_timezones (DbWorldRef v)
 static inline DbArrayofLocationRef
 db_world_get_locations (DbWorldRef v)
 {
-  guint offset_size = db_ref_get_offset_size (v.size);
+  guint offset_size = Db_ref_get_offset_size (v.size);
   gsize last_end = DB_REF_READ_FRAME_OFFSET(v, 2);
   guint offset = ((last_end + 7) & (~(gsize)7)) + 0;
   gsize start = offset;
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index bf9e174..160bb76 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -207,7 +207,7 @@ add_nearest_weather_station (GWeatherLocation *location)
 
 static GWeatherLocation *
 location_ref_for_idx (GWeatherDb       *db,
-                     guint             idx,
+                     guint16           idx,
                      GWeatherLocation *nearest_of)
 {
     GWeatherLocation *loc;
@@ -250,29 +250,22 @@ location_ref_for_idx (GWeatherDb       *db,
     }
 
     loc->country_code = g_strdup (EMPTY_TO_NULL (db_location_get_country_code (ref)));
-    if (db_maybe_idx_has_value (db_location_get_tz_hint (ref)))
-        loc->tz_hint_idx = db_idx_get_idx (db_maybe_idx_get_value (db_location_get_tz_hint (ref)));
-    else
-       loc->tz_hint_idx = -1;
+    loc->tz_hint_idx = db_location_get_tz_hint (ref);
 
     loc->station_code = g_strdup (EMPTY_TO_NULL (db_location_get_metar_code (ref)));
 
-    loc->latlon_valid = db_maybe_coordinate_has_value (db_location_get_coordinates (ref));
-    if (loc->latlon_valid) {
-       loc->latitude = db_coordinate_get_lat (db_maybe_coordinate_get_value (db_location_get_coordinates 
(ref)));
-       loc->longitude = db_coordinate_get_lon (db_maybe_coordinate_get_value (db_location_get_coordinates 
(ref)));
-    }
+    loc->latitude = db_coordinate_get_lat (db_location_get_coordinates (ref));
+    loc->longitude = db_coordinate_get_lon (db_location_get_coordinates (ref));
+    loc->latlon_valid = isfinite(loc->latitude) && isfinite(loc->longitude);
 
     loc->forecast_zone = g_strdup (EMPTY_TO_NULL (db_location_get_forecast_zone (ref)));
     loc->radar = g_strdup (EMPTY_TO_NULL (db_location_get_radar (ref)));
 
     /* Fill in the magic nearest child if we need to and should. */
     if (!g_getenv ("LIBGWEATHER_LOCATIONS_NO_NEAREST") &&
-        db_maybe_idx_has_value (db_location_get_nearest (ref))) {
-       guint nearest_idx = db_idx_get_idx (db_maybe_idx_get_value (db_location_get_nearest (ref)));
-
+        IDX_VALID (db_location_get_nearest (ref))) {
        loc->children = g_new0 (GWeatherLocation*, 2);
-       loc->children[0] = location_ref_for_idx (db, nearest_idx, loc);
+       loc->children[0] = location_ref_for_idx (db, db_location_get_nearest (ref), loc);
     }
 
     /* Note, we used to sort locations by distance (for cities) and name;
@@ -628,9 +621,9 @@ gweather_location_ref_parent (GWeatherLocation *loc)
     if (!loc->db || loc->db_idx == 0)
        return NULL;
 
-    /* Not self-referencing */
-    idx = db_idx_get_idx (db_location_get_parent (loc->ref));
-    g_assert (idx != loc->db_idx);
+    /* Not self-referencing and not invalid */
+    idx = db_location_get_parent (loc->ref);
+    g_assert (IDX_VALID(idx) && idx != loc->db_idx);
     return location_ref_for_idx (loc->db, idx, NULL);
 }
 
@@ -672,7 +665,7 @@ GWeatherLocation **
 gweather_location_get_children (GWeatherLocation *loc)
 {
     static GWeatherLocation *no_children = NULL;
-    DbArrayofIdxRef children_ref;
+    DbArrayofuint16Ref children_ref;
     gsize length;
     gsize i;
 
@@ -685,14 +678,14 @@ gweather_location_get_children (GWeatherLocation *loc)
        return &no_children;
 
     children_ref = db_location_get_children (loc->ref);
-    length = db_arrayof_idx_get_length (children_ref);
+    length = db_arrayofuint16_get_length (children_ref);
     if (length == 0)
        return &no_children;
 
     loc->children = g_new0 (GWeatherLocation*, length + 1);
     for (i = 0; i < length; i++)
        loc->children[i] = location_ref_for_idx (loc->db,
-                                                db_idx_get_idx (db_arrayof_idx_get_at (children_ref, i)),
+                                                db_arrayofuint16_get_at (children_ref, i),
                                                 NULL);
 
     return loc->children;
@@ -724,19 +717,19 @@ foreach_city (GWeatherLocation  *loc,
         for (i = 0; loc->children[i]; i++)
             foreach_city (loc->children[i], callback, user_data, country_code, func, user_data_func);
     } else if (loc->db) {
-       DbArrayofIdxRef children_ref;
+       DbArrayofuint16Ref children_ref;
        gsize length;
        gsize i;
        /* Also try non-cached iteration */
 
        children_ref = db_location_get_children (loc->ref);
-       length = db_arrayof_idx_get_length (children_ref);
+       length = db_arrayofuint16_get_length (children_ref);
 
        for (i = 0; i < length; i++) {
            g_autoptr(GWeatherLocation) child = NULL;
 
            child = location_ref_for_idx (loc->db,
-                                         db_idx_get_idx (db_arrayof_idx_get_at (children_ref, i)),
+                                         db_arrayofuint16_get_at (children_ref, i),
                                          NULL);
 
            foreach_city (child, callback, user_data, country_code, func, user_data_func);
@@ -1128,7 +1121,7 @@ gweather_location_get_timezone (GWeatherLocation *loc)
        return loc->timezone;
 
     s = gweather_location_ref (loc);
-    while (s && s->tz_hint_idx < 0) {
+    while (s && !IDX_VALID (s->tz_hint_idx)) {
        GWeatherLocation *parent = gweather_location_ref_parent (s);
        gweather_location_unref (s);
        s = parent;
@@ -1163,7 +1156,7 @@ gweather_location_get_timezone_str (GWeatherLocation *loc)
        return gweather_timezone_get_tzid (loc->timezone);
 
     s = gweather_location_ref (loc);
-    while (s && s->tz_hint_idx < 0) {
+    while (s && !IDX_VALID(s->tz_hint_idx)) {
        GWeatherLocation *parent = gweather_location_ref_parent (s);
        gweather_location_unref (s);
        s = parent;
@@ -1313,7 +1306,7 @@ _gweather_location_update_weather_location (GWeatherLocation *gloc,
                                            WeatherLocation  *loc)
 {
     const char *code = NULL, *zone = NULL, *radar = NULL, *tz_hint = NULL, *country = NULL;
-    gint tz_hint_idx = -1;
+    gint tz_hint_idx = INVALID_IDX;
     gboolean latlon_valid = FALSE;
     gdouble lat = DBL_MAX, lon = DBL_MAX;
     GWeatherLocation *l;
@@ -1324,7 +1317,7 @@ _gweather_location_update_weather_location (GWeatherLocation *gloc,
     else
        l = gloc;
 
-    while (l && (!db || !code || !zone || !radar || tz_hint_idx < 0 || !latlon_valid || !country)) {
+    while (l && (!db || !code || !zone || !radar || !IDX_VALID(tz_hint_idx) || !latlon_valid || !country)) {
        if (!db && l->db)
            db = l->db;
        if (!code && l->station_code)
@@ -1333,7 +1326,7 @@ _gweather_location_update_weather_location (GWeatherLocation *gloc,
            zone = l->forecast_zone;
        if (!radar && l->radar)
            radar = l->radar;
-       if (tz_hint_idx < 0)
+       if (!IDX_VALID(tz_hint_idx))
            tz_hint_idx = l->tz_hint_idx;
        if (!country && l->country_code)
            country = l->country_code;
@@ -1350,7 +1343,7 @@ _gweather_location_update_weather_location (GWeatherLocation *gloc,
     loc->zone = g_strdup (zone);
     loc->radar = g_strdup (radar);
     loc->country_code = g_strdup (country);
-    if (tz_hint_idx >= 0)
+    if (IDX_VALID(tz_hint_idx))
         loc->tz_hint = g_strdup (db_world_timezones_entry_get_key (db_world_timezones_get_at 
(db->timezones_ref, tz_hint_idx)));
 
     loc->latlon_valid = latlon_valid;
@@ -1378,16 +1371,16 @@ gweather_location_ref_from_station_code (GWeatherLocation *world,
                                         const gchar      *station_code)
 {
        DbWorldLocByMetarRef loc_by_metar;
-       DbIdxRef idx_ref;
+       guint16 idx;
 
        if (!world->db)
                return NULL;
 
        loc_by_metar = db_world_get_loc_by_metar (world->db->world);
-       if (!db_world_loc_by_metar_lookup (loc_by_metar, station_code, NULL, &idx_ref))
+       if (!db_world_loc_by_metar_lookup (loc_by_metar, station_code, NULL, &idx))
                return NULL;
 
-       return location_ref_for_idx (world->db, db_idx_get_idx (idx_ref), NULL);
+       return location_ref_for_idx (world->db, idx, NULL);
 }
 
 /**
@@ -1429,16 +1422,16 @@ gweather_location_find_by_country_code (GWeatherLocation *world,
                                         const gchar      *country_code)
 {
        DbWorldLocByCountryRef loc_by_country;
-       DbIdxRef idx_ref;
+       guint16 idx;
 
        if (!world->db)
                return NULL;
 
        loc_by_country = db_world_get_loc_by_country (world->db->world);
-       if (!db_world_loc_by_country_lookup (loc_by_country, country_code, NULL, &idx_ref))
+       if (!db_world_loc_by_country_lookup (loc_by_country, country_code, NULL, &idx))
                return NULL;
 
-       return location_sink_keep_alive (location_ref_for_idx (world->db, db_idx_get_idx (idx_ref), NULL));
+       return location_sink_keep_alive (location_ref_for_idx (world->db, idx, NULL));
 }
 
 /**
@@ -1562,7 +1555,7 @@ _gweather_location_new_detached (GWeatherLocation *nearest_station,
        self->local_sort_name = g_strdup (nearest_station->local_sort_name);
     }
 
-    self->tz_hint_idx = -1;
+    self->tz_hint_idx = INVALID_IDX;
     self->parent = nearest_station;
     self->children = NULL;
 
@@ -1642,7 +1635,7 @@ gweather_location_common_deserialize (GWeatherLocation *world,
            continue;
 
        /* Be lazy and allocate the location */
-       ws = location_ref_for_idx (world->db, db_idx_get_idx (db_world_loc_by_metar_entry_get_value 
(db_world_loc_by_metar_get_at (loc_by_metar, i))), NULL);
+       ws = location_ref_for_idx (world->db, db_world_loc_by_metar_entry_get_value 
(db_world_loc_by_metar_get_at (loc_by_metar, i)), NULL);
 
        if (!ws->latlon_valid ||
            ABS(ws->latitude - latitude) >= EPSILON ||
diff --git a/libgweather/gweather-private.h b/libgweather/gweather-private.h
index c4d6d0c..abf0083 100644
--- a/libgweather/gweather-private.h
+++ b/libgweather/gweather-private.h
@@ -41,6 +41,8 @@ DOUBLE_FROM_BE(gdouble x)
 }
 #include "gweather-db.h"
 
+#define INVALID_IDX G_MAXUINT16
+#define IDX_VALID(idx) ((idx) >= 0 && (idx) < 0xffff)
 #define EMPTY_TO_NULL(s) ((s)[0] == '\0' ? NULL : (s))
 
 void        _gweather_gettext_init (void);
diff --git a/libgweather/gweather.gv b/libgweather/gweather.gv
index 57058b6..3013399 100644
--- a/libgweather/gweather.gv
+++ b/libgweather/gweather.gv
@@ -1,8 +1,4 @@
 
-type Idx {
-   idx: bigendian uint16;
-};
-
 type I18n {
   str: string;
   msgctxt: string;
@@ -14,33 +10,33 @@ type Timezone {
 };
 
 type Coordinate {
-  lat: bigendian double;
-  lon: bigendian double;
+  lat: double;
+  lon: double;
 };
 
 type Location {
   name: I18n;
   forecast_zone: string;
   radar: string;
-  coordinates: ?Coordinate;
+  coordinates: Coordinate;
 
   country_code: string;
   metar_code: string;
-  tz_hint: ?Idx;
+  tz_hint: uint16;
 
   level: byte;
 
-  nearest: ?Idx;
+  nearest: uint16;
 
-  parent: Idx;
-  children: [] Idx;
+  parent: uint16;
+  children: [] uint16;
 
-  timezones: [] Idx;
+  timezones: [] uint16;
 };
 
 type World {
-  loc_by_country: [sorted string] Idx;
-  loc_by_metar: [sorted string] Idx;
+  loc_by_country: [sorted string] uint16;
+  loc_by_metar: [sorted string] uint16;
 
   timezones: [sorted string] Timezone;
   locations: []Location;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]