Skip to content

Instantly share code, notes, and snippets.

@dwilliamson
Created July 30, 2012 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwilliamson/3208569 to your computer and use it in GitHub Desktop.
Save dwilliamson/3208569 to your computer and use it in GitHub Desktop.
clReflect equivalent of protobuf example
// 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