-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
if("${yaLanTingLibs_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") | ||
# If this is a subproject in ylt | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/examples) | ||
else() | ||
# else find installed yalantinglibs | ||
cmake_minimum_required(VERSION 3.15) | ||
project(struct_pb_examples) | ||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE "Release") | ||
endif() | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
# if you have install ylt | ||
find_package(yalantinglibs REQUIRED) | ||
link_libraries(yalantinglibs::yalantinglibs) | ||
# else | ||
# include_directories(include) | ||
# include_directories(include/ylt/thirdparty) | ||
endif() | ||
|
||
add_executable(struct_pb_examples | ||
main.cpp | ||
) |
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,27 @@ | ||
#include <cassert> | ||
#include <iostream> | ||
#include <ylt/struct_pb.hpp> | ||
|
||
struct my_struct : struct_pb::pb_base { | ||
int x; | ||
bool y; | ||
iguana::fixed64_t z; | ||
}; | ||
REFLECTION(my_struct, x, y, z); | ||
|
||
struct nest : struct_pb::pb_base { | ||
std::string name; | ||
my_struct value; | ||
int var; | ||
}; | ||
REFLECTION(nest, name, value, var); | ||
|
||
int main() { | ||
nest v{0, "Hi", {0, 1, false, 3}, 5}, v2{}; | ||
std::string s; | ||
struct_pb::to_pb(v, s); | ||
struct_pb::from_pb(v2, s); | ||
assert(v.var == v2.var); | ||
assert(v.value.y == v2.value.y); | ||
assert(v.value.z == v2.value.z); | ||
} |