Implements loading of proto files
This commit is contained in:
parent
03c0d30928
commit
f6e691d3db
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
build/*
|
14
CMakeLists.txt
Normal file
14
CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(EsriAssignment)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
find_package(Protobuf REQUIRED)
|
||||
include_directories(${PROTOBUF_INCLUDE_DIR})
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_subdirectory(protocol_buffers_definitions)
|
||||
include_directories(src)
|
||||
add_subdirectory(src)
|
||||
|
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# ESRI C++ code assignment
|
||||
|
||||
## Setup
|
||||
|
||||
```
|
||||
aptitude install protobuf-compiler libprotobuf-c-dev ##libprotoc-dev
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
|
||||
## Links
|
||||
* https://developers.google.com/protocol-buffers/docs/cpptutorial
|
||||
* https://github.com/protocolbuffers/protobuf/tree/master/examples
|
||||
* https://cmake.org/cmake/help/latest/module/FindProtobuf.html
|
||||
|
14
protocol_buffers_definitions/CMakeLists.txt
Normal file
14
protocol_buffers_definitions/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
find_package(Protobuf REQUIRED)
|
||||
include_directories(${PROTOBUF_INCLUDE_DIR})
|
||||
|
||||
set(PROTO_LIST
|
||||
locatorevents.proto
|
||||
positions.proto
|
||||
recordings.proto
|
||||
sensors.proto
|
||||
structures.proto
|
||||
)
|
||||
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER ${PROTO_LIST})
|
||||
add_library(proto ${PROTO_HEADER} ${PROTO_SRC})
|
||||
set_target_properties(proto PROPERTIES PUBLIC_HEADER "${PROTO_HEADER}")
|
||||
|
6
src/CMakeLists.txt
Normal file
6
src/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
set(assignment_SOURCES
|
||||
main.cpp)
|
||||
|
||||
add_executable(main ${assignment_SOURCES})
|
||||
target_link_libraries(main proto ${PROTOBUF_LIBRARY})
|
40
src/main.cpp
Normal file
40
src/main.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "protocol_buffers_definitions/recordings.pb.h"
|
||||
|
||||
|
||||
using namespace ::indoors::proto;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Verify that the version of the library that we linked against is
|
||||
// compatible with the version of the headers we compiled against.
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
|
||||
std::cout << "ESRI C++ code assignment\n";
|
||||
|
||||
Recording recording;
|
||||
Position positions;
|
||||
|
||||
std::fstream input(argv[1], std::ios::in | std::ios::binary);
|
||||
if (!recording.ParseFromIstream(&input)) {
|
||||
std::cerr << "Failed to parse input file.\n";
|
||||
return -1;
|
||||
}
|
||||
std::cout.precision(17);
|
||||
for (int i=0; i < recording.magnetics_size(); i++) {
|
||||
auto const& s = recording.magnetics(i);
|
||||
std::cout << s.t() << ": [" << s.x() << ", " << s.y() << ", " << s.z() << "]\n";
|
||||
}
|
||||
for (int i=0; i < recording.positions_size(); i++) {
|
||||
auto const& s = recording.positions(i);
|
||||
std::cout << s.t() << ": [" << s.x() << ", " << s.y() << "]\n";
|
||||
}
|
||||
|
||||
// Optional: Delete all global objects allocated by libprotobuf.
|
||||
google::protobuf::ShutdownProtobufLibrary();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user