summaryrefslogtreecommitdiff
path: root/src/proto
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-05-31 18:30:10 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-06-03 10:09:24 +0200
commit3626877554b6c567d43336ec49414cedfe487260 (patch)
treef80c51ec1867fea029b955d85e89e39017f920e3 /src/proto
downloadhello-nix-3626877554b6c567d43336ec49414cedfe487260.tar.gz
Initial commit
Diffstat (limited to 'src/proto')
-rw-r--r--src/proto/TARGETS18
-rw-r--r--src/proto/example.proto7
-rw-r--r--src/proto/read.cc18
-rw-r--r--src/proto/write.cc17
4 files changed, 60 insertions, 0 deletions
diff --git a/src/proto/TARGETS b/src/proto/TARGETS
new file mode 100644
index 0000000..512d7c2
--- /dev/null
+++ b/src/proto/TARGETS
@@ -0,0 +1,18 @@
+{ "example":
+ { "type": ["@", "rules", "proto", "library"]
+ , "name": ["example"]
+ , "srcs": ["example.proto"]
+ }
+, "write":
+ { "type": ["@", "rules", "CC", "binary"]
+ , "name": ["write"]
+ , "srcs": ["write.cc"]
+ , "private-proto": ["example"]
+ }
+, "read":
+ { "type": ["@", "rules", "CC", "binary"]
+ , "name": ["read"]
+ , "srcs": ["read.cc"]
+ , "private-proto": ["example"]
+ }
+}
diff --git a/src/proto/example.proto b/src/proto/example.proto
new file mode 100644
index 0000000..69b5953
--- /dev/null
+++ b/src/proto/example.proto
@@ -0,0 +1,7 @@
+syntax = "proto3";
+package sample;
+
+message Example {
+ string foo = 1;
+ int32 bar = 2;
+}
diff --git a/src/proto/read.cc b/src/proto/read.cc
new file mode 100644
index 0000000..f97a39a
--- /dev/null
+++ b/src/proto/read.cc
@@ -0,0 +1,18 @@
+#include <fstream>
+#include <iostream>
+
+#include "example.pb.h"
+
+int main(int argc, char **argv) {
+ sample::Example example;
+
+ {
+ std::fstream input(argv[1], std::ios::in | std::ios::binary);
+ example.ParseFromIstream(&input);
+ }
+
+ std::cout << "foo=" << example.foo() << "\n";
+ std::cout << "bar=" << example.bar() << std::endl;
+
+ return 0;
+}
diff --git a/src/proto/write.cc b/src/proto/write.cc
new file mode 100644
index 0000000..2e206e5
--- /dev/null
+++ b/src/proto/write.cc
@@ -0,0 +1,17 @@
+#include <fstream>
+#include <string>
+
+#include "example.pb.h"
+
+int main(int argc, char **argv) {
+ sample::Example example;
+ example.set_foo(std::string{argv[1]});
+ example.set_bar(atoi(argv[2]));
+ {
+ std::fstream output(argv[3],
+ std::ios::out | std::ios::trunc | std::ios::binary);
+ example.SerializeToOstream(&output);
+ }
+
+ return 0;
+}