[grilo] core: Add support for binary data in GrlData
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo] core: Add support for binary data in GrlData
- Date: Thu, 3 Feb 2011 12:11:25 +0000 (UTC)
commit 3277b84188f9725adcbe456a82ff046d4560ec39
Author: Fabien Lebaillif - Delamare <fabien developers arq-media com>
Date: Thu Jan 20 12:37:52 2011 +0100
core: Add support for binary data in GrlData
Sometimes it is interested to handle binary data in the grilo medias.
This add support for making it easy to take care of it.
Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
src/data/grl-data.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-
src/data/grl-data.h | 4 +++
2 files changed, 60 insertions(+), 1 deletions(-)
---
diff --git a/src/data/grl-data.c b/src/data/grl-data.c
index 99c8446..116319c 100644
--- a/src/data/grl-data.c
+++ b/src/data/grl-data.c
@@ -343,7 +343,6 @@ grl_data_set_float (GrlData *data, GrlKeyID key, float floatvalue)
g_value_set_float (&value, floatvalue);
grl_data_set (data, key, &value);
}
-
/**
* grl_data_get_float:
* @data: data to inspect
@@ -369,6 +368,62 @@ grl_data_get_float (GrlData *data, GrlKeyID key)
}
/**
+ * grl_data_set_binary:
+ * @data: data to change
+ * @key: (type GObject.ParamSpec): key to change or add
+ * @buf: buffer holding the data
+ * @size: size of the buffer
+ *
+ * Sets the value associated with the key. If key already has a value and
+ * #overwrite is TRUE, old value is replaced by the new one.
+ **/
+void
+grl_data_set_binary (GrlData *data, GrlKeyID key, const guint8 *buf, gsize size)
+{
+ GValue v = { 0 };
+ GByteArray * array;
+
+ array = g_byte_array_append(g_byte_array_sized_new(size),
+ buf,
+ size);
+
+ g_value_init (&v, g_byte_array_get_type());
+ g_value_take_boxed(&v, array);
+ grl_data_set(data, key, &v);
+ g_value_unset (&v);
+}
+
+/**
+ * grl_data_get_binary:
+ * @data: data to inspect
+ * @key: (type GObject.ParamSpec): key to use
+ * @size: location to store the buffer size
+ *
+ * Returns the value associated with the key. If key has no value, or value is
+ * not a gfloat, or key is not in data, then 0 is returned.
+ *
+ * Returns: buffer location associated with the key, or NULL in other case. If
+ * successful size will be set the to the buffer size.
+ **/
+const guint8 *
+grl_data_get_binary(GrlData *data, GrlKeyID key, gsize *size)
+{
+ g_return_val_if_fail (size, NULL);
+
+ const GValue *value = grl_data_get (data, key);
+
+ if (!value || !G_VALUE_HOLDS_BOXED(value)) {
+ return NULL;
+ } else {
+ GByteArray * array;
+
+ array = g_value_get_boxed(value);
+ *size = array->len;
+ return (const guint8 *) array->data;
+ }
+}
+
+/**
* grl_data_add:
* @data: data to change
* @key: (type GObject.ParamSpec): key to add
diff --git a/src/data/grl-data.h b/src/data/grl-data.h
index 36fbdcb..fba7764 100644
--- a/src/data/grl-data.h
+++ b/src/data/grl-data.h
@@ -105,6 +105,8 @@ void grl_data_set_float (GrlData *data,
GrlKeyID key,
gfloat floatvalue);
+void grl_data_set_binary(GrlData *data, GrlKeyID key, const guint8 *buf, gsize size);
+
const GValue *grl_data_get (GrlData *data, GrlKeyID key);
const gchar *grl_data_get_string (GrlData *data, GrlKeyID key);
@@ -113,6 +115,8 @@ gint grl_data_get_int (GrlData *data, GrlKeyID key);
gfloat grl_data_get_float (GrlData *data, GrlKeyID key);
+const guint8 *grl_data_get_binary(GrlData *data, GrlKeyID key, gsize *size);
+
void grl_data_add (GrlData *data, GrlKeyID key);
void grl_data_remove (GrlData *data, GrlKeyID key);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]