From: Sage Weil Date: Wed, 19 Oct 2011 04:26:46 +0000 (-0700) Subject: use WRITE_CLASS_ENCOER macro when possible X-Git-Tag: v0.38~57^2~2^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=954d3f9b1aad05eeb4bdadf25107af4af40537b0;p=ceph.git use WRITE_CLASS_ENCOER macro when possible --- diff --git a/src/include/types.h b/src/include/types.h index 3092f378112..c87ac5fe4d7 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -296,10 +296,15 @@ struct inodeno_t { inodeno_t(_inodeno_t v) : val(v) {} inodeno_t operator+=(inodeno_t o) { val += o.val; return *this; } operator _inodeno_t() const { return val; } -} __attribute__ ((__may_alias__)); -inline void encode(inodeno_t i, bufferlist &bl) { encode(i.val, bl); } -inline void decode(inodeno_t &i, bufferlist::iterator &p) { decode(i.val, p); } + void encode(bufferlist& bl) const { + ::encode(val, bl); + } + void decode(bufferlist::iterator& p) { + ::decode(val, p); + } +} __attribute__ ((__may_alias__)); +WRITE_CLASS_ENCODER(inodeno_t) inline ostream& operator<<(ostream& out, inodeno_t ino) { return out << hex << ino.val << dec; diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 32f597277a1..eeedf6e8b4f 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -755,18 +755,16 @@ struct metareqid_t { uint64_t tid; metareqid_t() : tid(0) {} metareqid_t(entity_name_t n, tid_t t) : name(n), tid(t) {} + void encode(bufferlist& bl) const { + ::encode(name, bl); + ::encode(tid, bl); + } + void decode(bufferlist::iterator &p) { + ::decode(name, p); + ::decode(tid, p); + } }; - -static inline void encode(const metareqid_t &r, bufferlist &bl) -{ - ::encode(r.name, bl); - ::encode(r.tid, bl); -} -static inline void decode( metareqid_t &r, bufferlist::iterator &p) -{ - ::decode(r.name, p); - ::decode(r.tid, p); -} +WRITE_CLASS_ENCODER(metareqid_t) inline ostream& operator<<(ostream& out, const metareqid_t& r) { return out << r.name << ":" << r.tid; @@ -887,16 +885,17 @@ struct dirfrag_t { dirfrag_t() : ino(0) { } dirfrag_t(inodeno_t i, frag_t f) : ino(i), frag(f) { } -}; -inline void encode(const dirfrag_t &f, bufferlist& bl) { - encode(f.ino, bl); - encode(f.frag, bl); -} -inline void decode(dirfrag_t &f, bufferlist::iterator& p) { - decode(f.ino, p); - decode(f.frag, p); -} + void encode(bufferlist& bl) const { + ::encode(ino, bl); + ::encode(frag, bl); + } + void decode(bufferlist::iterator& bl) { + ::decode(ino, bl); + ::decode(frag, bl); + } +}; +WRITE_CLASS_ENCODER(dirfrag_t) inline ostream& operator<<(ostream& out, const dirfrag_t df) { diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index d520e3554f7..ad58772fe2c 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -93,17 +93,16 @@ public: return true; } + void encode(bufferlist& bl) const { + ::encode(_type, bl); + ::encode(_num, bl); + } + void decode(bufferlist::iterator& bl) { + ::decode(_type, bl); + ::decode(_num, bl); + } }; - -inline void encode(const entity_name_t &a, bufferlist& bl) { - encode(a._type, bl); - encode(a._num, bl); -} - -inline void decode(entity_name_t &a, bufferlist::iterator& p) { - decode(a._type, p); - decode(a._num, p); -} +WRITE_CLASS_ENCODER(entity_name_t) inline bool operator== (const entity_name_t& l, const entity_name_t& r) { return (l.type() == r.type()) && (l.num() == r.num()); } @@ -320,16 +319,18 @@ struct entity_inst_t { ceph_entity_inst i = {name, addr}; return i; } + + void encode(bufferlist& bl) const { + ::encode(name, bl); + ::encode(addr, bl); + } + void decode(bufferlist::iterator& bl) { + ::decode(name, bl); + ::decode(addr, bl); + } }; +WRITE_CLASS_ENCODER(entity_inst_t) -inline void encode(const entity_inst_t &i, bufferlist& bl) { - encode(i.name, bl); - encode(i.addr, bl); -} -inline void decode(entity_inst_t &i, bufferlist::iterator& p) { - decode(i.name, p); - decode(i.addr, p); -} inline bool operator==(const entity_inst_t& a, const entity_inst_t& b) { return a.name == b.name && a.addr == b.addr; diff --git a/src/radosacl.cc b/src/radosacl.cc index 521634f4efa..d2f7ca5c488 100644 --- a/src/radosacl.cc +++ b/src/radosacl.cc @@ -38,19 +38,18 @@ void buf_to_hex(const unsigned char *buf, int len, char *str) struct ACLID { char id[ID_SIZE + 1]; + + void encode(bufferlist& bl) const { + bl.append((const char *)id, ID_SIZE); + } + void decode(bufferlist::iterator& iter) { + iter.copy(ID_SIZE, (char *)id); + } }; +WRITE_CLASS_ENCODER(ACLID) typedef __u32 ACLFlags; -void encode(const ACLID& id, bufferlist& bl) -{ - bl.append((const char *)id.id, ID_SIZE); -} - -void decode(ACLID& id, bufferlist::iterator& iter) -{ - iter.copy(ID_SIZE, (char *)id.id); -} inline bool operator<(const ACLID& l, const ACLID& r) {