Goby3  3.1.5a
2024.05.23
moos_serializer.h
Go to the documentation of this file.
1 // Copyright 2011-2021:
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 // File authors:
6 // Toby Schneider <toby@gobysoft.org>
7 //
8 //
9 // This file is part of the Goby Underwater Autonomy Project Libraries
10 // ("The Goby Libraries").
11 //
12 // The Goby Libraries are free software: you can redistribute them and/or modify
13 // them under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation, either version 2.1 of the License, or
15 // (at your option) any later version.
16 //
17 // The Goby Libraries are distributed in the hope that they will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef GOBY_MOOS_MOOS_SERIALIZER_H
26 #define GOBY_MOOS_MOOS_SERIALIZER_H
27 
28 #include <string>
29 
30 #include "goby/moos/moos_header.h"
31 
32 namespace goby
33 {
34 namespace moos
35 {
37 {
38  public:
39  static void serialize(const CMOOSMsg& const_msg, std::string* data)
40  {
41  // copy because Serialize wants to modify the CMOOSMsg
42  CMOOSMsg msg(const_msg);
43  // adapted from MOOSCommPkt.cpp
44  int serialized_size = msg.GetSizeInBytesWhenSerialised();
45  data->resize(serialized_size);
46  serialized_size =
47  msg.Serialize(reinterpret_cast<unsigned char*>(&(*data)[0]), serialized_size);
48  data->resize(serialized_size);
49  }
50 
51  static void parse(CMOOSMsg* msg, std::string data)
52  {
53  msg->Serialize(reinterpret_cast<unsigned char*>(&data[0]), data.size(), false);
54  }
55 };
56 } // namespace moos
57 } // namespace goby
58 
59 #endif
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
moos_header.h
CMOOSMsg
goby::msg
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
Definition: option_extensions.pb.h:1327
goby::moos::MOOSSerializer
Definition: moos_serializer.h:36
goby::moos::MOOSSerializer::serialize
static void serialize(const CMOOSMsg &const_msg, std::string *data)
Definition: moos_serializer.h:39
goby::moos::MOOSSerializer::parse
static void parse(CMOOSMsg *msg, std::string data)
Definition: moos_serializer.h:51