-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
27 lines (24 loc) · 902 Bytes
/
Copy pathmain.cpp
File metadata and controls
27 lines (24 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include "proto/message.pb.h"
using namespace std;
int main(int argc, char const *argv[])
{
// Preparing data
message::Message mes;
mes.set_mystring("Hello Protobuf");
mes.set_myint(2137);
message::Person* person = mes.mutable_myperson();
person->set_age(84);
person->set_name("Karol");
cout << "Message before encryption: " << mes.mystring() << " " << mes.myint() << " " << mes.myperson().name() << " " << mes.myperson().age() << endl;
// Encryption
std::string encrypted;
mes.SerializeToString(&encrypted);
cout << "Encrypted message: " << encrypted << endl;
// Decryption
message::Message decrypted;
mes.SerializeToString(&encrypted);
decrypted.ParseFromString(encrypted);
cout << "Message after decryption: " << mes.mystring() << " " << mes.myint() << " " << mes.myperson().name() << " " << mes.myperson().age() << endl;
return 0;
}