-
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
6 changed files
with
1,810 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
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,37 @@ | ||
find_package(Protobuf QUIET) | ||
if("${yaLanTingLibs_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") | ||
# If this is a subproject in ylt | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/tests) | ||
else() | ||
# else find installed yalantinglibs | ||
cmake_minimum_required(VERSION 3.15) | ||
project(struct_pb_test) | ||
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() | ||
|
||
set(TEST_PROTO main.cpp) | ||
|
||
if (Protobuf_FOUND) | ||
add_definitions(-DSTRUCT_PB_WITH_PROTO) | ||
message(STATUS "Found Protobuf: ${Protobuf_VERSION}") | ||
include_directories(${Protobuf_INCLUDE_DIRS}) | ||
include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
set(PROTO_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/) | ||
file(GLOB PROTO_FILES ${PROTO_SRC_DIR}/*.proto) | ||
|
||
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES}) | ||
# message(STATUS "Proto source files: ${PROTO_SRCS}") | ||
# message(STATUS "Proto header files: ${PROTO_HDRS}") | ||
add_executable(struct_pb_test ${PROTO_SRCS} ${TEST_PROTO}) | ||
target_link_libraries(struct_pb_test PRIVATE protobuf::libprotobuf) | ||
else() | ||
add_executable(struct_pb_test ${TEST_PROTO}) | ||
endif() |
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,56 @@ | ||
syntax = "proto3"; | ||
|
||
package mygame; | ||
|
||
option optimize_for = SPEED; | ||
option cc_enable_arenas = true; | ||
|
||
message Vec3 { | ||
float x = 1; | ||
float y = 2; | ||
float z = 3; | ||
} | ||
|
||
message Weapon { | ||
string name = 1; | ||
int32 damage = 2; | ||
} | ||
|
||
message Monster { | ||
Vec3 pos = 1; | ||
int32 mana = 2; | ||
int32 hp = 3; | ||
string name = 4; | ||
bytes inventory = 5; | ||
enum Color { | ||
Red = 0; | ||
Green = 1; | ||
Blue = 2; | ||
} | ||
Color color = 6; | ||
repeated Weapon weapons = 7; | ||
Weapon equipped = 8; | ||
repeated Vec3 path = 9; | ||
} | ||
|
||
message Monsters { | ||
repeated Monster monsters = 1; | ||
} | ||
|
||
message person { | ||
int32 id = 1; | ||
string name = 2; | ||
int32 age = 3; | ||
double salary = 4; | ||
} | ||
|
||
message persons { | ||
repeated person person_list = 1; | ||
} | ||
|
||
message bench_int32 { | ||
int32 a = 1; | ||
int32 b = 2; | ||
int32 c = 3; | ||
int32 d = 4; | ||
} |
Oops, something went wrong.