pjmsg_mcap_wrapper
Loading...
Searching...
No Matches
CdrSizeCalculator.cpp
Go to the documentation of this file.
1// Copyright 2023 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
16
17namespace eprosima {
18namespace fastcdr {
19
21 CdrVersion cdr_version)
22 : cdr_version_(cdr_version)
23{
24 switch (cdr_version_)
25 {
27 break;
28 default:
30 align64_ = 8;
31 break;
32 }
33}
34
36 CdrVersion cdr_version,
37 EncodingAlgorithmFlag encoding)
38 : CdrSizeCalculator(cdr_version)
39{
40 current_encoding_ = encoding;
41}
42
47
52
54 EncodingAlgorithmFlag new_encoding,
55 size_t& current_alignment)
56{
57 size_t calculated_size {0};
58 current_encoding_ = new_encoding;
59
61 {
62 calculated_size = 4 + alignment(current_alignment, 4); // DHEADER
63 }
64
65 current_alignment += calculated_size;
66
67 serialized_member_size_ = NO_SERIALIZED_MEMBER_SIZE; // Avoid error when serializing arrays, sequences, etc..
68
69 return calculated_size;
70}
71
73 EncodingAlgorithmFlag new_encoding,
74 size_t& current_alignment)
75{
76 size_t calculated_size {0};
77
79 {
80 calculated_size = 4 + alignment(current_alignment, 4); // Sentinel
81 }
83 {
84 serialized_member_size_ = SERIALIZED_MEMBER_SIZE;
85 }
86
87 current_alignment += calculated_size;
88
89 current_encoding_ = new_encoding;
90
91 return calculated_size;
92}
93
94} // namespace fastcdr
95} // namespace eprosima
This class offers an interface to calculate the encoded size of a type serialized using a support enc...
enum eprosima::fastcdr::CdrSizeCalculator::SerializedMemberSizeForNextInt NO_SERIALIZED_MEMBER_SIZE
Specifies if a DHEADER was serialized. Used to calculate XCDRv2 member headers.
Cdr_DllAPI EncodingAlgorithmFlag get_encoding() const
Retrieves the current encoding algorithm used by the instance.
Cdr_DllAPI CdrVersion get_cdr_version() const
Retrieves the version of the encoding algorithm used by the instance.
Cdr_DllAPI size_t begin_calculate_type_serialized_size(EncodingAlgorithmFlag new_encoding, size_t &current_alignment)
Indicates a new constructed type will be calculated.
Cdr_DllAPI size_t end_calculate_type_serialized_size(EncodingAlgorithmFlag new_encoding, size_t &current_alignment)
Indicates the ending of a constructed type.
size_t alignment(size_t current_alignment, size_t data_size) const
size_t align64_
Align for types equal or greater than 64bits.
EncodingAlgorithmFlag
This enumeration represents the supported XCDR encoding algorithms.
@ PLAIN_CDR
Specifies that the content is PLAIN_CDR.
@ PLAIN_CDR2
Specifies that the content is PLAIN_CDR2.
@ PL_CDR
Specifies that the content is PL_CDR,.
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
@ XCDRv1
XCDRv1 encoding defined by standard DDS X-Types 1.3.
@ XCDRv2
XCDRv2 encoding defined by standard DDS X-Types 1.3.
Definition Cdr.h:49