5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef CHAT_MESSAGE_HPP
12 #define CHAT_MESSAGE_HPP
32 const char* data() const
44 return header_length + body_length_;
47 const char* body() const
49 return data_ + header_length;
54 return data_ + header_length;
57 size_t body_length() const
62 void body_length(size_t new_length)
64 body_length_ = new_length;
65 if (body_length_ > max_body_length)
66 body_length_ = max_body_length;
71 using namespace std; // For strncat and atoi.
72 char header[header_length + 1] = "";
73 strncat(header, data_, header_length);
74 body_length_ = atoi(header);
75 if (body_length_ > max_body_length)
85 using namespace std; // For sprintf and memcpy.
86 char header[header_length + 1] = "";
87 sprintf(header, "%4d", static_cast<int>(body_length_));
88 memcpy(data_, header, header_length);
92 char data_[header_length + max_body_length];
96 #endif // CHAT_MESSAGE_HPP