otsdaq  v2_05_02_indev
TCPPacket.h
1 #ifndef _ots_TCPPacket_h_
2 #define _ots_TCPPacket_h_
3 
4 #include <string>
5 
6 namespace ots
7 {
8 class TCPPacket
9 {
10  public:
11  TCPPacket();
12  virtual ~TCPPacket(void);
13 
14  static std::string encode(char const* message, std::size_t length);
15  static std::string encode(const std::string& message);
16 
17  bool decode (std::string& message);
18  // Resets the storage buffer
19  void reset (void);
20  bool isEmpty(void);
21 
22  // Operator overload
23  TCPPacket& operator+=(const std::string& buffer)
24  {
25  this->fBuffer += buffer;
26  return *this;
27  }
28 
29  friend std::ostream& operator<<(std::ostream& out, const TCPPacket& packet)
30  {
31  // out << packet.fBuffer.substr(TCPPacket::headerLength);
32  out << packet.fBuffer;
33 
34  return out; // return std::ostream so we can chain calls to operator<<
35  }
36 
37  private:
38  static constexpr uint32_t headerLength = 4; // sizeof(uint32_t); //THIS MUST BE 4
39 
40  std::string fBuffer; // This is Header + Message
41 };
42 } // namespace ots
43 #endif