Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/content/supported_formats/supporting_your_own_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions include/rfl/boost_serialization/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions include/rfl/cereal/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions include/rfl/parsing/Parent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ struct Parent {
return add_array(_w, _size, _parent);
} else if constexpr (std::is_same_v<Type, Array>) {
return _w.add_fixed_array_to_array(_size, _parent.arr_);
} else if constexpr (is_map_entry<Type>()) {
return _w.add_fixed_array_to_map_entry(_size, _parent.entry_);
} else if constexpr (std::is_same_v<Type, Object>) {
return _w.add_fixed_array_to_object(_parent.name_, _size, _parent.obj_);
} else if constexpr (std::is_same_v<Type, Root>) {
Expand Down
5 changes: 5 additions & 0 deletions include/rfl/yas/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions tests/check_fixed_array_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, Array> fixed_values{{7, input}};
const std::map<int, std::vector<std::int32_t>> 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<std::int32_t, 0> empty{};
EXPECT_EQ(write(empty).size(), header_size);
check_roundtrip(empty, write, read);
Expand Down
5 changes: 5 additions & 0 deletions tests/test_typed_maps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <gtest/gtest.h>

#include <array>
#include <cmath>
#include <cstdint>
#include <functional>
Expand Down Expand Up @@ -47,6 +48,10 @@ inline void check(const auto& write, const auto& read) {
std::unordered_map<int, std::string>{{-7, "a"}, {42, "b"}});
roundtrip(write, read, std::map<bool, int>{{false, 1}, {true, 2}});
roundtrip(write, read, std::map<std::string, int>{{"", 1}, {"42", 2}});
roundtrip(write, read,
std::map<int, std::array<int, 2>>{{1, {2, 3}}, {4, {5, 6}}});
roundtrip(write, read,
std::map<int, std::array<int, 0>>{{1, {}}, {2, {}}});

roundtrip(write, read, std::map<int, int, std::greater<int>>{{1, 2}, {3, 4}});
roundtrip(write, read,
Expand Down
Loading