15 #ifndef RMW_FASTRTPS_SHARED_CPP__GUID_UTILS_HPP_
16 #define RMW_FASTRTPS_SHARED_CPP__GUID_UTILS_HPP_
21 #include <type_traits>
23 #include "fastrtps/rtps/common/Guid.h"
28 template<
typename ByteT>
31 const ByteT * guid_byte_array,
32 eprosima::fastrtps::rtps::GUID_t * guid)
36 "ByteT should be either int8_t or uint8_t");
37 assert(guid_byte_array);
39 constexpr
auto prefix_size =
sizeof(guid->guidPrefix.value);
40 memcpy(guid->guidPrefix.value, guid_byte_array, prefix_size);
41 memcpy(guid->entityId.value, &guid_byte_array[prefix_size], guid->entityId.size);
44 template<
typename ByteT>
47 const eprosima::fastrtps::rtps::GUID_t & guid,
48 ByteT * guid_byte_array)
52 "ByteT should be either int8_t or uint8_t");
53 assert(guid_byte_array);
54 constexpr
auto prefix_size =
sizeof(guid.guidPrefix.value);
55 memcpy(guid_byte_array, &guid.guidPrefix, prefix_size);
56 memcpy(&guid_byte_array[prefix_size], &guid.entityId, guid.entityId.size);
64 uint8_t plain_value[
sizeof(guid)];
65 uint32_t plain_ints[
sizeof(guid) /
sizeof(uint32_t)];
70 sizeof(u.plain_value) ==
sizeof(u.plain_ints) &&
71 offsetof(u_convert, plain_value) == offsetof(u_convert, plain_ints),
72 "Plain guid should be easily convertible to uint32_t[4]");
80 size_t ret_val = prime_1 * u.plain_ints[0];
81 ret_val = prime_2 * (u.plain_ints[1] + ret_val);
82 ret_val = prime_3 * (u.plain_ints[2] + ret_val);
83 ret_val = u.plain_ints[3] + ret_val;
91 #endif // RMW_FASTRTPS_SHARED_CPP__GUID_UTILS_HPP_