diff --git a/docs/content/supported_formats/supporting_your_own_format.md b/docs/content/supported_formats/supporting_your_own_format.md index e745b3ce..7fafcf10 100644 --- a/docs/content/supported_formats/supporting_your_own_format.md +++ b/docs/content/supported_formats/supporting_your_own_format.md @@ -455,6 +455,8 @@ A writer defines an `OutputMapEntryType` context and the following methods: ```cpp OutputMapEntryType map_entry(OutputMapType* map) const; OutputArrayType add_array_to_map_entry(size_t size, OutputMapEntryType*) const; +// Additionally required if the writer provides fixed_array_as_root: +OutputArrayType add_fixed_array_to_map_entry(size_t size, OutputMapEntryType*) const; OutputObjectType add_object_to_map_entry(size_t size, OutputMapEntryType*) const; OutputVarType add_null_to_map_entry(OutputMapEntryType*) const; diff --git a/include/rfl/boost_serialization/Writer.hpp b/include/rfl/boost_serialization/Writer.hpp index 56b2f84c..a5fb795f 100644 --- a/include/rfl/boost_serialization/Writer.hpp +++ b/include/rfl/boost_serialization/Writer.hpp @@ -41,6 +41,11 @@ class Writer { return array_as_root(_size); } + OutputArrayType add_fixed_array_to_map_entry(const size_t _size, + OutputMapEntryType*) const { + return fixed_array_as_root(_size); + } + OutputObjectType add_object_to_map_entry(const size_t _size, OutputMapEntryType*) const { return object_as_root(_size); diff --git a/include/rfl/cereal/Writer.hpp b/include/rfl/cereal/Writer.hpp index 55e3585b..030ac20f 100644 --- a/include/rfl/cereal/Writer.hpp +++ b/include/rfl/cereal/Writer.hpp @@ -52,6 +52,11 @@ class Writer { return array_as_root(_size); } + OutputArrayType add_fixed_array_to_map_entry(const size_t _size, + OutputMapEntryType*) const { + return fixed_array_as_root(_size); + } + OutputObjectType add_object_to_map_entry(const size_t _size, OutputMapEntryType*) const { return object_as_root(_size); diff --git a/include/rfl/parsing/Parent.hpp b/include/rfl/parsing/Parent.hpp index 14090a27..2fae3405 100644 --- a/include/rfl/parsing/Parent.hpp +++ b/include/rfl/parsing/Parent.hpp @@ -99,6 +99,8 @@ struct Parent { return add_array(_w, _size, _parent); } else if constexpr (std::is_same_v) { return _w.add_fixed_array_to_array(_size, _parent.arr_); + } else if constexpr (is_map_entry()) { + return _w.add_fixed_array_to_map_entry(_size, _parent.entry_); } else if constexpr (std::is_same_v) { return _w.add_fixed_array_to_object(_parent.name_, _size, _parent.obj_); } else if constexpr (std::is_same_v) { diff --git a/include/rfl/yas/Writer.hpp b/include/rfl/yas/Writer.hpp index 24a8d791..aca68d3c 100644 --- a/include/rfl/yas/Writer.hpp +++ b/include/rfl/yas/Writer.hpp @@ -53,6 +53,11 @@ struct Writer { return array_as_root(_size); } + OutputArrayType add_fixed_array_to_map_entry(const size_t _size, + OutputMapEntryType*) const { + return fixed_array_as_root(_size); + } + OutputObjectType add_object_to_map_entry(const size_t _size, OutputMapEntryType*) const { return object_as_root(_size); diff --git a/tests/check_fixed_array_io.hpp b/tests/check_fixed_array_io.hpp index 535f3e04..3c3c4d00 100644 --- a/tests/check_fixed_array_io.hpp +++ b/tests/check_fixed_array_io.hpp @@ -33,6 +33,13 @@ void check_sizes(Write write, Read read, const size_t prefix_size) { bytes.size() + prefix_size); check_roundtrip(input, write, read); + const std::map fixed_values{{7, input}}; + const std::map> dynamic_values{ + {7, {input.begin(), input.end()}}}; + EXPECT_EQ(write(dynamic_values).size(), + write(fixed_values).size() + prefix_size); + check_roundtrip(fixed_values, write, read); + const std::array empty{}; EXPECT_EQ(write(empty).size(), header_size); check_roundtrip(empty, write, read); diff --git a/tests/test_typed_maps.hpp b/tests/test_typed_maps.hpp index 7c3a8cde..d63e148a 100644 --- a/tests/test_typed_maps.hpp +++ b/tests/test_typed_maps.hpp @@ -3,6 +3,7 @@ #include +#include #include #include #include @@ -47,6 +48,10 @@ inline void check(const auto& write, const auto& read) { std::unordered_map{{-7, "a"}, {42, "b"}}); roundtrip(write, read, std::map{{false, 1}, {true, 2}}); roundtrip(write, read, std::map{{"", 1}, {"42", 2}}); + roundtrip(write, read, + std::map>{{1, {2, 3}}, {4, {5, 6}}}); + roundtrip(write, read, + std::map>{{1, {}}, {2, {}}}); roundtrip(write, read, std::map>{{1, 2}, {3, 4}}); roundtrip(write, read,