26 #ifndef _AMPS_COMPOSITEMESSAGEBUILDER_HPP_ 27 #define _AMPS_COMPOSITEMESSAGEBUILDER_HPP_ 43 static const size_t DEFAULT_INITIAL_CAPACITY = 16 * 1024;
44 static const size_t PART_HEADER_LENGTH = 4;
50 DEFAULT_INITIAL_CAPACITY);
77 const char*
data(
void)
const;
89 void _resize(
size_t required_);
97 : _data(new char[initialCapacity_]),
99 _capacity(initialCapacity_)
102 inline CompositeMessageBuilder::~CompositeMessageBuilder(
void)
111 size_t length = data_.length();
112 size_t required = _position + length + PART_HEADER_LENGTH;
113 if (_capacity < required)
117 char* p = _data + _position;
118 *p++ = (char)((length & 0xFF000000) >> 24);
119 *p++ = (char)((length & 0x00FF0000) >> 16);
120 *p++ = (char)((length & 0x0000FF00) >> 8);
121 *p++ = (char)((length & 0x000000FF) );
122 memcpy(p, data_.c_str(),
length);
123 _position += length + PART_HEADER_LENGTH;
129 size_t required = _position + length_ + PART_HEADER_LENGTH;
130 if (_capacity < required)
134 char* p = _data + _position;
135 *p++ = (char)((length_ & 0xFF000000) >> 24);
136 *p++ = (char)((length_ & 0x00FF0000) >> 16);
137 *p++ = (char)((length_ & 0x0000FF00) >> 8);
138 *p++ = (char)((length_ & 0x000000FF) );
139 memcpy(p, data_, length_);
140 _position += length_ + PART_HEADER_LENGTH;
160 CompositeMessageBuilder::_resize(
size_t required_)
162 if (required_ <= _capacity)
166 char* newData =
new char[required_];
167 memcpy(newData, _data, _position);
170 _capacity = required_;
const char * data(void) const
Returns the composite message's data.
Definition: CompositeMessageBuilder.hpp:144
CompositeMessageBuilder & append(const std::string &data_)
Appends a message part to this object.
Definition: CompositeMessageBuilder.hpp:109
size_t length(void) const
Returns the length of the composite message's data.
Definition: CompositeMessageBuilder.hpp:149
Used to create payloads for AMPS composite messages, which are messages with a number of parts where ...
Definition: CompositeMessageBuilder.hpp:40
CompositeMessageBuilder & clear(void)
Clears this object.
Definition: CompositeMessageBuilder.hpp:154
CompositeMessageBuilder(size_t initialCapacity_=DEFAULT_INITIAL_CAPACITY)
Create a new, empty CompositeMessageBuilder.
Definition: CompositeMessageBuilder.hpp:96
Definition: ampsplusplus.hpp:102