Skip to content

Commit

Permalink
SerializationText: Support bool data types for JSON serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagghiu committed Jul 31, 2024
1 parent 924a797 commit 1783a3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Libraries/SerializationText/SerializationJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ bool SC::SerializationJson::Reader::getNextField(uint32_t index, StringView& tex
return token.getType() == JsonTokenizer::Token::Colon;
}

bool SC::SerializationJson::Reader::serialize(uint32_t index, bool& value)
{
SC_COMPILER_UNUSED(value);
SC_TRY(eventuallyExpectComma(index));
JsonTokenizer::Token token;
SC_TRY(JsonTokenizer::tokenizeNext(iterator, token));
if (token.getType() == JsonTokenizer::Token::True)
{
value = true;
return true;
}
if (token.getType() == JsonTokenizer::Token::False)
{
value = false;
return true;
}
return false;
}

bool SC::SerializationJson::Reader::serialize(uint32_t index, float& value)
{
SC_COMPILER_UNUSED(value);
Expand Down
1 change: 1 addition & 0 deletions Libraries/SerializationText/SerializationJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ struct SC::SerializationJson
[[nodiscard]] bool startObjectField(uint32_t index, StringView text);
[[nodiscard]] bool getNextField(uint32_t index, StringView& text, bool& hasMore);

[[nodiscard]] bool serialize(uint32_t index, bool& value);
[[nodiscard]] bool serialize(uint32_t index, float& value);
[[nodiscard]] bool serialize(uint32_t index, int32_t& value);
[[nodiscard]] bool serialize(uint32_t index, String& text);
Expand Down

0 comments on commit 1783a3a

Please sign in to comment.