diff --git a/src/struct_pb/examples/CMakeLists.txt b/src/struct_pb/examples/CMakeLists.txt new file mode 100644 index 000000000..4183a5de6 --- /dev/null +++ b/src/struct_pb/examples/CMakeLists.txt @@ -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 + ) \ No newline at end of file diff --git a/src/struct_pb/examples/main.cpp b/src/struct_pb/examples/main.cpp new file mode 100644 index 000000000..5eebd583c --- /dev/null +++ b/src/struct_pb/examples/main.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +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); +} \ No newline at end of file