diff options
author | Cedric Bail <cedric@osg.samsung.com> | 2017-09-13 17:26:04 -0700 |
---|---|---|
committer | Cedric Bail <cedric@osg.samsung.com> | 2017-09-13 17:26:04 -0700 |
commit | 8fbfab83e9c580a25537a2eefa6f63ef313f3089 (patch) | |
tree | 77ef2c88dc39172c1d55388e301166a80d9f2fa2 | |
parent | b9ef9af74a4cc401c02468f20a68659b9b2a1235 (diff) | |
download | efl-8fbfab83e9c580a25537a2eefa6f63ef313f3089.tar.gz |
eina: add an ability to quickly convert from an Eina_Value to an Eina_Binbuf.
-rw-r--r-- | src/lib/eina/eina_binbuf.h | 1 | ||||
-rw-r--r-- | src/lib/eina/eina_value.c | 29 | ||||
-rw-r--r-- | src/lib/eina/eina_value.h | 18 |
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 @@ #include <stdarg.h> #include "eina_types.h" +#include "eina_slice.h" /** * @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 @@ #include "eina_lock.h" #include "eina_file.h" #include "eina_rectangle.h" +#include "eina_binbuf.h" /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ #include "eina_safety_checks.h" @@ -5572,6 +5573,34 @@ eina_value_to_string(const Eina_Value *value) return tmp.value.ptr; /* steal value */ } +EAPI Eina_Binbuf * +eina_value_to_binbuf(Eina_Value *value) +{ + Eina_Value tmp = EINA_VALUE_EMPTY; + Eina_Value_Blob out; + Eina_Binbuf *buf; + + if (value->type != EINA_VALUE_TYPE_BLOB) + { + eina_value_setup(&tmp, EINA_VALUE_TYPE_BLOB); + + if (!eina_value_convert(value, &tmp)) + return NULL; + + value = &tmp; + } + + eina_value_get(value, &out); + if (!out.memory) return NULL; + + buf = eina_binbuf_new(); + eina_binbuf_append_length(buf, out.memory, out.size); + + eina_value_flush(&tmp); + + return buf; +} + EAPI Eina_Value * eina_value_array_new(const Eina_Value_Type *subtype, unsigned int step) { 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 @@ #include "eina_list.h" #include "eina_hash.h" #include "eina_rectangle.h" +#include "eina_binbuf.h" /** * @page eina_value_example_01_page Eina_Value usage @@ -1070,6 +1071,22 @@ static inline Eina_Bool eina_value_pget(const Eina_Value *value, EAPI Eina_Bool eina_value_convert(const Eina_Value *value, Eina_Value *convert) EINA_ARG_NONNULL(1, 2); +/** + * @brief Converts one value to Eina_Binbuf. + * @param value Source value object. + * @return @c NULL if it failed to get a memory content, a valid Eina_Binbuf otherwise. + * + * Converts one value to EINA_TYPE_VALUE_BLOB if necessary by calling + * @c eina_value_convert() function. + * + * @note You are responsible for destroying the Eina_Binbuf returned. + * + * @see eina_value_to_string() + * @see eina_value_convert() + * + * @since 1.20 + */ +EAPI Eina_Binbuf *eina_value_to_binbuf(Eina_Value *value); /** * @brief Converts value to string. @@ -1077,6 +1094,7 @@ EAPI Eina_Bool eina_value_convert(const Eina_Value *value, * @return newly allocated memory or @c NULL on failure. * * @see eina_value_convert() + * @see eina_value_to_binbuf() * @since 1.2 */ EAPI char *eina_value_to_string(const Eina_Value *value) EINA_ARG_NONNULL(1); |