Added support for Cap'n Proto (#323)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-01-06 15:12:40 +01:00
committed by GitHub
parent 6b63b41b81
commit 1d58526869
111 changed files with 4035 additions and 171 deletions
+70
View File
@@ -0,0 +1,70 @@
#include <gtest/gtest.h>
#include <iostream>
#include <rfl.hpp>
#include <rfl/capnproto.hpp>
#include <string>
#include <vector>
// #include "write_and_read.hpp"
/// The basic example from the capnproto C tutorial.
namespace test_tutorial_example {
const std::string ADDRESS_BOOK_SCHEMA = R"(
@0xb07899ba441fd7ec;
struct Person {
id @0 :UInt32;
name @1 :Text;
email @2 :Text;
phones @3 :List(PhoneNumber);
struct PhoneNumber {
number @0 :Text;
type @1 :Type;
enum Type {
mobile @0;
home @1;
work @2;
}
}
employment :union {
unemployed @4 :Void;
employer @5 :Text;
school @6 :Text;
selfEmployed @7 :Void;
# We assume that a person is only one of these.
}
}
struct AddressBook {
people @0 :List(Person);
}
)";
enum class Type { mobile, home, work };
struct PhoneNumber {
std::string number;
std::string email;
Type type;
};
struct Person {
uint32_t id;
std::string name;
std::string email;
// TODO: Employment.
};
struct AddressBook {
std::vector<Person> people;
};
TEST(capnproto, test_tutorial_example) {
rfl::capnproto::Schema<Person>::from_string(ADDRESS_BOOK_SCHEMA).value();
}
} // namespace test_tutorial_example