mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
libgimpconfig: add (de)serialization support of GBytes arguments.
Basically the same as GimpParasite, except that we don't same a parasite name and flags.
This commit is contained in:
parent
69edf13e2c
commit
cd5d221cfa
2 changed files with 53 additions and 0 deletions
|
@ -98,6 +98,9 @@ static GTokenType gimp_config_deserialize_file_value (GValue *value,
|
|||
static GTokenType gimp_config_deserialize_parasite_value (GValue *value,
|
||||
GParamSpec *prop_spec,
|
||||
GScanner *scanner);
|
||||
static GTokenType gimp_config_deserialize_bytes (GValue *value,
|
||||
GParamSpec *prop_spec,
|
||||
GScanner *scanner);
|
||||
static GTokenType gimp_config_deserialize_any (GValue *value,
|
||||
GParamSpec *prop_spec,
|
||||
GScanner *scanner);
|
||||
|
@ -389,6 +392,10 @@ gimp_config_deserialize_value (GValue *value,
|
|||
{
|
||||
return gimp_config_deserialize_parasite_value (value, prop_spec, scanner);
|
||||
}
|
||||
else if (prop_spec->value_type == G_TYPE_BYTES)
|
||||
{
|
||||
return gimp_config_deserialize_bytes (value, prop_spec, scanner);
|
||||
}
|
||||
|
||||
/* This fallback will only work for value_types that
|
||||
* can be transformed from a string value.
|
||||
|
@ -1030,6 +1037,28 @@ gimp_config_deserialize_parasite_value (GValue *value,
|
|||
return G_TOKEN_RIGHT_PAREN;
|
||||
}
|
||||
|
||||
static GTokenType
|
||||
gimp_config_deserialize_bytes (GValue *value,
|
||||
GParamSpec *prop_spec,
|
||||
GScanner *scanner)
|
||||
{
|
||||
GBytes *bytes;
|
||||
guint8 *data;
|
||||
gint data_length;
|
||||
|
||||
if (! gimp_scanner_parse_int (scanner, &data_length))
|
||||
return G_TOKEN_INT;
|
||||
|
||||
if (! gimp_scanner_parse_data (scanner, data_length, &data))
|
||||
return G_TOKEN_STRING;
|
||||
|
||||
bytes = g_bytes_new (data, data_length);
|
||||
|
||||
g_value_take_boxed (value, bytes);
|
||||
|
||||
return G_TOKEN_RIGHT_PAREN;
|
||||
}
|
||||
|
||||
static GTokenType
|
||||
gimp_config_deserialize_any (GValue *value,
|
||||
GParamSpec *prop_spec,
|
||||
|
|
|
@ -270,6 +270,30 @@ gimp_config_serialize_property (GimpConfig *config,
|
|||
success = TRUE;
|
||||
}
|
||||
|
||||
if (success)
|
||||
gimp_config_writer_close (writer);
|
||||
else
|
||||
gimp_config_writer_revert (writer);
|
||||
}
|
||||
else if (G_VALUE_TYPE (&value) == G_TYPE_BYTES)
|
||||
{
|
||||
GBytes *bytes = g_value_get_boxed (&value);
|
||||
|
||||
gimp_config_writer_open (writer, param_spec->name);
|
||||
|
||||
if (bytes)
|
||||
{
|
||||
gconstpointer data;
|
||||
gsize data_length;
|
||||
|
||||
data = g_bytes_get_data (bytes, &data_length);
|
||||
|
||||
gimp_config_writer_printf (writer, "%lu", data_length);
|
||||
gimp_config_writer_data (writer, data_length, data);
|
||||
|
||||
success = TRUE;
|
||||
}
|
||||
|
||||
if (success)
|
||||
gimp_config_writer_close (writer);
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue