[FFmpeg-devel] [PATCH 07/11] lavu/dict: add av_dict_serialize

Michael Niedermayer michaelni at gmx.at
Tue Nov 18 03:31:17 CET 2014


On Tue, Nov 18, 2014 at 01:28:42AM +0100, Lukasz Marek wrote:
> On 17.11.2014 14:01, Michael Niedermayer wrote:
> >On Mon, Nov 17, 2014 at 02:46:54AM +0100, Lukasz Marek wrote:
> >>TODO: bump minor, update doc/APIchanges
> >>
> >>Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
> >>---
> >>  libavutil/dict.c | 27 +++++++++++++++++++++++++++
> >>  libavutil/dict.h | 16 ++++++++++++++++
> >>  2 files changed, 43 insertions(+)
> >>
> >>diff --git a/libavutil/dict.c b/libavutil/dict.c
> >>index 475e906..a41d61e 100644
> >>--- a/libavutil/dict.c
> >>+++ b/libavutil/dict.c
> >>@@ -24,6 +24,7 @@
> >>  #include "dict.h"
> >>  #include "internal.h"
> >>  #include "mem.h"
> >>+#include "bprint.h"
> >>
> >>  struct AVDictionary {
> >>      int count;
> >
> >>@@ -207,3 +208,29 @@ void av_dict_copy(AVDictionary **dst, FF_CONST_AVUTIL53 AVDictionary *src, int f
> >>      while ((t = av_dict_get(src, "", t, AV_DICT_IGNORE_SUFFIX)))
> >>          av_dict_set(dst, t->key, t->value, flags);
> >>  }
> >>+
> >>+int av_dict_serialize(const AVDictionary *m, char **buffer,
> >>+                      const char pairs_sep, const char key_val_sep)
> >>+{
> >>+    AVDictionaryEntry *t = NULL;
> >>+    AVBPrint bprint;
> >>+    int cnt = 0;
> >>+
> >>+    if (!m || !buffer)
> >>+        return AVERROR(EINVAL);
> >
> >It should be also possible to serialize an empty dictionary
> >
> >the serialization string should also contain a serialization format
> >identifer/version otherwise future maintaince could become hard
> >this identifer should specify the used separator chars
> 
> Escaping OK, added. But what is the point of this? It will just
> require additional function to remove these and pass it to
> av_dict_parse_string.
> Of course user will not have to remember separators.

what will the function be used for ?
will it be used to store dictionaries in files?, communicate them
across the network? communicate between libs ?

most likely the format will change over the years in some way,
maybe dictionaries will get additional fields for type or maybe
length for non-null terminated data, or ...

how will that work without any way to identify the version or format?

also a serialization stream thats self containd seems much nicer to
handle as theres no need to keep track of the exact version (if we
end up having more than 1) the used seperators, ...

also consider 2 libs or apps to interface with each other using this
serialization format, if one requires a change to the format how can
the other know without a version in it, it would need to know it by
external means. it can surely be done but it doesnt feel like
something desirable


[...]
> @@ -207,3 +208,69 @@ void av_dict_copy(AVDictionary **dst, FF_CONST_AVUTIL53 AVDictionary *src, int f
>      while ((t = av_dict_get(src, "", t, AV_DICT_IGNORE_SUFFIX)))
>          av_dict_set(dst, t->key, t->value, flags);
>  }
> +
> +int av_dict_serialize(const AVDictionary *m, char **buffer,
> +                      const char pairs_sep, const char key_val_sep)
> +{
> +    AVDictionaryEntry *t = NULL;
> +    AVBPrint bprint;
> +    int cnt = 0;
> +    char special_chars[] = {pairs_sep, key_val_sep, '\0'};
> +
> +    if (!buffer || pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep)
> +        return AVERROR(EINVAL);

does it work if the escaping chars " ' \ are used as seperators ?

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141118/898084ad/attachment.asc>


More information about the ffmpeg-devel mailing list