CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
streaming
detail
tcp
Message.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include "
carla/ListView.h
"
10
#include "
carla/Buffer.h
"
11
#include "
carla/BufferView.h
"
12
#include "
carla/Debug.h
"
13
#include "
carla/NonCopyable.h
"
14
#include "
carla/streaming/detail/Types.h
"
15
16
#include <boost/asio/buffer.hpp>
17
18
#include <array>
19
#include <exception>
20
#include <limits>
21
#include <memory>
22
#include <string>
23
24
namespace
carla
{
25
namespace
streaming
{
26
namespace
detail
{
27
namespace
tcp
{
28
29
/// Serialization of a set of buffers to be sent over a TCP socket as a single
30
/// message. Template paramenter @a MaxNumberOfBuffers imposes a compile-time
31
/// limit on the maximum number of buffers that can be included in a single
32
/// message.
33
template
<
size_t
MaxNumberOfBuffers>
34
class
MessageTmpl
35
:
public
std::enable_shared_from_this<MessageTmpl<MaxNumberOfBuffers>>,
36
private
NonCopyable
{
37
public
:
38
39
static
constexpr
size_t
max_size
() {
40
return
MaxNumberOfBuffers;
41
}
42
43
private
:
44
45
MessageTmpl
(
size_t
) {}
46
47
template
<
typename
... Buffers>
48
MessageTmpl
(
size_t
size
,
SharedBufferView
buffer, Buffers... buffers)
49
:
MessageTmpl
(
size
, buffers...) {
50
++
_number_of_buffers
;
51
_total_size
+= buffer->size();
52
_buffer_views
[1u +
size
-
_number_of_buffers
] = buffer->cbuffer();
53
_buffers
[
size
-
_number_of_buffers
] = buffer;
54
}
55
56
public
:
57
58
template
<
typename
... Buffers>
59
MessageTmpl
(
SharedBufferView
buf, Buffers... buffers)
60
:
MessageTmpl
(sizeof...(Buffers) + 1u, buf, buffers...) {
61
static_assert
(
sizeof
...(Buffers) <
max_size
(),
"Too many buffers!"
);
62
_buffer_views
[0u] = boost::asio::buffer(&
_total_size
,
sizeof
(
_total_size
));
63
}
64
65
/// Size in bytes of the message excluding the header.
66
auto
size
() const noexcept {
67
return
_total_size
;
68
}
69
70
bool
empty
() const noexcept {
71
return
size
() == 0u;
72
}
73
74
auto
GetBufferSequence
()
const
{
75
auto
begin =
_buffer_views
.begin();
76
return
MakeListView(begin, begin +
_number_of_buffers
+ 1u);
77
}
78
79
private
:
80
81
message_size_type
_number_of_buffers
= 0u;
82
83
message_size_type
_total_size
= 0u;
84
85
std::array<SharedBufferView, MaxNumberOfBuffers>
_buffers
;
86
87
std::array<boost::asio::const_buffer, MaxNumberOfBuffers + 1u>
_buffer_views
;
88
};
89
90
/// A TCP message containing a maximum of 2 buffers. This is optimized for a
91
/// header and body sort of messages.
92
using
Message
=
MessageTmpl<2u>
;
93
94
}
// namespace tcp
95
}
// namespace detail
96
}
// namespace streaming
97
}
// namespace carla
BufferView.h
Debug.h
ListView.h
NonCopyable.h
Buffer.h
carla::NonCopyable::NonCopyable
NonCopyable()=default
carla::streaming::detail::tcp::MessageTmpl
Serialization of a set of buffers to be sent over a TCP socket as a single message.
Definition
Message.h:36
carla::streaming::detail::tcp::MessageTmpl::MessageTmpl
MessageTmpl(size_t size, SharedBufferView buffer, Buffers... buffers)
Definition
Message.h:48
carla::streaming::detail::tcp::MessageTmpl< 2u >::_buffers
std::array< SharedBufferView, MaxNumberOfBuffers > _buffers
Definition
Message.h:85
carla::streaming::detail::tcp::MessageTmpl< 2u >::size
auto size() const noexcept
Definition
Message.h:66
carla::streaming::detail::tcp::MessageTmpl::max_size
static constexpr size_t max_size()
Definition
Message.h:39
carla::streaming::detail::tcp::MessageTmpl::GetBufferSequence
auto GetBufferSequence() const
Definition
Message.h:74
carla::streaming::detail::tcp::MessageTmpl::MessageTmpl
MessageTmpl(SharedBufferView buf, Buffers... buffers)
Definition
Message.h:59
carla::streaming::detail::tcp::MessageTmpl::MessageTmpl
MessageTmpl(size_t)
Definition
Message.h:45
carla::streaming::detail::tcp::MessageTmpl< 2u >::_number_of_buffers
message_size_type _number_of_buffers
Definition
Message.h:81
carla::streaming::detail::tcp::MessageTmpl< 2u >::_buffer_views
std::array< boost::asio::const_buffer, MaxNumberOfBuffers+1u > _buffer_views
Definition
Message.h:87
carla::streaming::detail::tcp::MessageTmpl< 2u >::_total_size
message_size_type _total_size
Definition
Message.h:83
carla::streaming::detail::tcp::MessageTmpl::empty
bool empty() const noexcept
Definition
Message.h:70
carla::streaming::detail::tcp
Definition
streaming/detail/tcp/Client.cpp:26
carla::streaming::detail::tcp::Message
MessageTmpl< 2u > Message
A TCP message containing a maximum of 2 buffers.
Definition
Message.h:92
carla::streaming::detail
Definition
Dispatcher.cpp:17
carla::streaming::detail::message_size_type
uint32_t message_size_type
Definition
streaming/detail/Types.h:20
carla::streaming
Definition
client/detail/Client.h:61
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::SharedBufferView
std::shared_ptr< BufferView > SharedBufferView
Definition
BufferView.h:151
Types.h
Generated by
1.18.0