12 #define private public 13 #include <topic_tools/shape_shifter.h> 21 #include <boost/shared_ptr.hpp> 23 #include <ros/common.h> 25 #include <std_msgs/Header.h> 35 #if ROS_VERSION_MINIMUM(1, 15, 0) 49 if (newLength == msg.
size())
52 msg.
msgBuf.resize(newLength);
74 if (newLength == msg.
size())
76 if (newLength < msg.
size())
84 msg.
msgBuf =
new uint8_t[newLength];
88 std::memcpy(msg.
msgBuf, oldBuf, oldLength);
120 auto p = boost::make_shared<std_msgs::Header>();
129 return cras::nullopt;
136 if (!oldHeader.has_value())
141 const auto oldLength = msg.
size();
142 const auto newLength = oldLength + newHeaderLength - oldHeaderLength;
144 if (oldHeaderLength == newHeaderLength)
158 else if (newHeaderLength < oldHeaderLength)
167 std::memmove(buffer + newHeaderLength, buffer + oldHeaderLength, oldLength - oldHeaderLength);
180 std::memmove(buffer + newHeaderLength, buffer + oldHeaderLength, oldLength - oldHeaderLength);
194 #if ROS_VERSION_MINIMUM(1, 15, 0) 201 ShapeShifter(reinterpret_cast<const ShapeShifter&>(other))
212 return operator=(reinterpret_cast<const ShapeShifter&>(other));
217 return operator=(reinterpret_cast<ShapeShifter &&>(other));
222 this->
md5 = other.md5;
226 this->
typed = other.typed;
228 if (other.msgBuf !=
nullptr && other.msgBufUsed > 0)
230 this->
msgBuf =
new uint8_t[other.msgBufUsed];
231 memcpy(this->
msgBuf, other.msgBuf, other.msgBufUsed);
256 this->
md5 = other.md5;
260 this->
typed = other.typed;
262 if (other.msgBuf !=
nullptr && other.msgBufUsed > 0)
267 this->
msgBuf =
new uint8_t[other.msgBufUsed];
270 memcpy(this->
msgBuf, other.msgBuf, other.msgBufUsed);
272 else if (this->
msgBuf !=
nullptr)
void copyShapeShifter(const ::topic_tools::ShapeShifter &in, ::topic_tools::ShapeShifter &out)
Copy in ShapeShifter to out.
uint8_t * getBuffer(::topic_tools::ShapeShifter &msg)
Get the internal buffer with serialized message data.
ShapeShifter & operator=(const ::topic_tools::ShapeShifter &other)
::cras::optional<::std_msgs::Header > getHeader(const ::topic_tools::ShapeShifter &msg)
Get the header field of the given message, if it has any.
void serialize(Stream &stream, const T &t)
Tools for more convenient working with ShapeShifter objects.
bool setHeader(::topic_tools::ShapeShifter &msg, ::std_msgs::Header &header)
Change the header field of the given message, if it has any.
size_t getBufferLength(const ::topic_tools::ShapeShifter &msg)
Get the length of the internal buffer with serialized message data.
void resizeBuffer(::topic_tools::ShapeShifter &msg, size_t newLength)
Resize the internal buffer of the message.
uint32_t serializationLength(const T &t)
ShapeShifter class with fixed behavior on copy/move on Melodic. Use this class everywhere possible to...
bool contains(const ::std::string &str, char c)
bool hasHeader(const ::topic_tools::ShapeShifter &msg)
Tell whether the given message has header field.
void deserialize(Stream &stream, T &t)