libcopp  2.2.0
cross-main.cpp
Go to the documentation of this file.
1 // Copyright 2022 atframework
2 
3 #include <iostream>
4 #include <memory>
5 #include <string>
6 
7 #include "helloworld_generated.h"
8 
9 int main(int argc, char** argv) {
10  flatbuffers::FlatBufferBuilder fbb;
11  helloworld::MessageT mutable_msg;
12 
13  mutable_msg.head = std::unique_ptr<helloworld::MessageHead>(new helloworld::MessageHead());
14  mutable_msg.head->mutate_sequence(123);
15  mutable_msg.head->mutate_timestamp(123000000);
16 
17  helloworld::HelloReplyT* reply = new helloworld::HelloReplyT();
18  reply->message = "hello";
19  mutable_msg.body.type = helloworld::MessageBody_hello_response;
20  mutable_msg.body.value = reinterpret_cast<void*>(reply);
21 
22  auto msg = helloworld::CreateMessage(fbb, &mutable_msg);
23  fbb.Finish(msg);
24 
25  const helloworld::Message* msg2 = helloworld::GetMessage(fbb.GetBufferPointer());
26  std::cout << "head.sequence: " << msg2->head()->sequence() << std::endl;
27  std::cout << "head.timestamp: " << msg2->head()->timestamp() << std::endl;
28  std::cout << "body.hello_response.message: ";
29  std::cout.write(msg2->body_as_hello_response()->message()->c_str(),
30  msg2->body_as_hello_response()->message()->size());
31  std::cout << std::endl;
32  return 0;
33 }
int main(int argc, char **argv)
Definition: cross-main.cpp:9