Goby3  3.1.5a
2024.05.23
cstr.h
Go to the documentation of this file.
1 // Copyright 2016-2021:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Toby Schneider <toby@gobysoft.org>
6 //
7 //
8 // This file is part of the Goby Underwater Autonomy Project Libraries
9 // ("The Goby Libraries").
10 //
11 // The Goby Libraries are free software: you can redistribute them and/or modify
12 // them under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // The Goby Libraries are distributed in the hope that they will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef GOBY_MIDDLEWARE_MARSHALLING_CSTR_H
25 #define GOBY_MIDDLEWARE_MARSHALLING_CSTR_H
26 
27 #include <vector>
28 
29 #include "interface.h"
30 
31 namespace goby
32 {
33 namespace middleware
34 {
36 template <> struct SerializerParserHelper<std::string, MarshallingScheme::CSTR>
37 {
38  static std::vector<char> serialize(const std::string& msg)
39  {
40  std::vector<char> bytes(std::begin(msg), std::end(msg));
41  bytes.push_back('\0');
42  return bytes;
43  }
44 
45  static std::string type_name(const std::string& d = std::string()) { return "CSTR"; }
46 
47  template <typename CharIterator>
48  static std::shared_ptr<std::string> parse(CharIterator bytes_begin, CharIterator bytes_end,
49  CharIterator& actual_end,
50  const std::string& type = type_name())
51  {
52  actual_end = bytes_end;
53  if (bytes_begin != bytes_end)
54  {
55  return std::make_shared<std::string>(bytes_begin, bytes_end - 1);
56  }
57  else
58  {
59  return std::make_shared<std::string>();
60  }
61  }
62 };
63 
64 template <typename T, typename std::enable_if<std::is_same<T, std::string>::value>::type* = nullptr>
65 constexpr int scheme()
66 {
68 }
69 } // namespace middleware
70 } // namespace goby
71 
72 #endif
interface.h
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::middleware::SerializerParserHelper
Class for parsing and serializing a given marshalling scheme. Must be specialized for a particular sc...
Definition: interface.h:97
goby::middleware::SerializerParserHelper< std::string, MarshallingScheme::CSTR >::parse
static std::shared_ptr< std::string > parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator &actual_end, const std::string &type=type_name())
Definition: cstr.h:48
goby::middleware::SerializerParserHelper< std::string, MarshallingScheme::CSTR >::type_name
static std::string type_name(const std::string &d=std::string())
Definition: cstr.h:45
goby::middleware::SerializerParserHelper::type_name
static std::string type_name()
The marshalling scheme specific string name for this type.
Definition: interface.h:107
jwt::json::type
type
Generic JSON types used in JWTs.
Definition: jwt.h:2071
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::middleware::SerializerParserHelper< std::string, MarshallingScheme::CSTR >::serialize
static std::vector< char > serialize(const std::string &msg)
Definition: cstr.h:38
goby::middleware::scheme
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
Definition: cstr.h:65
goby::middleware::MarshallingScheme::CSTR
@ CSTR
Definition: interface.h:52