diff --git a/examples/universal/z_bytes.cxx b/examples/universal/z_bytes.cxx index 9bbda18..cc8646f 100644 --- a/examples/universal/z_bytes.cxx +++ b/examples/universal/z_bytes.cxx @@ -91,6 +91,16 @@ int _main(int argc, char** argv) { assert(input == output); } +// Span +#if __cplusplus >= 202002L + { + double input[] = {1.0, 2.0, 3.0, 4.0}; + const auto payload = ext::serialize(std::span(input)); + const auto output = ext::deserialize>(payload); + assert(std::equal(std::begin(input), std::end(input), std::begin(output))); + } +#endif + // Serializer, deserializer (for struct or tuple serialization) { // serialization @@ -171,4 +181,4 @@ int main(int argc, char** argv) { } catch (ZException e) { std::cout << "Received an error :" << e.what() << "\n"; } -} \ No newline at end of file +} diff --git a/include/zenoh/api/ext/serialization.hxx b/include/zenoh/api/ext/serialization.hxx index 416aa47..b235462 100644 --- a/include/zenoh/api/ext/serialization.hxx +++ b/include/zenoh/api/ext/serialization.hxx @@ -13,6 +13,9 @@ #pragma once +#if __cplusplus >= 202002L +#include +#endif #include #include #include @@ -236,6 +239,13 @@ bool __zenoh_serialize_with_serializer(zenoh::ext::Serializer& serializer, const return __serialize_sequence_with_serializer(serializer, value.begin(), value.end(), value.size(), err); } +#if __cplusplus >= 202002L +template +bool __zenoh_serialize_with_serializer(zenoh::ext::Serializer& serializer, std::span value, ZResult* err) { + return __serialize_sequence_with_serializer(serializer, value.begin(), value.end(), value.size(), err); +} +#endif + template bool serialize_with_serializer(zenoh::ext::Serializer& serializer, const T& t, ZResult* err) { return __zenoh_serialize_with_serializer(serializer, t, err);