Coverage Report

Created: 2026-02-14 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Fast-DDS/src/cpp/rtps/security/common/ParticipantGenericMessage.h
Line
Count
Source
1
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/*!
16
 * @file ParticipantGenericMessage.h
17
 */
18
#ifndef _FASTDDS_RTPS_SECURITY_COMMON_PARTICIPANTGENERICMESSAGE_H_
19
#define _FASTDDS_RTPS_SECURITY_COMMON_PARTICIPANTGENERICMESSAGE_H_
20
21
#include <fastdds/rtps/common/Guid.hpp>
22
#include <fastdds/rtps/common/Token.hpp>
23
24
namespace eprosima {
25
namespace fastdds {
26
namespace rtps {
27
namespace security {
28
29
class MessageIdentity
30
{
31
public:
32
33
    MessageIdentity()
34
        : sequence_number_(0)
35
0
    {
36
0
    }
37
38
    MessageIdentity(
39
            const MessageIdentity& mi)
40
        : source_guid_(mi.source_guid_)
41
        , sequence_number_(mi.sequence_number_)
42
0
    {
43
0
    }
44
45
    MessageIdentity(
46
            MessageIdentity&& mi)
47
        : source_guid_(std::move(mi.source_guid_))
48
        , sequence_number_(mi.sequence_number_)
49
0
    {
50
0
    }
51
52
    MessageIdentity& operator =(
53
            const MessageIdentity& mi)
54
0
    {
55
0
        source_guid_ = mi.source_guid_;
56
0
        sequence_number_ = mi.sequence_number_;
57
0
        return *this;
58
0
    }
59
60
    MessageIdentity& operator =(
61
            MessageIdentity&& mi)
62
0
    {
63
0
        source_guid_ = std::move(mi.source_guid_);
64
0
        sequence_number_ = mi.sequence_number_;
65
0
        return *this;
66
0
    }
67
68
    void source_guid(
69
            const GUID_t& source_guid)
70
0
    {
71
0
        source_guid_ = source_guid;
72
0
    }
73
74
    void source_guid(
75
            GUID_t&& source_guid)
76
0
    {
77
0
        source_guid_ = std::move(source_guid);
78
0
    }
79
80
    const GUID_t& source_guid() const
81
0
    {
82
0
        return source_guid_;
83
0
    }
84
85
    GUID_t& source_guid()
86
0
    {
87
0
        return source_guid_;
88
0
    }
89
90
    void sequence_number(
91
            int64_t sequence_number)
92
0
    {
93
0
        sequence_number_ = sequence_number;
94
0
    }
95
96
    int64_t sequence_number() const
97
0
    {
98
0
        return sequence_number_;
99
0
    }
100
101
    int64_t& sequence_number()
102
0
    {
103
0
        return sequence_number_;
104
0
    }
105
106
private:
107
108
    GUID_t source_guid_;
109
    int64_t sequence_number_;
110
};
111
112
class MessageIdentityHelper
113
{
114
public:
115
116
    static size_t serialized_size(
117
            const MessageIdentity& /*message*/,
118
            size_t current_alignment = 0)
119
0
    {
120
0
        size_t initial_alignment = current_alignment;
121
0
122
0
        current_alignment += 16;
123
0
        current_alignment +=  alignment(current_alignment, 8) + 8;
124
0
125
0
        return current_alignment - initial_alignment;
126
0
    }
127
128
private:
129
130
    inline static size_t alignment(
131
            size_t current_alignment,
132
            size_t dataSize)
133
0
    {
134
0
        return (dataSize - (current_alignment % dataSize)) & (dataSize - 1);
135
0
    }
136
137
};
138
139
class ParticipantGenericMessage
140
{
141
public:
142
143
    ParticipantGenericMessage()
144
0
    {
145
0
    }
146
147
    ParticipantGenericMessage(
148
            const ParticipantGenericMessage& message)
149
        : message_identity_(message.message_identity_)
150
        , related_message_identity_(message.related_message_identity_)
151
        , destination_participant_key_(message.destination_participant_key_)
152
        , destination_endpoint_key_(message.destination_endpoint_key_)
153
        , source_endpoint_key_(message.source_endpoint_key_)
154
        , message_class_id_(message.message_class_id_)
155
        , message_data_(message.message_data_)
156
0
    {
157
0
    }
158
159
    ParticipantGenericMessage(
160
            ParticipantGenericMessage&& message)
161
        : message_identity_(std::move(message.message_identity_))
162
        , related_message_identity_(std::move(message.related_message_identity_))
163
        , destination_participant_key_(std::move(message.destination_participant_key_))
164
        , destination_endpoint_key_(std::move(message.destination_endpoint_key_))
165
        , source_endpoint_key_(std::move(message.source_endpoint_key_))
166
        , message_class_id_(std::move(message.message_class_id_))
167
        , message_data_(std::move(message.message_data_))
168
0
    {
169
0
    }
170
171
    ParticipantGenericMessage& operator =(
172
            const ParticipantGenericMessage& message)
173
0
    {
174
0
        message_identity_ = message.message_identity_;
175
0
        related_message_identity_ = message.related_message_identity_;
176
0
        destination_participant_key_ = message.destination_participant_key_;
177
0
        destination_endpoint_key_ = message.destination_endpoint_key_;
178
0
        source_endpoint_key_ = message.source_endpoint_key_;
179
0
        message_class_id_ = message.message_class_id_;
180
0
        message_data_ = message.message_data_;
181
0
        return *this;
182
0
    }
183
184
    ParticipantGenericMessage& operator =(
185
            ParticipantGenericMessage&& message)
186
0
    {
187
0
        message_identity_ = std::move(message.message_identity_);
188
0
        related_message_identity_ = std::move(message.related_message_identity_);
189
0
        destination_participant_key_ = std::move(message.destination_participant_key_);
190
0
        destination_endpoint_key_ = std::move(message.destination_endpoint_key_);
191
0
        source_endpoint_key_ = std::move(message.source_endpoint_key_);
192
0
        message_class_id_ = std::move(message.message_class_id_);
193
0
        message_data_ = std::move(message.message_data_);
194
0
        return *this;
195
0
    }
196
197
    void message_identity(
198
            const MessageIdentity& message_identity)
199
0
    {
200
0
        message_identity_ = message_identity;
201
0
    }
202
203
    void message_identity(
204
            MessageIdentity&& message_identity)
205
0
    {
206
0
        message_identity_ = std::move(message_identity);
207
0
    }
208
209
    const MessageIdentity& message_identity() const
210
0
    {
211
0
        return message_identity_;
212
0
    }
213
214
    MessageIdentity& message_identity()
215
0
    {
216
0
        return message_identity_;
217
0
    }
218
219
    void related_message_identity(
220
            const MessageIdentity& related_message_identity)
221
0
    {
222
0
        related_message_identity_ = related_message_identity;
223
0
    }
224
225
    void related_message_identity(
226
            MessageIdentity&& related_message_identity)
227
0
    {
228
0
        related_message_identity_ = std::move(related_message_identity);
229
0
    }
230
231
    const MessageIdentity& related_message_identity() const
232
0
    {
233
0
        return related_message_identity_;
234
0
    }
235
236
    MessageIdentity& related_message_identity()
237
0
    {
238
0
        return related_message_identity_;
239
0
    }
240
241
    void destination_participant_key(
242
            const GUID_t& destination_participant_key)
243
0
    {
244
0
        destination_participant_key_ = destination_participant_key;
245
0
    }
246
247
    void destination_participant_key(
248
            GUID_t&& destination_participant_key)
249
0
    {
250
0
        destination_participant_key_ = std::move(destination_participant_key);
251
0
    }
252
253
    const GUID_t& destination_participant_key() const
254
0
    {
255
0
        return destination_participant_key_;
256
0
    }
257
258
    GUID_t& destination_participant_key()
259
0
    {
260
0
        return destination_participant_key_;
261
0
    }
262
263
    void destination_endpoint_key(
264
            const GUID_t& destination_endpoint_key)
265
0
    {
266
0
        destination_endpoint_key_ = destination_endpoint_key;
267
0
    }
268
269
    void destination_endpoint_key(
270
            GUID_t&& destination_endpoint_key)
271
0
    {
272
0
        destination_endpoint_key_ = std::move(destination_endpoint_key);
273
0
    }
274
275
    const GUID_t& destination_endpoint_key() const
276
0
    {
277
0
        return destination_endpoint_key_;
278
0
    }
279
280
    GUID_t& destination_endpoint_key()
281
0
    {
282
0
        return destination_endpoint_key_;
283
0
    }
284
285
    void source_endpoint_key(
286
            const GUID_t& source_endpoint_key)
287
0
    {
288
0
        source_endpoint_key_ = source_endpoint_key;
289
0
    }
290
291
    void source_endpoint_key(
292
            GUID_t&& source_endpoint_key)
293
0
    {
294
0
        source_endpoint_key_ = std::move(source_endpoint_key);
295
0
    }
296
297
    const GUID_t& source_endpoint_key() const
298
0
    {
299
0
        return source_endpoint_key_;
300
0
    }
301
302
    GUID_t& source_endpoint_key()
303
0
    {
304
0
        return source_endpoint_key_;
305
0
    }
306
307
    void message_class_id(
308
            const std::string& message_class_id)
309
0
    {
310
0
        message_class_id_ = message_class_id;
311
0
    }
312
313
    void message_class_id(
314
            std::string&& message_class_id)
315
0
    {
316
0
        message_class_id_ = std::move(message_class_id);
317
0
    }
318
319
    const std::string& message_class_id() const
320
0
    {
321
0
        return message_class_id_;
322
0
    }
323
324
    std::string& message_class_id()
325
0
    {
326
0
        return message_class_id_;
327
0
    }
328
329
    void message_data(
330
            const DataHolderSeq& message_data)
331
0
    {
332
0
        message_data_ = message_data;
333
0
    }
334
335
    void message_data(
336
            DataHolderSeq&& message_data)
337
0
    {
338
0
        message_data_ = std::move(message_data);
339
0
    }
340
341
    const DataHolderSeq& message_data() const
342
0
    {
343
0
        return message_data_;
344
0
    }
345
346
    DataHolderSeq& message_data()
347
0
    {
348
0
        return message_data_;
349
0
    }
350
351
private:
352
353
    MessageIdentity message_identity_;
354
    MessageIdentity related_message_identity_;
355
    GUID_t destination_participant_key_;
356
    GUID_t destination_endpoint_key_;
357
    GUID_t source_endpoint_key_;
358
    std::string message_class_id_;
359
    DataHolderSeq message_data_;
360
};
361
362
class ParticipantGenericMessageHelper
363
{
364
public:
365
366
    static size_t serialized_size(
367
            const ParticipantGenericMessage& message,
368
            size_t current_alignment = 0)
369
0
    {
370
0
        size_t initial_alignment = current_alignment;
371
0
372
0
        current_alignment += MessageIdentityHelper::serialized_size(message.message_identity(), current_alignment);
373
0
        current_alignment += MessageIdentityHelper::serialized_size(
374
0
            message.related_message_identity(), current_alignment);
375
0
        current_alignment += 16 * 3;
376
0
        current_alignment += 4 + alignment(current_alignment, 4) + message.message_class_id().size() + 1;
377
0
        current_alignment += DataHolderHelper::serialized_size(message.message_data(), current_alignment);
378
0
379
0
        return current_alignment - initial_alignment;
380
0
    }
381
382
private:
383
384
    inline static size_t alignment(
385
            size_t current_alignment,
386
            size_t dataSize)
387
0
    {
388
0
        return (dataSize - (current_alignment % dataSize)) & (dataSize - 1);
389
0
    }
390
391
};
392
393
} //namespace security
394
} //namespace rtps
395
} //namespace fastdds
396
} //namespace eprosima
397
398
#endif // _FASTDDS_RTPS_SECURITY_COMMON_PARTICIPANTGENERICMESSAGE_H_