Change LGPL-2.1+ to LGPL-2.1-or-later
[platform/upstream/glib.git] / glib / gvariant-serialiser.h
1 /*
2  * Copyright © 2007, 2008 Ryan Lortie
3  * Copyright © 2010 Codethink Limited
4  *
5  * SPDX-License-Identifier: LGPL-2.1-or-later
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  *
20  * Author: Ryan Lortie <desrt@desrt.ca>
21  */
22
23 #ifndef __G_VARIANT_SERIALISER_H__
24 #define __G_VARIANT_SERIALISER_H__
25
26 #include "gvarianttypeinfo.h"
27
28 typedef struct
29 {
30   GVariantTypeInfo *type_info;
31   guchar           *data;
32   gsize             size;
33   gsize             depth;  /* same semantics as GVariant.depth */
34
35   /* If ordered_offsets_up_to == n this means that all the frame offsets up to and
36    * including the frame offset determining the end of element n are in order.
37    * This guarantees that the bytes of element n don't overlap with any previous
38    * element.
39    *
40    * This is both read and set by g_variant_serialised_get_child() for arrays of
41    * non-fixed-width types, and for tuples.
42    *
43    * Even when dealing with tuples, @ordered_offsets_up_to is an element index,
44    * rather than an index into the frame offsets. */
45   gsize             ordered_offsets_up_to;
46
47   /* Similar to @ordered_offsets_up_to. This gives the index of the child element
48    * whose frame offset is the highest in the offset table which has been
49    * checked so far.
50    *
51    * This is always ≥ @ordered_offsets_up_to. It is always an element index.
52    *
53    * See documentation in gvariant-core.c for `struct GVariant` for details. */
54   gsize             checked_offsets_up_to;
55 } GVariantSerialised;
56
57 /* deserialization */
58 GLIB_AVAILABLE_IN_ALL
59 gsize                           g_variant_serialised_n_children         (GVariantSerialised        container);
60 GLIB_AVAILABLE_IN_ALL
61 GVariantSerialised              g_variant_serialised_get_child          (GVariantSerialised        container,
62                                                                          gsize                     index);
63
64 /* serialization */
65 typedef void                  (*GVariantSerialisedFiller)               (GVariantSerialised       *serialised,
66                                                                          gpointer                  data);
67
68 GLIB_AVAILABLE_IN_ALL
69 gsize                           g_variant_serialiser_needed_size        (GVariantTypeInfo         *info,
70                                                                          GVariantSerialisedFiller  gsv_filler,
71                                                                          const gpointer           *children,
72                                                                          gsize                     n_children);
73
74 GLIB_AVAILABLE_IN_ALL
75 void                            g_variant_serialiser_serialise          (GVariantSerialised        container,
76                                                                          GVariantSerialisedFiller  gsv_filler,
77                                                                          const gpointer           *children,
78                                                                          gsize                     n_children);
79
80 /* misc */
81 GLIB_AVAILABLE_IN_2_60
82 gboolean                        g_variant_serialised_check              (GVariantSerialised        serialised);
83 GLIB_AVAILABLE_IN_ALL
84 gboolean                        g_variant_serialised_is_normal          (GVariantSerialised        value);
85 GLIB_AVAILABLE_IN_ALL
86 void                            g_variant_serialised_byteswap           (GVariantSerialised        value);
87
88 /* validation of strings */
89 GLIB_AVAILABLE_IN_ALL
90 gboolean                        g_variant_serialiser_is_string          (gconstpointer             data,
91                                                                          gsize                     size);
92 GLIB_AVAILABLE_IN_ALL
93 gboolean                        g_variant_serialiser_is_object_path     (gconstpointer             data,
94                                                                          gsize                     size);
95 GLIB_AVAILABLE_IN_ALL
96 gboolean                        g_variant_serialiser_is_signature       (gconstpointer             data,
97                                                                          gsize                     size);
98
99 #endif /* __G_VARIANT_SERIALISER_H__ */