From: Greg Farnum Date: Fri, 6 Dec 2013 21:51:51 +0000 (-0800) Subject: MonCommand: support encode/decode X-Git-Tag: v0.75~125^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ac69a0122bf6665123e9d282e6dbe7521950c2f1;p=ceph.git MonCommand: support encode/decode Signed-off-by: Greg Farnum --- diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 2c066f6e263e..5d280cc8a80f 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -857,7 +857,46 @@ struct MonCommand { string module; string req_perms; string availability; + + void encode(bufferlist &bl) const { + /* + * very naughty: deliberately unversioned because individual commands + * shouldn't be encoded standalone, only as a full set (which we do + * version, see encode_array() below). + */ + ::encode(cmdstring, bl); + ::encode(helpstring, bl); + ::encode(module, bl); + ::encode(req_perms, bl); + ::encode(availability, bl); + } + void decode(bufferlist::iterator &bl) { + ::decode(cmdstring, bl); + ::decode(helpstring, bl); + ::decode(module, bl); + ::decode(req_perms, bl); + ::decode(availability, bl); + } + + static void encode_array(const MonCommand *cmds, int size, bufferlist &bl) { + ENCODE_START(1, 1, bl); + uint16_t s = size; + ::encode(s, bl); + ::encode_array_nohead(cmds, size, bl); + ENCODE_FINISH(bl); + } + static void decode_array(MonCommand **cmds, int *size, + bufferlist::iterator &bl) { + DECODE_START(1, bl); + uint16_t s = 0; + ::decode(s, bl); + *size = s; + *cmds = new MonCommand[*size]; + ::decode_array_nohead(*cmds, *size, bl); + DECODE_FINISH(bl); + } }; +WRITE_CLASS_ENCODER(MonCommand); void get_command_descriptions(const MonCommand *commands, unsigned commands_size,