![]() |
![]() |
![]() |
JSON-GLib Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
JsonNode * (*JsonBoxedSerializeFunc) (gconstpointer boxed
); gpointer (*JsonBoxedDeserializeFunc) (JsonNode *node
); void json_boxed_register_serialize_func (GType gboxed_type
,JsonNodeType node_type
,JsonBoxedSerializeFunc serialize_func
); void json_boxed_register_deserialize_func (GType gboxed_type
,JsonNodeType node_type
,JsonBoxedDeserializeFunc deserialize_func
); gboolean json_boxed_can_serialize (GType gboxed_type
,JsonNodeType *node_type
); gboolean json_boxed_can_deserialize (GType gboxed_type
,JsonNodeType node_type
); JsonNode * json_boxed_serialize (GType gboxed_type
,gconstpointer boxed
); gpointer json_boxed_deserialize (GType gboxed_type
,JsonNode *node
);
GLib's GBoxed type is a generic wrapper for arbitrary C structures.
JSON-GLib allows serialization and deserialization of a GBoxed type by registering functions mapping a JsonNodeType to a specific GType.
When registering a GBoxed type you should also register the corresponding transformation functions, e.g.:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
GType my_struct_get_type (void) { static GType boxed_type = 0; if (boxed_type == 0) { boxed_type = g_boxed_type_register_static (g_intern_static_string ("MyStruct"), (GBoxedCopyFunc) my_struct_copy, (GBoxedFreeFunc) my_struct_free); json_boxed_register_serialize_func (boxed_type, JSON_NODE_OBJECT, my_struct_serialize); json_boxed_register_deserialize_func (boxed_type, JSON_NODE_OBJECT, my_struct_deserialize); } return boxed_type; } |
The serialization function will be invoked by json_boxed_serialize()
:
it will be passed a pointer to the C structure and it must return a
JsonNode. The deserialization function will be invoked by
json_boxed_deserialize()
: it will be passed a JsonNode for the
declared type and it must return a newly allocated C structure.
It is possible to check whether a GBoxed type can be deserialized from a specific JsonNodeType, and whether a GBoxed can be serialized and to which specific JsonNodeType.
JsonNode * (*JsonBoxedSerializeFunc) (gconstpointer boxed
);
Serializes the passed GBoxed and stores it inside a JsonNode
|
a GBoxed |
Returns : |
the newly created JsonNode |
Since 0.10
gpointer (*JsonBoxedDeserializeFunc) (JsonNode *node
);
Deserializes the contents of the passed JsonNode into a GBoxed
|
a JsonNode |
Returns : |
the newly created boxed type |
Since 0.10
void json_boxed_register_serialize_func (GType gboxed_type
,JsonNodeType node_type
,JsonBoxedSerializeFunc serialize_func
);
Registers a serialization function for a GBoxed of type gboxed_type
to a JsonNode of type node_type
|
a boxed type |
|
a node type |
|
serialization function for boxed_type into
a JsonNode of type node_type
|
Since 0.10
void json_boxed_register_deserialize_func (GType gboxed_type
,JsonNodeType node_type
,JsonBoxedDeserializeFunc deserialize_func
);
Registers a deserialization function for a GBoxed of type gboxed_type
from a JsonNode of type node_type
|
a boxed type |
|
a node type |
|
deserialization function for boxed_type from
a JsonNode of type node_type
|
Since 0.10
gboolean json_boxed_can_serialize (GType gboxed_type
,JsonNodeType *node_type
);
Checks whether it is possible to serialize a GBoxed of
type gboxed_type
into a JsonNode. The type of the
JsonNode is placed inside node_type
if the function
returns TRUE
and it's undefined otherwise.
|
a boxed type |
|
the JsonNode type to which the boxed type can be serialized into. [out] |
Returns : |
TRUE if the type can be serialized,
and FALSE otherwise. |
Since 0.10
gboolean json_boxed_can_deserialize (GType gboxed_type
,JsonNodeType node_type
);
Checks whether it is possible to deserialize a GBoxed of
type gboxed_type
from a JsonNode of type node_type
|
a boxed type |
|
a JsonNode type |
Returns : |
TRUE if the type can be deserialized, FALSE otherwise |
Since 0.10
JsonNode * json_boxed_serialize (GType gboxed_type
,gconstpointer boxed
);
Serializes boxed
, a pointer to a GBoxed of type gboxed_type
,
into a JsonNode
|
a boxed type |
|
a pointer to a GBoxed of type gboxed_type
|
Returns : |
a JsonNode with the serialization of the
boxed type, or NULL if serialization either failed or was not possible. [transfer full]
|
Since 0.10
gpointer json_boxed_deserialize (GType gboxed_type
,JsonNode *node
);
Deserializes node
into a GBoxed of gboxed_type
|
a boxed type |
|
a JsonNode |
Returns : |
the newly allocated GBoxed. Use
g_boxed_free() to release the resources allocated by this
function. [transfer full]
|
Since 0.10