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

Feature/replace jsoncons #535

Merged
merged 9 commits into from
Nov 20, 2022

Conversation

Pheubel
Copy link
Contributor

@Pheubel Pheubel commented Nov 19, 2022

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Replaces jsoncons with nlohmann json as json provider for NovelRT

Is there an open issue that this resolves? If so, please link it here.
This PR partially resolves #500, more specifically; jsoncons was causing issues when compiling for C++ 20.

What is the current behavior? (You can also link to an open issue here)
The DesktopResourceLoader uses jsoncons for bson deserialization/serialization

What is the new behavior (if this is a feature change)?
The DesktopResourceLoader uses nlohmann json for bson deserialization/serialization

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
If users relied on jsoncons as json provider, they will have to either set up the inclusion themself, or convert their json code to work with nlohmann json.
If users relied on nlohmann json as json provider (indirectly provided through Fabulist) then they should not have to change their code.

Other information:
So far I only touched the CMake and the C++ code. I do not really know what exact alterations I would have to make to the LICENCE-DIST.md and the build-system.yml.

instead of fetching for jsoncons it fetches nlohmann json instead.

because fabulist also relies on it, it has to be told not to fetch it.
@RubyNova
Copy link
Member

The build system YML should not require changes but I'll leave that up to @capnkenny to confirm.

The licence distributable file requires you to add the licence for the new dependency, and remove the jsoncons licence assuming I added it originally, and that's it.

Copy link
Member

@capnkenny capnkenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall seems good - just needs the licensing change, and I would move the one flag being set.

internal/CMakeLists.txt Outdated Show resolved Hide resolved
@capnkenny
Copy link
Member

Just confirming - build system does not need to change and passes as-is

@Pheubel Pheubel marked this pull request as ready for review November 19, 2022 15:23
Copy link
Member

@capnkenny capnkenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few questions that need answering before approval or changes requested

jsoncons::json j(jsoncons::json_object_arg);
std::vector<jsoncons::json> memberMetadataJson{};
nlohmann::json j{};
nlohmann::json memberMetadataJson{};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this isn't a std::vector of the json object anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The json object behaves like std::vector, i feel like having it be a json object instead would make more sense in showing what it actually is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm, do we have a test covering this code path in the case the vector would have multiple entries?


newMemberJson["name"] = member.name;
newMemberJson["type"] = static_cast<uint32_t>(member.type);
newMemberJson["type"] = member.type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is member.type already a uint32_t for nlohmann::json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peeking at the json header file, it does seem to already look at the underlying value in the enum, but i could be wrong. it is not the easiest library to look through

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's converted to an int by default, but it can be customised: https://json.nlohmann.me/features/enum_conversion/

I would suggest doing so, as this avoids potential reordering errors.

obj["location"].as<size_t>(), obj["sizeOfTypeInBytes"].as<size_t>(),
obj["length"].as<size_t>(), obj["sizeOfSerialisedDataInBytes"].as<size_t>()};
BinaryMemberMetadata newMemberMetadata{obj.value<std::string>("name", std::string()),
obj.value<BinaryDataType>("type", BinaryDataType::NullOrUnknown),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the possibly BinaryDataTypes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean how it's serialized: it's serialized as an integer by default,they can be serialized as strings as seen here.

if you mean the values BinaryDataType can represent, then a full list can be seen here. examples are:

  • Boolean
  • Int32
  • Int64

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @RubyNova - should we be typing as UInt32 here? I see the static cast has been dropped, but I'm not sure if its necessary anymore (CI appears to pass but idk if we specifically test this)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

target_compile_options(nlohmann_json::nlohmann_json
INTERFACE
$<BUILD_INTERFACE:$<$<CXX_COMPILER_ID:MSVC>:/external:I${json_SOURCE_DIR}/include>>
$<$<CXX_COMPILER_ID:MSVC>:/external:W0>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this taken from Fabulist's version of the nlohmann::json dependency CMakeLists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it was, i did bump the version, as fabulist is a little behind.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem - my only ask is that we double check how this aligns with the Engine's compiler flags? I believe there's a difference between the two and I'm not sure which we prefer...

Cc @RubyNova for compiler flag input

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is an external dependency I am unsure if it matters what flags this dependency requires.

You're best off asking @FiniteReality .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd be using this format going forward, if I understand correctly. The /external:W0 here is just used to turn off warnings for external code.

Copy link
Member

@RubyNova RubyNova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All questions have been resolved, LGTM

@FiniteReality
Copy link
Contributor

Merging on @RubyNova's instructions. Fingers crossed this doesn't break everything 😜

@FiniteReality FiniteReality merged commit 7f33a04 into novelrt:main Nov 20, 2022
@Pheubel Pheubel deleted the feature/replace-jsoncons branch November 23, 2022 01:43
@Pheubel Pheubel mentioned this pull request Nov 25, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prepare NovelRT for C++ 20
4 participants