Created
July 30, 2012 17:34
-
-
Save dwilliamson/3208569 to your computer and use it in GitHub Desktop.
clReflect equivalent of protobuf example
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
// You write a structure with reflect attribute, like this: | |
clcpp_attr(reflect) | |
struct Person | |
{ | |
int id; | |
std::string name; | |
std::string email; | |
}; | |
// You modify it like this: | |
Person person; | |
person.id = 123; | |
person.name = "Bob"; | |
person.email = "bob@example.com"; | |
// You save like this: | |
clutl::WriteBuffer wb; | |
clutl::SaveJSON(wb, &person, clcpp::GetType<Person>(), 0, 0); | |
// Send to file, network, whatever... | |
// You load like this: | |
clutl::ReadBuffer rb(wb); | |
clutl::LoadJSON(rb, &person, clcpp::GetType<Person>()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment