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 
17 namespace eprosima {
18 namespace fastcdr {
19 
21  CdrVersion cdr_version)
22  : cdr_version_(cdr_version)
23 {
24  switch (cdr_version_)
25  {
26  case CdrVersion::XCDRv2:
27  break;
28  default:
30  align64_ = 8;
31  break;
32  }
33 }
34 
36  CdrVersion cdr_version,
37  EncodingAlgorithmFlag encoding)
38  : cdr_version_(cdr_version)
39  , current_encoding_(encoding)
40 {
41 }
42 
44 {
45  return cdr_version_;
46 }
47 
49 {
50  return current_encoding_;
51 }
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
eprosima::fastcdr::CdrSizeCalculator::current_encoding_
EncodingAlgorithmFlag current_encoding_
Definition: CdrSizeCalculator.hpp:1306
eprosima::fastcdr::CdrSizeCalculator::get_encoding
Cdr_DllAPI EncodingAlgorithmFlag get_encoding() const
Retrieves the current encoding algorithm used by the instance.
Definition: CdrSizeCalculator.cpp:48
CdrSizeCalculator.hpp
eprosima::fastcdr::CdrSizeCalculator::begin_calculate_type_serialized_size
Cdr_DllAPI size_t begin_calculate_type_serialized_size(EncodingAlgorithmFlag new_encoding, size_t &current_alignment)
Indicates a new constructed type will be calculated.
Definition: CdrSizeCalculator.cpp:53
eprosima::fastcdr::CdrSizeCalculator::cdr_version_
CdrVersion cdr_version_
Definition: CdrSizeCalculator.hpp:1304
eprosima::fastcdr::CdrSizeCalculator::end_calculate_type_serialized_size
Cdr_DllAPI size_t end_calculate_type_serialized_size(EncodingAlgorithmFlag new_encoding, size_t &current_alignment)
Indicates the ending of a constructed type.
Definition: CdrSizeCalculator.cpp:72
eprosima::fastcdr::PL_CDR
@ PL_CDR
Specifies that the content is PL_CDR,.
Definition: CdrEncoding.hpp:42
eprosima::fastcdr::CdrVersion
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
Definition: CdrEncoding.hpp:24
eprosima::fastcdr::CdrSizeCalculator::alignment
size_t alignment(size_t current_alignment, size_t data_size) const
Definition: CdrSizeCalculator.hpp:1321
eprosima::fastcdr::CdrSizeCalculator::get_cdr_version
Cdr_DllAPI CdrVersion get_cdr_version() const
Retrieves the version of the encoding algorithm used by the instance.
Definition: CdrSizeCalculator.cpp:43
eprosima::fastcdr::PLAIN_CDR
@ PLAIN_CDR
Specifies that the content is PLAIN_CDR.
Definition: CdrEncoding.hpp:40
eprosima::fastcdr::PLAIN_CDR2
@ PLAIN_CDR2
Specifies that the content is PLAIN_CDR2.
Definition: CdrEncoding.hpp:44
eprosima::fastcdr::XCDRv2
@ XCDRv2
XCDRv2 encoding defined by standard DDS X-Types 1.3.
Definition: CdrEncoding.hpp:33
eprosima::fastcdr::CdrSizeCalculator::CdrSizeCalculator
CdrSizeCalculator()=delete
eprosima::fastcdr::XCDRv1
@ XCDRv1
XCDRv1 encoding defined by standard DDS X-Types 1.3.
Definition: CdrEncoding.hpp:31
eprosima::fastcdr::CdrSizeCalculator::align64_
size_t align64_
Align for types equal or greater than 64bits.
Definition: CdrSizeCalculator.hpp:1319
eprosima::fastcdr::CdrSizeCalculator::SERIALIZED_MEMBER_SIZE
@ SERIALIZED_MEMBER_SIZE
Definition: CdrSizeCalculator.hpp:1311
eprosima::fastcdr::CdrSizeCalculator::NO_SERIALIZED_MEMBER_SIZE
enum eprosima::fastcdr::CdrSizeCalculator::SerializedMemberSizeForNextInt NO_SERIALIZED_MEMBER_SIZE
Specifies if a DHEADER was serialized. Used to calculate XCDRv2 member headers.
eprosima::fastcdr::EncodingAlgorithmFlag
EncodingAlgorithmFlag
This enumeration represents the supported XCDR encoding algorithms.
Definition: CdrEncoding.hpp:37
eprosima
Definition: fixed_size_string.hpp:32


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:43