otsdaq  v2_04_02
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(const std::string& message);
15 
16  bool decode(std::string& message);
17  // Resets the storage buffer
18  void reset(void);
19 
20  // Operator overload
21  TCPPacket& operator+=(const std::string& buffer)
22  {
23  this->fBuffer += buffer;
24  return *this;
25  }
26 
27  friend std::ostream& operator<<(std::ostream& out, const TCPPacket& packet)
28  {
29  // out << packet.fBuffer.substr(TCPPacket::headerLength);
30  out << packet.fBuffer;
31 
32  return out; // return std::ostream so we can chain calls to operator<<
33  }
34 
35  private:
36  static constexpr uint32_t headerLength = 4; // sizeof(uint32_t); //THIS MUST BE 4
37 
38  std::string fBuffer; // This is Header + Message
39 };
40 } // namespace ots
41 #endif