Skip to content

Commit 219bf84

Browse files
authored
feat(autoware_utils_uuid): split package (#39)
* feat(autoware_utils_uuid): split package Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * update for compatibility Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> --------- Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent 0740af5 commit 219bf84

File tree

9 files changed

+160
-61
lines changed

9 files changed

+160
-61
lines changed

autoware_utils/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ The ROS module provides utilities for working with ROS messages and nodes:
4343
- **`published_time_publisher.hpp`**: Tracks and publishes the time when messages are published.
4444
- **`self_pose_listener.hpp`**: Listens to the self-pose of the vehicle.
4545
- **`update_param.hpp`**: Updates parameters from remote nodes.
46-
- **`uuid_helper.hpp`**: Utilities for generating and managing UUIDs.
4746
- **`wait_for_param.hpp`**: Waits for parameters from remote nodes.
4847
- **`debug_traits.hpp`**: Traits for identifying debug message types.
4948

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Tier IV, Inc.
1+
// Copyright 2025 The Autoware Contributors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,58 +15,14 @@
1515
#ifndef AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_
1616
#define AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_
1717

18-
#include <unique_identifier_msgs/msg/uuid.hpp>
18+
// NOLINTBEGIN(build/namespaces, whitespace/line_length)
19+
// clang-format off
1920

20-
#include <boost/uuid/uuid.hpp>
21+
#pragma message("#include <autoware_utils/ros/uuid_helper.hpp> is deprecated. Use #include <autoware_utils_uuid/uuid_helper.hpp> instead.")
22+
#include <autoware_utils_uuid/uuid_helper.hpp>
23+
namespace autoware_utils { using namespace autoware_utils_uuid; }
2124

22-
#include <algorithm>
23-
#include <random>
24-
#include <string>
25-
26-
namespace autoware_utils
27-
{
28-
inline unique_identifier_msgs::msg::UUID generate_uuid()
29-
{
30-
// Generate random number
31-
unique_identifier_msgs::msg::UUID uuid;
32-
std::mt19937 gen(std::random_device{}());
33-
std::independent_bits_engine<std::mt19937, 8, uint8_t> bit_eng(gen);
34-
std::generate(uuid.uuid.begin(), uuid.uuid.end(), bit_eng);
35-
36-
return uuid;
37-
}
38-
inline unique_identifier_msgs::msg::UUID generate_default_uuid()
39-
{
40-
// Generate UUID with all zeros
41-
unique_identifier_msgs::msg::UUID default_uuid;
42-
// Use std::generate to fill the UUID with zeros
43-
std::generate(default_uuid.uuid.begin(), default_uuid.uuid.end(), []() { return 0; });
44-
45-
return default_uuid;
46-
}
47-
inline std::string to_hex_string(const unique_identifier_msgs::msg::UUID & id)
48-
{
49-
std::stringstream ss;
50-
for (auto i = 0; i < 16; ++i) {
51-
ss << std::hex << std::setfill('0') << std::setw(2) << +id.uuid[i];
52-
}
53-
return ss.str();
54-
}
55-
56-
inline boost::uuids::uuid to_boost_uuid(const unique_identifier_msgs::msg::UUID & id)
57-
{
58-
boost::uuids::uuid boost_uuid{};
59-
std::copy(id.uuid.begin(), id.uuid.end(), boost_uuid.begin());
60-
return boost_uuid;
61-
}
62-
63-
inline unique_identifier_msgs::msg::UUID to_uuid_msg(const boost::uuids::uuid & id)
64-
{
65-
unique_identifier_msgs::msg::UUID ros_uuid{};
66-
std::copy(id.begin(), id.end(), ros_uuid.uuid.begin());
67-
return ros_uuid;
68-
}
69-
70-
} // namespace autoware_utils
25+
// clang-format on
26+
// NOLINTEND
7127

7228
#endif // AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_

autoware_utils/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<depend>autoware_utils_math</depend>
2525
<depend>autoware_utils_pcl</depend>
2626
<depend>autoware_utils_system</depend>
27+
<depend>autoware_utils_uuid</depend>
2728
<depend>autoware_utils_visualization</depend>
2829
<depend>autoware_vehicle_msgs</depend>
2930
<depend>builtin_interfaces</depend>

autoware_utils_uuid/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(autoware_utils_uuid)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
if(BUILD_TESTING)
8+
file(GLOB_RECURSE test_files test/*.cpp)
9+
ament_auto_add_gtest(test_${PROJECT_NAME} ${test_files})
10+
endif()
11+
12+
ament_auto_package()

autoware_utils_uuid/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# autoware_utils_uuid
2+
3+
## Overview
4+
5+
The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications.
6+
This package provides essential utilities for UUID.
7+
It is extensively used in the Autoware project to handle common tasks such as generation and conversion of UUID.
8+
9+
## Design
10+
11+
- **`uuid_helper.hpp`**: Utilities for generating and managing UUIDs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2022 Tier IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef AUTOWARE_UTILS_UUID__UUID_HELPER_HPP_
16+
#define AUTOWARE_UTILS_UUID__UUID_HELPER_HPP_
17+
18+
#include <unique_identifier_msgs/msg/uuid.hpp>
19+
20+
#include <boost/uuid/uuid.hpp>
21+
22+
#include <algorithm>
23+
#include <random>
24+
#include <string>
25+
26+
namespace autoware_utils_uuid
27+
{
28+
29+
inline unique_identifier_msgs::msg::UUID generate_uuid()
30+
{
31+
// Generate random number
32+
unique_identifier_msgs::msg::UUID uuid;
33+
std::mt19937 gen(std::random_device{}());
34+
std::independent_bits_engine<std::mt19937, 8, uint8_t> bit_eng(gen);
35+
std::generate(uuid.uuid.begin(), uuid.uuid.end(), bit_eng);
36+
37+
return uuid;
38+
}
39+
inline unique_identifier_msgs::msg::UUID generate_default_uuid()
40+
{
41+
// Generate UUID with all zeros
42+
unique_identifier_msgs::msg::UUID default_uuid;
43+
// Use std::generate to fill the UUID with zeros
44+
std::generate(default_uuid.uuid.begin(), default_uuid.uuid.end(), []() { return 0; });
45+
46+
return default_uuid;
47+
}
48+
inline std::string to_hex_string(const unique_identifier_msgs::msg::UUID & id)
49+
{
50+
std::stringstream ss;
51+
for (auto i = 0; i < 16; ++i) {
52+
ss << std::hex << std::setfill('0') << std::setw(2) << +id.uuid[i];
53+
}
54+
return ss.str();
55+
}
56+
57+
inline boost::uuids::uuid to_boost_uuid(const unique_identifier_msgs::msg::UUID & id)
58+
{
59+
boost::uuids::uuid boost_uuid{};
60+
std::copy(id.uuid.begin(), id.uuid.end(), boost_uuid.begin());
61+
return boost_uuid;
62+
}
63+
64+
inline unique_identifier_msgs::msg::UUID to_uuid_msg(const boost::uuids::uuid & id)
65+
{
66+
unique_identifier_msgs::msg::UUID ros_uuid{};
67+
std::copy(id.begin(), id.end(), ros_uuid.uuid.begin());
68+
return ros_uuid;
69+
}
70+
71+
} // namespace autoware_utils_uuid
72+
73+
#endif // AUTOWARE_UTILS_UUID__UUID_HELPER_HPP_

autoware_utils_uuid/package.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>autoware_utils_uuid</name>
5+
<version>1.1.0</version>
6+
<description>The autoware_utils_uuid package</description>
7+
<maintainer email="egon.kang@autocore.ai">Jian Kang</maintainer>
8+
<maintainer email="ryohsuke.mitsudome@tier4.jp">Ryohsuke Mitsudome</maintainer>
9+
<maintainer email="esteve.fernandez@tier4.jp">Esteve Fernandez</maintainer>
10+
<maintainer email="yutaka.kondo@tier4.jp">Yutaka Kondo</maintainer>
11+
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
12+
<license>Apache License 2.0</license>
13+
14+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
15+
<buildtool_depend>autoware_cmake</buildtool_depend>
16+
17+
<depend>libboost-system-dev</depend>
18+
<depend>unique_identifier_msgs</depend>
19+
20+
<test_depend>ament_lint_auto</test_depend>
21+
<test_depend>autoware_lint_common</test_depend>
22+
23+
<export>
24+
<build_type>ament_cmake</build_type>
25+
</export>
26+
</package>

autoware_utils/test/src/ros/test_uuid_helper.cpp autoware_utils_uuid/test/cases/uuid_helper.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "autoware_utils/ros/uuid_helper.hpp"
15+
#include "autoware_utils_uuid/uuid_helper.hpp"
1616

1717
#include <boost/uuid/uuid_generators.hpp>
1818

@@ -24,18 +24,18 @@ TEST(UUIDHelperTest, generate_uuid)
2424
{
2525
// Generate two UUIDs and ensure they are all different
2626

27-
unique_identifier_msgs::msg::UUID uuid1 = autoware_utils::generate_uuid();
28-
unique_identifier_msgs::msg::UUID uuid2 = autoware_utils::generate_uuid();
27+
unique_identifier_msgs::msg::UUID uuid1 = autoware_utils_uuid::generate_uuid();
28+
unique_identifier_msgs::msg::UUID uuid2 = autoware_utils_uuid::generate_uuid();
2929

3030
EXPECT_FALSE(uuid1 == uuid2) << "Duplicate UUID generated: "
31-
<< autoware_utils::to_hex_string(uuid2);
31+
<< autoware_utils_uuid::to_hex_string(uuid2);
3232
}
3333

3434
TEST(UUIDHelperTest, generate_default_uuid)
3535
{
3636
// Generate two UUIDs and ensure they are all different
3737

38-
unique_identifier_msgs::msg::UUID default_uuid = autoware_utils::generate_default_uuid();
38+
unique_identifier_msgs::msg::UUID default_uuid = autoware_utils_uuid::generate_default_uuid();
3939
unique_identifier_msgs::msg::UUID zero_uuid;
4040
std::fill(zero_uuid.uuid.begin(), zero_uuid.uuid.end(), 0x00);
4141

@@ -48,7 +48,7 @@ TEST(UUIDHelperTest, to_hex_string)
4848
// Populate the UUID with some values
4949
std::fill(uuid.uuid.begin(), uuid.uuid.end(), 0x42);
5050

51-
std::string hex_string = autoware_utils::to_hex_string(uuid);
51+
std::string hex_string = autoware_utils_uuid::to_hex_string(uuid);
5252

5353
// Check if the generated hex string is correct
5454
EXPECT_EQ(hex_string, "42424242424242424242424242424242");
@@ -64,14 +64,14 @@ TEST(UUIDHelperTest, to_boost_uuid)
6464
std::fill(boost_uuid.begin(), boost_uuid.end(), 0x42);
6565

6666
// Check if the conversion from ROS UUID to Boost UUID is correct
67-
EXPECT_TRUE(boost_uuid == autoware_utils::to_boost_uuid(uuid));
67+
EXPECT_TRUE(boost_uuid == autoware_utils_uuid::to_boost_uuid(uuid));
6868
}
6969

7070
TEST(UUIDHelperTest, to_uuid_msg)
7171
{
7272
boost::uuids::random_generator generator;
7373
boost::uuids::uuid boost_uuid = generator();
74-
unique_identifier_msgs::msg::UUID ros_uuid = autoware_utils::to_uuid_msg(boost_uuid);
74+
unique_identifier_msgs::msg::UUID ros_uuid = autoware_utils_uuid::to_uuid_msg(boost_uuid);
7575

7676
// Check if the conversion from Boost UUID to ROS UUID is correct
7777
EXPECT_TRUE(std::equal(boost_uuid.begin(), boost_uuid.end(), ros_uuid.uuid.begin()));

autoware_utils_uuid/test/main.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2025 The Autoware Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <gtest/gtest.h>
16+
17+
int main(int argc, char ** argv)
18+
{
19+
testing::InitGoogleTest(&argc, argv);
20+
return RUN_ALL_TESTS();
21+
}

0 commit comments

Comments
 (0)