[gimp/gimp-2-10] libgimpbase: add _gimp_wire_{read,write}_int64()



commit 7de86c63e66266440449e665228c9475d73d455d
Author: Ell <ell_se yahoo com>
Date:   Mon Nov 19 16:06:28 2018 -0500

    libgimpbase: add _gimp_wire_{read,write}_int64()
    
    ... for reading/writing guint64 data in the wire protocol.
    
    (cherry picked from commit 77c24ca16c521b1c4db0c4f45554bba0ae7a85cc)

 libgimpbase/gimpwire.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 libgimpbase/gimpwire.h |  8 ++++++++
 2 files changed, 57 insertions(+)
---
diff --git a/libgimpbase/gimpwire.c b/libgimpbase/gimpwire.c
index 2c3ea74eac..9382beec00 100644
--- a/libgimpbase/gimpwire.c
+++ b/libgimpbase/gimpwire.c
@@ -311,6 +311,30 @@ gimp_wire_destroy (GimpWireMessage *msg)
   (* handler->destroy_func) (msg);
 }
 
+gboolean
+_gimp_wire_read_int64 (GIOChannel *channel,
+                       guint64    *data,
+                       gint        count,
+                       gpointer    user_data)
+{
+  g_return_val_if_fail (count >= 0, FALSE);
+
+  if (count > 0)
+    {
+      if (! _gimp_wire_read_int8 (channel,
+                                  (guint8 *) data, count * 8, user_data))
+        return FALSE;
+
+      while (count--)
+        {
+          *data = GUINT64_FROM_BE (*data);
+          data++;
+        }
+    }
+
+  return TRUE;
+}
+
 gboolean
 _gimp_wire_read_int32 (GIOChannel *channel,
                        guint32    *data,
@@ -468,6 +492,31 @@ _gimp_wire_read_color (GIOChannel *channel,
                                  (gdouble *) data, 4 * count, user_data);
 }
 
+gboolean
+_gimp_wire_write_int64 (GIOChannel    *channel,
+                        const guint64 *data,
+                        gint           count,
+                        gpointer       user_data)
+{
+  g_return_val_if_fail (count >= 0, FALSE);
+
+  if (count > 0)
+    {
+      gint i;
+
+      for (i = 0; i < count; i++)
+        {
+          guint64 tmp = GUINT64_TO_BE (data[i]);
+
+          if (! _gimp_wire_write_int8 (channel,
+                                       (const guint8 *) &tmp, 8, user_data))
+            return FALSE;
+        }
+    }
+
+  return TRUE;
+}
+
 gboolean
 _gimp_wire_write_int32 (GIOChannel    *channel,
                         const guint32 *data,
diff --git a/libgimpbase/gimpwire.h b/libgimpbase/gimpwire.h
index 3f65b809f0..dde69d9881 100644
--- a/libgimpbase/gimpwire.h
+++ b/libgimpbase/gimpwire.h
@@ -83,6 +83,10 @@ void      gimp_wire_destroy       (GimpWireMessage     *msg);
 
 /*  for internal use in libgimpbase  */
 
+G_GNUC_INTERNAL gboolean  _gimp_wire_read_int64   (GIOChannel     *channel,
+                                                   guint64        *data,
+                                                   gint            count,
+                                                   gpointer        user_data);
 G_GNUC_INTERNAL gboolean  _gimp_wire_read_int32   (GIOChannel     *channel,
                                                    guint32        *data,
                                                    gint            count,
@@ -107,6 +111,10 @@ G_GNUC_INTERNAL gboolean  _gimp_wire_read_color   (GIOChannel     *channel,
                                                    GimpRGB        *data,
                                                    gint            count,
                                                    gpointer        user_data);
+G_GNUC_INTERNAL gboolean  _gimp_wire_write_int64  (GIOChannel     *channel,
+                                                   const guint64  *data,
+                                                   gint            count,
+                                                   gpointer        user_data);
 G_GNUC_INTERNAL gboolean  _gimp_wire_write_int32  (GIOChannel     *channel,
                                                    const guint32  *data,
                                                    gint            count,


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