Skip to content

Commit

Permalink
Align proto with other examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowhatter committed Sep 20, 2024
1 parent 33f5db8 commit eb45243
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function(add_protobuf target)
if(Protobuf_FOUND)
message(STATUS "Found Protobuf ${protobuf_VERSION}, will build Protobuf example!")

protobuf_generate_cpp(pb_src pb_hdr ${CMAKE_CURRENT_LIST_DIR}/universal/proto/test.proto)
protobuf_generate_cpp(pb_src pb_hdr ${CMAKE_CURRENT_LIST_DIR}/universal/proto/entity.proto)

add_library(example_message ${pb_hdr} ${pb_src})
target_include_directories(example_message INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
6 changes: 6 additions & 0 deletions examples/universal/proto/entity.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";

message Entity {
uint32 id = 1;
string name = 2;
}
8 changes: 0 additions & 8 deletions examples/universal/proto/test.proto

This file was deleted.

16 changes: 7 additions & 9 deletions examples/universal/z_bytes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <iostream>

#ifdef ZENOH_CPP_EXMAPLE_WITH_PROTOBUF
#include "test.pb.h"
#include "entity.pb.h"
#endif

#include "zenoh.hxx"
Expand Down Expand Up @@ -131,10 +131,9 @@ int _main(int argc, char** argv) {
GOOGLE_PROTOBUF_VERIFY_VERSION;

// Construct PB message
Book input;
input.set_author("H. P. Lovecraft");
input.set_title("The Call of Cthulhu");
input.set_isbn(931082);
Entity input;
input.set_id(1234);
input.set_name("John Doe");

// Serialize PB message into wire format
const auto input_wire_pb = input.SerializeAsString();
Expand All @@ -149,14 +148,13 @@ int _main(int argc, char** argv) {
assert(input_wire_pb == output_wire_pb);

// deserialize output wire PB into PB message
Book output;
Entity output;
const auto parsed = output.ParseFromString(output_wire_pb);
assert(parsed);

// data is equal
assert(input.author() == output.author());
assert(input.title() == output.title());
assert(input.isbn() == output.isbn());
assert(input.id() == output.id());
assert(input.name() == output.name());

// Corresponding encoding to be used in operations like `.put()`, `.reply()`, etc.
const auto encoding = Encoding("application/protobuf");
Expand Down

0 comments on commit eb45243

Please sign in to comment.