Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
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
31namespace goby
32{
33namespace middleware
34{
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
64template <typename T, typename std::enable_if<std::is_same<T, std::string>::value>::type* = nullptr>
65constexpr int scheme()
66{
68}
69} // namespace middleware
70} // namespace goby
71
72#endif
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
Definition cstr.h:65
The global namespace for the Goby project.
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::PROTOBUF_NAMESPACE_ID::MessageOptions, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
STL namespace.
static std::string type_name(const std::string &d=std::string())
Definition cstr.h:45
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
static std::vector< char > serialize(const std::string &msg)
Definition cstr.h:38
Class for parsing and serializing a given marshalling scheme. Must be specialized for a particular sc...
Definition interface.h:98
static std::string type_name()
The marshalling scheme specific string name for this type.
Definition interface.h:107