DCCL v3
quick.cpp
1 // Copyright 2009-2017 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (for 2013-)
3 // Massachusetts Institute of Technology (for 2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Dynamic Compact Control Language Library
8 // ("DCCL").
9 //
10 // DCCL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // DCCL is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with DCCL. If not, see <http://www.gnu.org/licenses/>.
22 #include "dccl.h"
23 #include "navreport.pb.h"
24 #include <iostream>
25 
26 int main()
27 {
28  std::string encoded_bytes;
29  dccl::Codec codec;
30  codec.load<NavigationReport>();
31  // SENDER
32  {
33  NavigationReport r_out;
34  r_out.set_x(450);
35  r_out.set_y(550);
36  r_out.set_z(-100);
37  r_out.set_veh_class(NavigationReport::AUV);
38  r_out.set_battery_ok(true);
39 
40  codec.encode(&encoded_bytes, r_out);
41  }
42  // send encoded_bytes across your link
43 
44  // RECEIVER
45  if(codec.id(encoded_bytes) == codec.id<NavigationReport>())
46  {
47  NavigationReport r_in;
48  codec.decode(encoded_bytes, &r_in);
49  std::cout << r_in.ShortDebugString() << std::endl;
50  }
51 }
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
Definition: codec.h:56
void load()
All messages must be explicited loaded and validated (size checks, option extensions checks...
Definition: codec.h:96
void encode(std::string *bytes, const google::protobuf::Message &msg, bool header_only=false, int user_id=-1)
Encodes a DCCL message.
Definition: codec.cpp:273
unsigned id() const
Gives the DCCL id (defined by the custom message option extension "(dccl.msg).id" in the ...
Definition: codec.h:174
CharIterator decode(CharIterator begin, CharIterator end, google::protobuf::Message *msg, bool header_only=false)
Decode a DCCL message when the type is known at compile time.
Definition: codec.h:439