From e17ac220e4bff53fb89f5bea636acb61e347cf50 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Mon, 13 Feb 2012 13:00:26 +0530 Subject: protocol: code cleanup make dict serialize and unserialization code a macro Change-Id: I459c77c6c1f54118c6c94390162670f4159b9690 BUG: 764890 Signed-off-by: Amar Tumballi Reviewed-on: http://review.gluster.com/2742 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- libglusterfs/src/dict.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index c68c3af8..8e81e539 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -35,6 +35,51 @@ typedef struct _data data_t; typedef struct _dict dict_t; typedef struct _data_pair data_pair_t; + +#define GF_PROTOCOL_DICT_SERIALIZE(this,from_dict,to,len,ope,labl) do { \ + int ret = 0; \ + size_t dictlen = 0; \ + \ + if (!from_dict) \ + break; \ + \ + ret = dict_allocate_and_serialize (from_dict, to, \ + &dictlen); \ + if (ret < 0) { \ + gf_log (this->name, GF_LOG_WARNING, \ + "failed to get serialized dict (%s)", \ + (#from_dict)); \ + ope = EINVAL; \ + goto labl; \ + } \ + len = dictlen; \ + } while (0) + + +#define GF_PROTOCOL_DICT_UNSERIALIZE(xl,to,buff,len,ret,ope,labl) do { \ + char *buf = NULL; \ + if (!len) \ + break; \ + to = dict_new(); \ + GF_VALIDATE_OR_GOTO (xl->name, to, labl); \ + \ + buf = memdup (buff, len); \ + GF_VALIDATE_OR_GOTO (xl->name, buf, labl); \ + \ + ret = dict_unserialize (buf, len, &to); \ + if (ret < 0) { \ + gf_log (xl->name, GF_LOG_WARNING, \ + "failed to unserialize dictionary (%s)", \ + (#to)); \ + \ + ope = EINVAL; \ + GF_FREE (buf); \ + goto labl; \ + } \ + \ + to->extra_free = buf; \ + } while (0) + struct _data { unsigned char is_static:1; unsigned char is_const:1; -- cgit