summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-09-13 17:26:04 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-09-13 17:26:04 -0700
commit8fbfab83e9c580a25537a2eefa6f63ef313f3089 (patch)
tree77ef2c88dc39172c1d55388e301166a80d9f2fa2 /src
parentb9ef9af74a4cc401c02468f20a68659b9b2a1235 (diff)
eina: add an ability to quickly convert from an Eina_Value to an Eina_Binbuf.
Diffstat (limited to 'src')
-rw-r--r--src/lib/eina/eina_binbuf.h1
-rw-r--r--src/lib/eina/eina_value.c29
-rw-r--r--src/lib/eina/eina_value.h18
3 files changed, 48 insertions, 0 deletions
diff --git a/src/lib/eina/eina_binbuf.h b/src/lib/eina/eina_binbuf.h
index 0aa0e1a117..e84453731e 100644
--- a/src/lib/eina/eina_binbuf.h
+++ b/src/lib/eina/eina_binbuf.h
@@ -5,6 +5,7 @@
5#include <stdarg.h> 5#include <stdarg.h>
6 6
7#include "eina_types.h" 7#include "eina_types.h"
8#include "eina_slice.h"
8 9
9/** 10/**
10 * @addtogroup Eina_Binary_Buffer_Group Binary Buffer 11 * @addtogroup Eina_Binary_Buffer_Group Binary Buffer
diff --git a/src/lib/eina/eina_value.c b/src/lib/eina/eina_value.c
index d3a9d6dec6..f22718b147 100644
--- a/src/lib/eina/eina_value.c
+++ b/src/lib/eina/eina_value.c
@@ -37,6 +37,7 @@
37#include "eina_lock.h" 37#include "eina_lock.h"
38#include "eina_file.h" 38#include "eina_file.h"
39#include "eina_rectangle.h" 39#include "eina_rectangle.h"
40#include "eina_binbuf.h"
40 41
41/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ 42/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
42#include "eina_safety_checks.h" 43#include "eina_safety_checks.h"
@@ -5572,6 +5573,34 @@ eina_value_to_string(const Eina_Value *value)
5572 return tmp.value.ptr; /* steal value */ 5573 return tmp.value.ptr; /* steal value */
5573} 5574}
5574 5575
5576EAPI Eina_Binbuf *
5577eina_value_to_binbuf(Eina_Value *value)
5578{
5579 Eina_Value tmp = EINA_VALUE_EMPTY;
5580 Eina_Value_Blob out;
5581 Eina_Binbuf *buf;
5582
5583 if (value->type != EINA_VALUE_TYPE_BLOB)
5584 {
5585 eina_value_setup(&tmp, EINA_VALUE_TYPE_BLOB);
5586
5587 if (!eina_value_convert(value, &tmp))
5588 return NULL;
5589
5590 value = &tmp;
5591 }
5592
5593 eina_value_get(value, &out);
5594 if (!out.memory) return NULL;
5595
5596 buf = eina_binbuf_new();
5597 eina_binbuf_append_length(buf, out.memory, out.size);
5598
5599 eina_value_flush(&tmp);
5600
5601 return buf;
5602}
5603
5575EAPI Eina_Value * 5604EAPI Eina_Value *
5576eina_value_array_new(const Eina_Value_Type *subtype, unsigned int step) 5605eina_value_array_new(const Eina_Value_Type *subtype, unsigned int step)
5577{ 5606{
diff --git a/src/lib/eina/eina_value.h b/src/lib/eina/eina_value.h
index 305d378548..773de02119 100644
--- a/src/lib/eina/eina_value.h
+++ b/src/lib/eina/eina_value.h
@@ -27,6 +27,7 @@
27#include "eina_list.h" 27#include "eina_list.h"
28#include "eina_hash.h" 28#include "eina_hash.h"
29#include "eina_rectangle.h" 29#include "eina_rectangle.h"
30#include "eina_binbuf.h"
30 31
31/** 32/**
32 * @page eina_value_example_01_page Eina_Value usage 33 * @page eina_value_example_01_page Eina_Value usage
@@ -1070,6 +1071,22 @@ static inline Eina_Bool eina_value_pget(const Eina_Value *value,
1070EAPI Eina_Bool eina_value_convert(const Eina_Value *value, 1071EAPI Eina_Bool eina_value_convert(const Eina_Value *value,
1071 Eina_Value *convert) EINA_ARG_NONNULL(1, 2); 1072 Eina_Value *convert) EINA_ARG_NONNULL(1, 2);
1072 1073
1074/**
1075 * @brief Converts one value to Eina_Binbuf.
1076 * @param value Source value object.
1077 * @return @c NULL if it failed to get a memory content, a valid Eina_Binbuf otherwise.
1078 *
1079 * Converts one value to EINA_TYPE_VALUE_BLOB if necessary by calling
1080 * @c eina_value_convert() function.
1081 *
1082 * @note You are responsible for destroying the Eina_Binbuf returned.
1083 *
1084 * @see eina_value_to_string()
1085 * @see eina_value_convert()
1086 *
1087 * @since 1.20
1088 */
1089EAPI Eina_Binbuf *eina_value_to_binbuf(Eina_Value *value);
1073 1090
1074/** 1091/**
1075 * @brief Converts value to string. 1092 * @brief Converts value to string.
@@ -1077,6 +1094,7 @@ EAPI Eina_Bool eina_value_convert(const Eina_Value *value,
1077 * @return newly allocated memory or @c NULL on failure. 1094 * @return newly allocated memory or @c NULL on failure.
1078 * 1095 *
1079 * @see eina_value_convert() 1096 * @see eina_value_convert()
1097 * @see eina_value_to_binbuf()
1080 * @since 1.2 1098 * @since 1.2
1081 */ 1099 */
1082EAPI char *eina_value_to_string(const Eina_Value *value) EINA_ARG_NONNULL(1); 1100EAPI char *eina_value_to_string(const Eina_Value *value) EINA_ARG_NONNULL(1);