tdaq-develop-2025-02-12
TCPPacket.h
1 #ifndef _ots_TCPPacket_h_
2 #define _ots_TCPPacket_h_
3 
4 #include <cstdint>
5 #include <string>
6 
7 namespace ots
8 {
9 class TCPPacket
10 {
11  public:
12  TCPPacket();
13  virtual ~TCPPacket(void);
14 
15  static std::string encode(char const* message, std::size_t length);
16  static std::string encode(const std::string& message);
17 
18  bool decode(std::string& message);
20  void reset(void);
21  bool isEmpty(void);
22 
24  TCPPacket& operator+=(const std::string& buffer)
25  {
26  this->fBuffer += buffer;
27  return *this;
28  }
29 
30  friend std::ostream& operator<<(std::ostream& out, const TCPPacket& packet)
31  {
32  // out << packet.fBuffer.substr(TCPPacket::headerLength);
33  out << packet.fBuffer;
34 
35  return out;
36  }
37 
38  private:
39  static constexpr uint32_t headerLength = 4;
40 
41  std::string fBuffer;
42 };
43 } // namespace ots
44 #endif
void reset(void)
Resets the storage buffer.
Definition: TCPPacket.cc:46
friend std::ostream & operator<<(std::ostream &out, const TCPPacket &packet)
Definition: TCPPacket.h:30
TCPPacket & operator+=(const std::string &buffer)
Operator overload.
Definition: TCPPacket.h:24