diff --git a/src/include/encoding.h b/src/include/encoding.h index a37b740dee8..693b2193cce 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -160,6 +160,11 @@ WRITE_INTTYPE_ENCODER(int16_t, le16) ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \ inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); } +#define WRITE_CLASS_ENCODER_OPTIONAL_FEATURES(cl) \ + inline void encode(const cl &c, bufferlist &bl, uint64_t features = 0) { \ + ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \ + inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); } + // string inline void encode(const std::string& s, bufferlist& bl, uint64_t features=0) diff --git a/src/msg/msg_types.cc b/src/msg/msg_types.cc index 44486aab03a..fb8ec5efea4 100644 --- a/src/msg/msg_types.cc +++ b/src/msg/msg_types.cc @@ -14,13 +14,18 @@ void entity_name_t::dump(Formatter *f) const f->dump_unsigned("num", num()); } - void entity_addr_t::dump(Formatter *f) const { f->dump_unsigned("nonce", nonce); f->dump_stream("addr") << get_sockaddr(); } +void entity_inst_t::dump(Formatter *f) const +{ + f->dump_object("name", name); + f->dump_object("addr", addr); +} + void entity_name_t::generate_test_instances(list& o) { o.push_back(new entity_name_t(entity_name_t::MON())); @@ -46,6 +51,15 @@ void entity_addr_t::generate_test_instances(list& o) o.push_back(b); } +void entity_inst_t::generate_test_instances(list& o) +{ + o.push_back(new entity_inst_t()); + entity_name_t name; + entity_addr_t addr; + entity_inst_t *a = new entity_inst_t(name, addr); + o.push_back(a); +} + bool entity_addr_t::parse(const char *s, const char **end) { memset(this, 0, sizeof(*this)); @@ -130,8 +144,6 @@ bool entity_addr_t::parse(const char *s, const char **end) return true; } - - ostream& operator<<(ostream& out, const sockaddr_storage &ss) { char buf[NI_MAXHOST] = { 0 }; diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 0f7439b9f4d..757c5d4a863 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -365,7 +365,7 @@ struct entity_addr_t { // broader study - void encode(bufferlist& bl) const { + void encode(bufferlist& bl, uint64_t features = 0) const { ::encode(type, bl); ::encode(nonce, bl); sockaddr_storage ss = get_sockaddr_storage(); @@ -400,7 +400,7 @@ struct entity_addr_t { static void generate_test_instances(list& o); }; -WRITE_CLASS_ENCODER(entity_addr_t) +WRITE_CLASS_ENCODER_OPTIONAL_FEATURES(entity_addr_t) inline ostream& operator<<(ostream& out, const entity_addr_t &addr) { @@ -442,16 +442,19 @@ struct entity_inst_t { return i; } - void encode(bufferlist& bl) const { + void encode(bufferlist& bl, uint64_t features = 0) const { ::encode(name, bl); - ::encode(addr, bl); + ::encode(addr, bl, features); } void decode(bufferlist::iterator& bl) { ::decode(name, bl); ::decode(addr, bl); } + + void dump(Formatter *f) const; + static void generate_test_instances(list& o); }; -WRITE_CLASS_ENCODER(entity_inst_t) +WRITE_CLASS_ENCODER_OPTIONAL_FEATURES(entity_inst_t) inline bool operator==(const entity_inst_t& a, const entity_inst_t& b) { diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index 22919bd970f..152cb2b72f5 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -34,7 +34,8 @@ TYPE(SloppyCRCMap) #include "msg/msg_types.h" TYPE(entity_name_t) -TYPE(entity_addr_t) +TYPE_FEATUREFUL(entity_addr_t) +TYPE_FEATUREFUL(entity_inst_t) #include "osd/OSDMap.h" TYPE(osd_info_t)