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