1515#include < fastcdr/FastCdr.h>
1616#include < fastcdr/exceptions/BadParamException.h>
1717#include < string.h>
18+ #include " helpers/memory_helpers.hpp"
1819
1920using namespace eprosima ::fastcdr;
2021using namespace ::exception;
@@ -90,15 +91,9 @@ bool FastCdr::resize(
9091FastCdr& FastCdr::serialize (
9192 const bool bool_t )
9293{
93- uint8_t value = 0 ;
94-
9594 if (((last_position_ - current_position_) >= sizeof (uint8_t )) || resize (sizeof (uint8_t )))
9695 {
97- if (bool_t )
98- {
99- value = 1 ;
100- }
101- current_position_++ << value;
96+ serialize_bool (bool_t );
10297
10398 return *this ;
10499 }
@@ -190,13 +185,7 @@ FastCdr& FastCdr::serialize_array(
190185 {
191186 for (size_t count = 0 ; count < num_elements; ++count)
192187 {
193- uint8_t value = 0 ;
194-
195- if (bool_t [count])
196- {
197- value = 1 ;
198- }
199- current_position_++ << value;
188+ serialize_bool (bool_t [count]);
200189 }
201190
202191 return *this ;
@@ -691,6 +680,16 @@ FastCdr& FastCdr::deserialize_array(
691680 throw NotEnoughMemoryException (NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT );
692681}
693682
683+ inline void FastCdr::serialize_bool (
684+ bool bool_t )
685+ {
686+ #if FASTCDR_STRICT_BOOL
687+ current_position_++ << static_cast <uint8_t >(normalize_bool (bool_t ));
688+ #else
689+ current_position_++ << (bool_t ? static_cast <uint8_t >(1 ) : static_cast <uint8_t >(0 ));
690+ #endif // if FASTCDR_STRICT_BOOL
691+ }
692+
694693FastCdr& FastCdr::serialize_bool_sequence (
695694 const std::vector<bool >& vector_t )
696695{
@@ -704,14 +703,7 @@ FastCdr& FastCdr::serialize_bool_sequence(
704703 {
705704 for (size_t count = 0 ; count < vector_t .size (); ++count)
706705 {
707- uint8_t value = 0 ;
708- std::vector<bool >::const_reference ref = vector_t [count];
709-
710- if (ref)
711- {
712- value = 1 ;
713- }
714- current_position_++ << value;
706+ serialize_bool (vector_t [count]);
715707 }
716708 }
717709 else
0 commit comments