Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for bool collections #4

Merged
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
7 changes: 4 additions & 3 deletions Serializable.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ namespace BSerializer {
};

requires requires(const typename _T::const_iterator CIt) {
{ *CIt } -> std::same_as<const typename _T::value_type&>;
requires std::same_as<decltype(*CIt), const typename _T::value_type&> ||
(std::same_as<typename _T::value_type, bool> && std::same_as<decltype(*CIt), bool>);
};

requires requires(typename _T::const_iterator CIt) {
Expand All @@ -99,8 +100,8 @@ namespace BSerializer {
{ CIt1 != CIt2 } -> std::same_as<bool>;
};

requires requires(const typename _T::value_type* const P1, const typename _T::value_type* const P2) {
_T{ P1, P2 };
requires requires(const std::initializer_list<typename _T::value_type> InitList) {
_T(InitList);
};
};

Expand Down
27 changes: 21 additions & 6 deletions Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,15 @@ __forceinline size_t BSerializer::SerializedSize(const _T& Value) {
}
else if constexpr (SerializableCollection<_T>) {
size_t t = sizeof(size_t);
for (auto& v : Value) {
t += SerializedSize(v);
if constexpr (std::same_as<decltype(*Value.cbegin()), bool>) {
for (bool v : Value) {
t += SerializedSize(v);
}
}
else {
for (auto& v : Value) {
t += SerializedSize(v);
}
}
return t;
}
Expand Down Expand Up @@ -337,9 +344,17 @@ __forceinline void BSerializer::Serialize(void*& Data, const _T& Value) {
size_t* lenLoc = (size_t*)Data;
Data = lenLoc + 1;
size_t len = 0;
for (auto& v : Value) {
Serialize(Data, v);
++len;
if constexpr (std::same_as<decltype(*Value.cbegin()), bool>) {
for (bool v : Value) {
Serialize(Data, v);
++len;
}
}
else {
for (auto& v : Value) {
Serialize(Data, v);
++len;
}
}
*lenLoc = ToFromLittleEndian(len);
}
Expand Down Expand Up @@ -383,7 +398,7 @@ __forceinline void BSerializer::Deserialize(const void*& Data, void* Value) {
value_t* arr = (value_t*)malloc(sizeof(value_t) * len);
value_t* b = arr + len;
for (value_t* i = arr; i < b; ++i) Deserialize(Data, i);
new (Value) _T{ arr, arr + len };
new (Value) _T(std::initializer_list<value_t>(arr, b));
free(arr);
}
else if constexpr (Arithmetic<_T>) {
Expand Down