GComm  0.2.3
gmcast_node.hpp
1 /*
2  * Copyright (C) 2009-2012 Codership Oy <info@codership.com>
3  */
4 
5 #ifndef GMCAST_NODE_HPP
6 #define GMCAST_NODE_HPP
7 
8 #include "gcomm/types.hpp"
9 #include "gcomm/uuid.hpp"
10 
11 #include "gu_serialize.hpp"
12 
13 namespace gcomm
14 {
15  namespace gmcast
16  {
17  class Node;
18  std::ostream& operator<<(std::ostream&, const Node&);
19  }
20 }
21 
22 
24 {
25 
26 public:
27 
28  Node(const std::string& addr = "") : addr_(addr), mcast_addr_("") { }
29 
30  const std::string& addr() const { return addr_.to_string(); }
31  const std::string& mcast_addr() const { return mcast_addr_.to_string(); }
32 
33  size_t unserialize(const gu::byte_t* buf,
34  const size_t buflen, const size_t offset)
35  {
36  size_t off;
37  uint32_t bits;
38  gu_trace (off = gu::unserialize4(buf, buflen, offset, bits));
39  gu_trace (off = addr_.unserialize(buf, buflen, off));
40  gu_trace (off = mcast_addr_.unserialize(buf, buflen, off));
41  return off;
42  }
43 
44  size_t serialize(gu::byte_t* buf, const size_t buflen,
45  const size_t offset) const
46  {
47  size_t off;
48  uint32_t bits(0);
49  gu_trace (off = gu::serialize4(bits, buf, buflen, offset));
50  gu_trace (off = addr_.serialize(buf, buflen, off));
51  gu_trace (off = mcast_addr_.serialize(buf, buflen, off));
52  return off;
53  }
54 
55  static size_t serial_size() { return (4 + 2 * ADDR_SIZE); }
56 
57 private:
58  static const size_t ADDR_SIZE = 64;
60  gcomm::String<ADDR_SIZE> mcast_addr_;
61 };
62 
63 
64 inline std::ostream& gcomm::gmcast::operator<<(std::ostream& os, const Node& n)
65 {
66  return os;
67 }
68 
69 
70 #endif // GMCAST_NODE_HPP
Definition: gmcast_node.hpp:23