-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add json serialization/deserialization support for c++ generator #99
Merged
a4z
merged 7 commits into
cross-language-cpp:main
from
mutagene:add-json-serialization-modified-from-finn
Oct 19, 2021
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
24f8017
Add json serialization/deserialization support for c++ generator
mutagene fc133ff
Run scalafmt on json serialization integration tests
mutagene 9f07cc1
Remove extraneous nlohmann/json.hpp include in c++ generated record h…
mutagene 6ee9912
- sync documentation with command line
mutagene 65bbf5a
Apply PR suggestions
mutagene 11cbb5f
Doc polishing
a4z 10754eb
Remove left over some text fragment
a4z File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
enum_data = enum { | ||
FirstEnumValue; | ||
SecondEnumValue; | ||
} | ||
|
||
# flag comment | ||
my_flags = flags { | ||
# flag option comment | ||
flag1; | ||
flag2; | ||
flag3; | ||
no_flags = none; | ||
all_flags = all; | ||
} | ||
|
||
all_datatypes_json = record { | ||
booleanData: bool; | ||
integer8Data: i8; | ||
integer16Data: i16; | ||
integer32Data: i32; | ||
integer64Data: i64; | ||
float32Data: f32; | ||
float64Data: f64; | ||
stringData: string; | ||
binaryData: binary; | ||
dateData: date; | ||
listData: list<bool>; | ||
setData: set<bool>; | ||
mapData: map<i8, bool>; | ||
optionalData: optional<bool>; | ||
enum_data: enum_data; | ||
myFlags: my_flags; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
my_enum = enum { | ||
FirstEnumValue; | ||
SecondEnumValue; | ||
} | ||
|
||
my_flags = flags { | ||
flag1; | ||
flag2; | ||
no_flags = none; | ||
all_flags = all; | ||
} | ||
|
||
my_record = record { | ||
myEnum: my_enum; | ||
myFlags: my_flags; | ||
} |
96 changes: 96 additions & 0 deletions
96
src/it/resources/expected/all_datatypes_json/cpp-headers/all_datatypes_json+json.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// AUTOGENERATED FILE - DO NOT MODIFY! | ||
// This file was generated by Djinni from all_datatypes_json.djinni | ||
|
||
#pragma once | ||
|
||
#include "enum_data+json.hpp" | ||
#include "json+extension.hpp" | ||
#include "my_flags+json.hpp" | ||
#include <chrono> | ||
#include <cstdint> | ||
#include <nlohmann/json.hpp> | ||
#include <optional> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include <vector> | ||
|
||
namespace nlohmann { | ||
|
||
template <> | ||
struct adl_serializer<::AllDatatypesJson> { | ||
static ::AllDatatypesJson from_json(const json & j) { | ||
auto result = ::AllDatatypesJson(); | ||
if (j.contains("booleanData")) { | ||
j.at("booleanData").get_to(result.booleanData); | ||
} | ||
if (j.contains("integer8Data")) { | ||
j.at("integer8Data").get_to(result.integer8Data); | ||
} | ||
if (j.contains("integer16Data")) { | ||
j.at("integer16Data").get_to(result.integer16Data); | ||
} | ||
if (j.contains("integer32Data")) { | ||
j.at("integer32Data").get_to(result.integer32Data); | ||
} | ||
if (j.contains("integer64Data")) { | ||
j.at("integer64Data").get_to(result.integer64Data); | ||
} | ||
if (j.contains("float32Data")) { | ||
j.at("float32Data").get_to(result.float32Data); | ||
} | ||
if (j.contains("float64Data")) { | ||
j.at("float64Data").get_to(result.float64Data); | ||
} | ||
if (j.contains("stringData")) { | ||
j.at("stringData").get_to(result.stringData); | ||
} | ||
if (j.contains("binaryData")) { | ||
j.at("binaryData").get_to(result.binaryData); | ||
} | ||
if (j.contains("dateData")) { | ||
j.at("dateData").get_to(result.dateData); | ||
} | ||
if (j.contains("listData")) { | ||
j.at("listData").get_to(result.listData); | ||
} | ||
if (j.contains("setData")) { | ||
j.at("setData").get_to(result.setData); | ||
} | ||
if (j.contains("mapData")) { | ||
j.at("mapData").get_to(result.mapData); | ||
} | ||
if (j.contains("optionalData")) { | ||
j.at("optionalData").get_to(result.optionalData); | ||
} | ||
if (j.contains("enum_data")) { | ||
j.at("enum_data").get_to(result.enum_data); | ||
} | ||
if (j.contains("myFlags")) { | ||
j.at("myFlags").get_to(result.myFlags); | ||
} | ||
return result; | ||
} | ||
static void to_json(json & j, const ::AllDatatypesJson & item) { | ||
j = json { | ||
{"booleanData", item.booleanData}, | ||
{"integer8Data", item.integer8Data}, | ||
{"integer16Data", item.integer16Data}, | ||
{"integer32Data", item.integer32Data}, | ||
{"integer64Data", item.integer64Data}, | ||
{"float32Data", item.float32Data}, | ||
{"float64Data", item.float64Data}, | ||
{"stringData", item.stringData}, | ||
{"binaryData", item.binaryData}, | ||
{"dateData", item.dateData}, | ||
{"listData", item.listData}, | ||
{"setData", item.setData}, | ||
{"mapData", item.mapData}, | ||
{"optionalData", item.optionalData}, | ||
{"enum_data", item.enum_data}, | ||
{"myFlags", item.myFlags} | ||
}; | ||
} | ||
}; | ||
|
||
} // namespace nlohmann |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI you may want to update the feature list on the gitpage as well: https://github.com/cross-language-cpp/cross-language-cpp.github.io/blob/main/docs/overview.md#main-features
This will show up here on the documentation website. :)