1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir
// from gtk-girs (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ffi,Node};
use glib::{prelude::*,translate::*};
glib::wrapper! {
/// `JsonSerializable` is an interface for controlling the serialization
/// and deserialization of `GObject` classes.
///
/// Implementing this interface allows controlling how the class is going
/// to be serialized or deserialized by `construct_gobject()` and
/// `serialize_gobject()`, respectively.
///
/// # Implements
///
/// [`SerializableExt`][trait@crate::prelude::SerializableExt]
#[doc(alias = "JsonSerializable")]
pub struct Serializable(Interface<ffi::JsonSerializable, ffi::JsonSerializableIface>);
match fn {
type_ => || ffi::json_serializable_get_type(),
}
}
impl Serializable {
pub const NONE: Option<&'static Serializable> = None;
}
/// Trait containing all [`struct@Serializable`] methods.
///
/// # Implementors
///
/// [`Serializable`][struct@crate::Serializable]
pub trait SerializableExt: IsA<Serializable> + 'static {
/// Calls the default implementation of the `vfunc::Json::Serializable::deserialize_property`
/// virtual function.
///
/// This function can be used inside a custom implementation of the
/// `deserialize_property()` virtual function in lieu of calling the
/// default implementation through `g_type_default_interface_peek()`:
///
/// **⚠️ The following code is in c ⚠️**
///
/// ```c
/// JsonSerializable *iface;
/// gboolean res;
///
/// iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
/// res = iface->deserialize_property (serializable, property_name,
/// value,
/// pspec,
/// property_node);
/// ```
/// ## `property_name`
/// the name of the property to deserialize
/// ## `value`
/// a pointer to an uninitialized value
/// ## `pspec`
/// a property description
/// ## `property_node`
/// the JSON node containing the serialized property
///
/// # Returns
///
/// `TRUE` if the property was successfully deserialized
#[doc(alias = "json_serializable_default_deserialize_property")]
fn default_deserialize_property(&self, property_name: &str, value: &mut glib::Value, pspec: impl AsRef<glib::ParamSpec>, property_node: &Node) -> bool {
unsafe {
from_glib(ffi::json_serializable_default_deserialize_property(self.as_ref().to_glib_none().0, property_name.to_glib_none().0, value.to_glib_none_mut().0, pspec.as_ref().to_glib_none().0, property_node.to_glib_none().0))
}
}
/// Calls the default implementation of the `vfunc::Json::Serializable::serialize_property`
/// virtual function.
///
/// This function can be used inside a custom implementation of the
/// `serialize_property()` virtual function in lieu of calling the
/// default implementation through `g_type_default_interface_peek()`:
///
/// **⚠️ The following code is in c ⚠️**
///
/// ```c
/// JsonSerializable *iface;
/// JsonNode *node;
///
/// iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
/// node = iface->serialize_property (serializable, property_name,
/// value,
/// pspec);
/// ```
///
/// This function will return `NULL` if the property could not be
/// serialized.
/// ## `property_name`
/// the name of the property to serialize
/// ## `value`
/// the value of the property to serialize
/// ## `pspec`
/// a property description
///
/// # Returns
///
/// a node containing the
/// serialized property
#[doc(alias = "json_serializable_default_serialize_property")]
fn default_serialize_property(&self, property_name: &str, value: &glib::Value, pspec: impl AsRef<glib::ParamSpec>) -> Option<Node> {
unsafe {
from_glib_full(ffi::json_serializable_default_serialize_property(self.as_ref().to_glib_none().0, property_name.to_glib_none().0, value.to_glib_none().0, pspec.as_ref().to_glib_none().0))
}
}
/// Asks a `JsonSerializable` implementation to deserialize the
/// property contained inside `property_node` and place its value
/// into `value`.
///
/// The `value` can be:
///
/// - an empty `GValue` initialized by `G_VALUE_INIT`, which will be automatically
/// initialized with the expected type of the property by using the given
/// property description (since JSON-GLib 1.6)
/// - a `GValue` initialized with the expected type of the property
///
/// This function will not be called for properties that are marked as
/// as `G_PARAM_CONSTRUCT_ONLY`.
/// ## `property_name`
/// the name of the property to serialize
/// ## `pspec`
/// a property description
/// ## `property_node`
/// the JSON node containing the serialized property
///
/// # Returns
///
/// `TRUE` if the property was successfully deserialized
///
/// ## `value`
/// a pointer to an uninitialized value
#[doc(alias = "json_serializable_deserialize_property")]
fn deserialize_property(&self, property_name: &str, pspec: impl AsRef<glib::ParamSpec>, property_node: &Node) -> Option<glib::Value> {
unsafe {
let mut value = glib::Value::uninitialized();
let ret = from_glib(ffi::json_serializable_deserialize_property(self.as_ref().to_glib_none().0, property_name.to_glib_none().0, value.to_glib_none_mut().0, pspec.as_ref().to_glib_none().0, property_node.to_glib_none().0));
if ret { Some(value) } else { None }
}
}
/// Calls the `vfunc::Json::Serializable::find_property` implementation on
/// the `JsonSerializable` instance, which will return the property
/// description for the given name.
/// ## `name`
/// the name of the property
///
/// # Returns
///
/// the property description
#[doc(alias = "json_serializable_find_property")]
fn find_property(&self, name: &str) -> Option<glib::ParamSpec> {
unsafe {
from_glib_none(ffi::json_serializable_find_property(self.as_ref().to_glib_none().0, name.to_glib_none().0))
}
}
/// Calls the `vfunc::Json::Serializable::get_property` implementation
/// on the `JsonSerializable` instance, which will get the value of
/// the given property.
/// ## `pspec`
/// a property description
///
/// # Returns
///
///
/// ## `value`
/// return location for the property value
#[doc(alias = "json_serializable_get_property")]
#[doc(alias = "get_property")]
fn property(&self, pspec: impl AsRef<glib::ParamSpec>) -> glib::Value {
unsafe {
let mut value = glib::Value::uninitialized();
ffi::json_serializable_get_property(self.as_ref().to_glib_none().0, pspec.as_ref().to_glib_none().0, value.to_glib_none_mut().0);
value
}
}
/// Calls the `vfunc::Json::Serializable::list_properties` implementation on
/// the `JsonSerializable` instance, which will return the list of serializable
/// properties.
///
/// # Returns
///
/// the serializable
/// properties of the object
#[doc(alias = "json_serializable_list_properties")]
fn list_properties(&self) -> Vec<glib::ParamSpec> {
unsafe {
let mut n_pspecs = std::mem::MaybeUninit::uninit();
let ret = FromGlibContainer::from_glib_container_num(ffi::json_serializable_list_properties(self.as_ref().to_glib_none().0, n_pspecs.as_mut_ptr()), n_pspecs.assume_init() as _);
ret
}
}
/// Asks a `JsonSerializable` implementation to serialize an object
/// property into a JSON node.
/// ## `property_name`
/// the name of the property to serialize
/// ## `value`
/// the value of the property to serialize
/// ## `pspec`
/// a property description
///
/// # Returns
///
/// a node containing the serialized property
#[doc(alias = "json_serializable_serialize_property")]
fn serialize_property(&self, property_name: &str, value: &glib::Value, pspec: impl AsRef<glib::ParamSpec>) -> Option<Node> {
unsafe {
from_glib_full(ffi::json_serializable_serialize_property(self.as_ref().to_glib_none().0, property_name.to_glib_none().0, value.to_glib_none().0, pspec.as_ref().to_glib_none().0))
}
}
/// Calls the `vfunc::Json::Serializable::set_property` implementation
/// on the `JsonSerializable` instance, which will set the property
/// with the given value.
/// ## `pspec`
/// a property description
/// ## `value`
/// the property value to set
#[doc(alias = "json_serializable_set_property")]
fn set_property(&self, pspec: impl AsRef<glib::ParamSpec>, value: &glib::Value) {
unsafe {
ffi::json_serializable_set_property(self.as_ref().to_glib_none().0, pspec.as_ref().to_glib_none().0, value.to_glib_none().0);
}
}
}
impl<O: IsA<Serializable>> SerializableExt for O {}