[pango/serialization-improvements: 6/16] Rename the serialize errors




commit 3ea26fbcb4d65dd0941eff77c5abe3ac443549ad
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 21 22:46:55 2021 -0500

    Rename the serialize errors
    
    They are produced by deserialization,
    so call them that.

 pango/pango-layout.h  | 39 ++++++++++++++++++++++++++-------------
 pango/serializer.c    | 41 +++++++++++++++++++++++------------------
 tests/testserialize.c | 10 +++++-----
 3 files changed, 54 insertions(+), 36 deletions(-)
---
diff --git a/pango/pango-layout.h b/pango/pango-layout.h
index 3b725adc..5e8d8784 100644
--- a/pango/pango-layout.h
+++ b/pango/pango-layout.h
@@ -351,25 +351,38 @@ GSList *         pango_layout_get_lines            (PangoLayout    *layout);
 PANGO_AVAILABLE_IN_1_16
 GSList *         pango_layout_get_lines_readonly   (PangoLayout    *layout);
 
-#define PANGO_LAYOUT_SERIALIZE_ERROR (pango_layout_serialize_error_quark ())
+PANGO_AVAILABLE_IN_1_50
+GBytes *        pango_layout_serialize             (PangoLayout    *layout);
 
-typedef enum {
-  PANGO_LAYOUT_SERIALIZE_INVALID,
-  PANGO_LAYOUT_SERIALIZE_INVALID_SYNTAX,
-  PANGO_LAYOUT_SERIALIZE_INVALID_VALUE,
-  PANGO_LAYOUT_SERIALIZE_MISSING_VALUE,
-} PangoLayoutSerializeError;
+#define PANGO_LAYOUT_DESERIALIZE_ERROR (pango_layout_deserialize_error_quark ())
 
-PANGO_AVAILABLE_IN_1_50
-GQuark          pango_layout_serialize_error_quark (void);
+/**
+ * PangoLayoutDeserializeError:
+ * @PANGO_LAYOUT_SERIALIZE_INVALID: Unspecified error
+ * @PANGO_LAYOUT_SERIALIZE_INVALID_SYNTAX: The serialized data had
+ *   the wrong structure (e.g. a member was expected to be a JSon object,
+ *   but was an array)
+ * @PANGO_LAYOUT_SERIALIZE_INVALID_VALUE: A JSon value could not be
+ *   interpreted
+ * @PANGO_LAYOUT_SERIALIZE_MISSING_VALUE: A required JSon member was
+ *   not found
+ *
+ * Errors that can be returned by [func@Pango.Layout.deserialize].
+ */
+typedef enum {
+  PANGO_LAYOUT_DESERIALIZE_INVALID,
+  PANGO_LAYOUT_DESERIALIZE_INVALID_SYNTAX,
+  PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE,
+  PANGO_LAYOUT_DESERIALIZE_MISSING_VALUE,
+} PangoLayoutDeserializeError;
 
 PANGO_AVAILABLE_IN_1_50
-GBytes *        pango_layout_serialize             (PangoLayout    *layout);
+GQuark          pango_layout_deserialize_error_quark (void);
 
 PANGO_AVAILABLE_IN_1_50
-PangoLayout *   pango_layout_deserialize           (PangoContext   *context,
-                                                    GBytes         *bytes,
-                                                    GError        **error);
+PangoLayout *   pango_layout_deserialize           (PangoContext                 *context,
+                                                    GBytes                       *bytes,
+                                                    GError                      **error);
 
 PANGO_AVAILABLE_IN_1_50
 gboolean        pango_layout_write_to_file          (PangoLayout   *layout,
diff --git a/pango/serializer.c b/pango/serializer.c
index 576e6cf6..2409afcb 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -29,7 +29,7 @@
 
 /* {{{ Error handling */
 
-G_DEFINE_QUARK(pango-layout-serialize-error-quark, pango_layout_serialize_error)
+G_DEFINE_QUARK(pango-layout-deserialize-error-quark, pango_layout_deserialize_error)
 
 /* }}} */
 /* {{{ Serialization */
@@ -368,7 +368,8 @@ json_to_attribute (JsonReader  *reader,
   if (!json_reader_is_object (reader))
     {
       g_set_error (error,
-                   PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_INVALID_SYNTAX,
+                   PANGO_LAYOUT_DESERIALIZE_ERROR,
+                   PANGO_LAYOUT_DESERIALIZE_INVALID_SYNTAX,
                    "Attribute must be a Json object");
       return NULL;
     }
@@ -387,7 +388,8 @@ json_to_attribute (JsonReader  *reader,
       if (type == -1 || type == PANGO_ATTR_INVALID)
         {
           g_set_error (error,
-                       PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_INVALID_VALUE,
+                       PANGO_LAYOUT_DESERIALIZE_ERROR,
+                       PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE,
                        "Attribute \"type\" invalid: %s",
                        json_reader_get_string_value (reader));
           return NULL;
@@ -397,7 +399,8 @@ json_to_attribute (JsonReader  *reader,
   else
     {
       g_set_error (error,
-                   PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_MISSING_VALUE,
+                   PANGO_LAYOUT_DESERIALIZE_ERROR,
+                   PANGO_LAYOUT_DESERIALIZE_MISSING_VALUE,
                    "Attribute \"type\" missing");
       json_reader_end_member (reader);
       return NULL;
@@ -406,7 +409,8 @@ json_to_attribute (JsonReader  *reader,
   if (!json_reader_read_member (reader, "value"))
     {
       g_set_error (error,
-                   PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_MISSING_VALUE,
+                   PANGO_LAYOUT_DESERIALIZE_ERROR,
+                   PANGO_LAYOUT_DESERIALIZE_MISSING_VALUE,
                    "Attribute \"value\" missing");
       json_reader_end_member (reader);
       return NULL;
@@ -556,7 +560,8 @@ json_to_attr_list (JsonReader  *reader,
   if (!json_reader_is_array (reader))
     {
       g_set_error (error,
-                   PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_INVALID_SYNTAX,
+                   PANGO_LAYOUT_DESERIALIZE_ERROR,
+                   PANGO_LAYOUT_DESERIALIZE_INVALID_SYNTAX,
                    "\"attributes\" must be a Json array");
       goto fail;
     }
@@ -600,8 +605,8 @@ json_to_tab_array (JsonReader  *reader,
       if (!json_reader_is_array (reader))
         {
           g_set_error (error,
-                       PANGO_LAYOUT_SERIALIZE_ERROR,
-                       PANGO_LAYOUT_SERIALIZE_INVALID_SYNTAX,
+                       PANGO_LAYOUT_DESERIALIZE_ERROR,
+                       PANGO_LAYOUT_DESERIALIZE_INVALID_SYNTAX,
                        "Tab \"positions\"  must be a Json array");
           goto fail;
         }
@@ -640,8 +645,8 @@ json_to_layout (PangoContext *context,
   if (!json_reader_is_object (reader))
     {
       g_set_error (error,
-                   PANGO_LAYOUT_SERIALIZE_ERROR,
-                   PANGO_LAYOUT_SERIALIZE_INVALID_SYNTAX,
+                   PANGO_LAYOUT_DESERIALIZE_ERROR,
+                   PANGO_LAYOUT_DESERIALIZE_INVALID_SYNTAX,
                    "Layout must be a Json object");
       goto fail;
     }
@@ -672,8 +677,8 @@ json_to_layout (PangoContext *context,
       if (!desc)
         {
           g_set_error (error,
-                       PANGO_LAYOUT_SERIALIZE_ERROR,
-                       PANGO_LAYOUT_SERIALIZE_INVALID_VALUE,
+                       PANGO_LAYOUT_DESERIALIZE_ERROR,
+                       PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE,
                        "Could not parse \"font\" value: %s",
                        json_reader_get_string_value (reader));
           goto fail;
@@ -721,8 +726,8 @@ json_to_layout (PangoContext *context,
       if (align == -1)
         {
           g_set_error (error,
-                       PANGO_LAYOUT_SERIALIZE_ERROR,
-                       PANGO_LAYOUT_SERIALIZE_INVALID_VALUE,
+                       PANGO_LAYOUT_DESERIALIZE_ERROR,
+                       PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE,
                        "Could not parse \"alignment\" value: %s",
                        json_reader_get_string_value (reader));
           goto fail;
@@ -742,8 +747,8 @@ json_to_layout (PangoContext *context,
       if (wrap == -1)
         {
           g_set_error (error,
-                       PANGO_LAYOUT_SERIALIZE_ERROR,
-                       PANGO_LAYOUT_SERIALIZE_INVALID_VALUE,
+                       PANGO_LAYOUT_DESERIALIZE_ERROR,
+                       PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE,
                        "Could not parse \"wrap\" value: %s",
                        json_reader_get_string_value (reader));
           goto fail;
@@ -763,8 +768,8 @@ json_to_layout (PangoContext *context,
       if (ellipsize == -1)
         {
           g_set_error (error,
-                       PANGO_LAYOUT_SERIALIZE_ERROR,
-                       PANGO_LAYOUT_SERIALIZE_INVALID_VALUE,
+                       PANGO_LAYOUT_DESERIALIZE_ERROR,
+                       PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE,
                        "Could not parse \"ellipsize\" value: %s",
                        json_reader_get_string_value (reader));
           goto fail;
diff --git a/tests/testserialize.c b/tests/testserialize.c
index 5fb7543a..b09b6ac3 100644
--- a/tests/testserialize.c
+++ b/tests/testserialize.c
@@ -257,7 +257,7 @@ test_serialize_layout_invalid (void)
       "    }\n"
       "  ]\n"
       "}",
-      PANGO_LAYOUT_SERIALIZE_INVALID_VALUE
+      PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE
     },
     {
       "{\n"
@@ -267,7 +267,7 @@ test_serialize_layout_invalid (void)
       "    }\n"
       "  ]\n"
       "}",
-      PANGO_LAYOUT_SERIALIZE_MISSING_VALUE
+      PANGO_LAYOUT_DESERIALIZE_MISSING_VALUE
     },
     {
       "{\n"
@@ -278,13 +278,13 @@ test_serialize_layout_invalid (void)
       "    }\n"
       "  ]\n"
       "}",
-      PANGO_LAYOUT_SERIALIZE_INVALID_VALUE
+      PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE
     },
     {
       "{\n"
       "  \"alignment\" : \"nonsense\"\n"
       "}",
-      PANGO_LAYOUT_SERIALIZE_INVALID_VALUE
+      PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE
     }
   };
 
@@ -301,7 +301,7 @@ test_serialize_layout_invalid (void)
        bytes = g_bytes_new_static (test[i].json, -1);
        layout = pango_layout_deserialize (context, bytes, &error);
        g_assert_null (layout);
-       g_assert_error (error, PANGO_LAYOUT_SERIALIZE_ERROR, test[i].expected_error);
+       g_assert_error (error, PANGO_LAYOUT_DESERIALIZE_ERROR, test[i].expected_error);
        g_bytes_unref (bytes);
        g_clear_error (&error);
     }


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