Byte array parameter rename (#428)
* rename bytes_value to byte_values * adapt enum to new names * rename byte_values to byte_array_values * linters
This commit is contained in:
parent
e08c80052a
commit
e4b5c0bbb9
2 changed files with 16 additions and 14 deletions
|
@ -38,7 +38,7 @@ enum ParameterType
|
|||
PARAMETER_INTEGER = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER,
|
||||
PARAMETER_DOUBLE = rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE,
|
||||
PARAMETER_STRING = rcl_interfaces::msg::ParameterType::PARAMETER_STRING,
|
||||
PARAMETER_BYTES = rcl_interfaces::msg::ParameterType::PARAMETER_BYTES,
|
||||
PARAMETER_BYTE_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY,
|
||||
};
|
||||
|
||||
// Structure to store an arbitrary parameter with templated get/set methods
|
||||
|
@ -62,7 +62,9 @@ public:
|
|||
RCLCPP_PUBLIC
|
||||
explicit ParameterVariant(const std::string & name, const char * string_value);
|
||||
RCLCPP_PUBLIC
|
||||
explicit ParameterVariant(const std::string & name, const std::vector<uint8_t> & bytes_value);
|
||||
explicit ParameterVariant(
|
||||
const std::string & name,
|
||||
const std::vector<uint8_t> & byte_array_value);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
ParameterType
|
||||
|
@ -128,14 +130,14 @@ public:
|
|||
|
||||
template<ParameterType type>
|
||||
typename std::enable_if<
|
||||
type == ParameterType::PARAMETER_BYTES, const std::vector<uint8_t> &>::type
|
||||
type == ParameterType::PARAMETER_BYTE_ARRAY, const std::vector<uint8_t> &>::type
|
||||
get_value() const
|
||||
{
|
||||
if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BYTES) {
|
||||
if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY) {
|
||||
// TODO(wjwwood): use custom exception
|
||||
throw std::runtime_error("Invalid type");
|
||||
}
|
||||
return value_.bytes_value;
|
||||
return value_.byte_array_value;
|
||||
}
|
||||
|
||||
// The following get_value() variants allow the use of primitive types
|
||||
|
@ -175,7 +177,7 @@ public:
|
|||
type, const std::vector<uint8_t> &>::value, const std::vector<uint8_t> &>::type
|
||||
get_value() const
|
||||
{
|
||||
return get_value<ParameterType::PARAMETER_BYTES>();
|
||||
return get_value<ParameterType::PARAMETER_BYTE_ARRAY>();
|
||||
}
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
|
|
|
@ -76,11 +76,11 @@ ParameterVariant::ParameterVariant(const std::string & name, const char * string
|
|||
{}
|
||||
|
||||
ParameterVariant::ParameterVariant(
|
||||
const std::string & name, const std::vector<uint8_t> & bytes_value)
|
||||
const std::string & name, const std::vector<uint8_t> & byte_array_value)
|
||||
: name_(name)
|
||||
{
|
||||
value_.bytes_value = bytes_value;
|
||||
value_.type = rcl_interfaces::msg::ParameterType::PARAMETER_BYTES;
|
||||
value_.byte_array_value = byte_array_value;
|
||||
value_.type = rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY;
|
||||
}
|
||||
|
||||
ParameterType
|
||||
|
@ -101,7 +101,7 @@ ParameterVariant::get_type_name() const
|
|||
return "double";
|
||||
case rclcpp::parameter::ParameterType::PARAMETER_STRING:
|
||||
return "string";
|
||||
case rclcpp::parameter::ParameterType::PARAMETER_BYTES:
|
||||
case rclcpp::parameter::ParameterType::PARAMETER_BYTE_ARRAY:
|
||||
return "bytes";
|
||||
case rclcpp::parameter::ParameterType::PARAMETER_NOT_SET:
|
||||
return "not set";
|
||||
|
@ -152,7 +152,7 @@ ParameterVariant::as_bool() const
|
|||
const std::vector<uint8_t> &
|
||||
ParameterVariant::as_bytes() const
|
||||
{
|
||||
return get_value<ParameterType::PARAMETER_BYTES>();
|
||||
return get_value<ParameterType::PARAMETER_BYTE_ARRAY>();
|
||||
}
|
||||
|
||||
ParameterVariant
|
||||
|
@ -167,8 +167,8 @@ ParameterVariant::from_parameter(const rcl_interfaces::msg::Parameter & paramete
|
|||
return ParameterVariant(parameter.name, parameter.value.double_value);
|
||||
case PARAMETER_STRING:
|
||||
return ParameterVariant(parameter.name, parameter.value.string_value);
|
||||
case PARAMETER_BYTES:
|
||||
return ParameterVariant(parameter.name, parameter.value.bytes_value);
|
||||
case PARAMETER_BYTE_ARRAY:
|
||||
return ParameterVariant(parameter.name, parameter.value.byte_array_value);
|
||||
case PARAMETER_NOT_SET:
|
||||
throw std::runtime_error("Type from ParameterValue is not set");
|
||||
default:
|
||||
|
@ -201,7 +201,7 @@ ParameterVariant::value_to_string() const
|
|||
return std::to_string(as_double());
|
||||
case rclcpp::parameter::ParameterType::PARAMETER_STRING:
|
||||
return as_string();
|
||||
case rclcpp::parameter::ParameterType::PARAMETER_BYTES:
|
||||
case rclcpp::parameter::ParameterType::PARAMETER_BYTE_ARRAY:
|
||||
{
|
||||
std::stringstream bytes;
|
||||
bool first_byte = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue