Skip to content

Commit 5b58239

Browse files
committed
Added rosidl::Buffer support.
1 parent 9256f1b commit 5b58239

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

ros_babel_fish/include/ros_babel_fish/messages/array_message.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ class ArrayMessage_ final : public ArrayMessageBase
149149
throw std::length_error( "Exceeded upper bound!" );
150150
}
151151
}
152-
reinterpret_cast<std::vector<T> *>( data_.get() )->push_back( value );
152+
// resize() + assign() route through the introspection function pointers when present
153+
// (and fall back to a std::vector cast only when they are null), so this works for
154+
// rosidl::Buffer-backed arrays (e.g. uint8[]) as well as plain std::vector members.
155+
const size_t index = size();
156+
resize( index + 1 );
157+
assign( index, value );
153158
}
154159

155160
//! Alias for push_back

ros_babel_fish/test/common.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <ros_babel_fish_test_msgs/msg/test_array.hpp>
99

10+
#include <rosidl_buffer/buffer.hpp>
11+
1012
#include <random>
1113
#include <vector>
1214

@@ -35,6 +37,12 @@ void fillArray( std::vector<bool> &msg, unsigned seed )
3537
for ( size_t i = 0; i < length; ++i ) { msg.push_back( distribution( generator ) == 1 ); }
3638
}
3739

40+
template<typename T>
41+
void fillArray( rosidl::Buffer<T> &msg, unsigned seed )
42+
{
43+
fillArray( static_cast<std::vector<T> &>( msg ), seed );
44+
}
45+
3846
template<typename T, size_t L>
3947
void fillArray( rosidl_runtime_cpp::BoundedVector<T, L> &msg, unsigned seed )
4048
{

ros_babel_fish/test/message_comparison.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ bool MessageContentEqualImpl( const ros_babel_fish::Message &a, const std::vecto
293293
return ArrayContentEqualImpl( arr.template as<ArrayMessage<T>>(), b, path, result );
294294
}
295295

296+
template<typename T, typename A>
297+
bool MessageContentEqualImpl( const ros_babel_fish::Message &a, const rosidl::Buffer<T, A> &b,
298+
const std::string &path, ::testing::AssertionResult &result )
299+
{
300+
return MessageContentEqualImpl( a, static_cast<const std::vector<T, A> &>( b ), path, result );
301+
}
302+
296303
template<typename T, size_t L>
297304
bool MessageContentEqualImpl( const ros_babel_fish::Message &a, const std::array<T, L> &b,
298305
const std::string &path, ::testing::AssertionResult &result )

0 commit comments

Comments
 (0)