You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stduuid is great, and I like how it provides uuids::to_string() and operator<< to serialize the contents.
However, both of these functions create a std::string as the destination buffer for the serialized results. When serializing UUIDs as part of a larger sequence, such as serializing to JSON or an error message, this is inefficient.
From the implementation of uuids::to_string(), shown below, it appears that any forward output range could be used.
Would it be possible to offer a more generic serialization function/overloads such that any range/iterators with the necessary traits could be used? This would not only make serializing UUIDs to larger buffers more efficient but would also support serializing to sequences other than std::string.
Am I interpreting the existing code correctly?
If so, I'm happy to contribute any necessary changes, but I'm not sure how contributions must be made as this is a reference implementation for standards.
template <classCharT,
classTraits,
classAllocator>
[[nodiscard]] inline std::basic_string<CharT, Traits, Allocator> to_string(uuid const & id)
{
std::basic_string<CharT, Traits, Allocator> uustr{detail::empty_guid<CharT>};
for (size_t i = 0, index = 0; i < 36; ++i)
{
if (i == 8 || i == 13 || i == 18 || i == 23)
{
continue;
}
uustr[i] = detail::guid_encoder<CharT>[id.data[index] >> 4 & 0x0f];
uustr[++i] = detail::guid_encoder<CharT>[id.data[index] & 0x0f];
index++;
}
return uustr;
}
The text was updated successfully, but these errors were encountered:
stduuid is great, and I like how it provides
uuids::to_string()
andoperator<<
to serialize the contents.However, both of these functions create a
std::string
as the destination buffer for the serialized results. When serializing UUIDs as part of a larger sequence, such as serializing to JSON or an error message, this is inefficient.From the implementation of
uuids::to_string()
, shown below, it appears that any forward output range could be used.Would it be possible to offer a more generic serialization function/overloads such that any range/iterators with the necessary traits could be used? This would not only make serializing UUIDs to larger buffers more efficient but would also support serializing to sequences other than
std::string
.Am I interpreting the existing code correctly?
If so, I'm happy to contribute any necessary changes, but I'm not sure how contributions must be made as this is a reference implementation for standards.
The text was updated successfully, but these errors were encountered: