diff options
author | Amar Tumballi <amar@gluster.com> | 2012-02-13 13:00:26 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2012-02-14 01:00:26 -0800 |
commit | e17ac220e4bff53fb89f5bea636acb61e347cf50 (patch) | |
tree | 5d34c63d431ff13bbcdadcd88bf11f463d5c1b9d /libglusterfs/src | |
parent | 635f3bc0f8a05ad1280f8ab7d55181502bcad700 (diff) |
protocol: code cleanup
make dict serialize and unserialization code a macro
Change-Id: I459c77c6c1f54118c6c94390162670f4159b9690
BUG: 764890
Signed-off-by: Amar Tumballi <amar@gluster.com>
Reviewed-on: http://review.gluster.com/2742
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/dict.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index c68c3af873b..8e81e539b74 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; |