Implements loading of proto files

This commit is contained in:
2021-06-17 20:14:50 +02:00
parent 03c0d30928
commit f6e691d3db
6 changed files with 98 additions and 0 deletions

6
src/CMakeLists.txt Normal file
View 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
View 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;
}