20 using namespace ::exception;
24 : m_currentPosition(fastcdr.m_currentPosition)
29 const state& current_state)
45 bool returnedValue =
false;
106 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
110 const char* string_t)
114 if (string_t !=
nullptr)
132 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
144 const wchar_t* string_t)
146 uint32_t bytesLength = 0;
149 if (string_t !=
nullptr)
151 wstrlen = wcslen(string_t);
167 #endif // if defined(_WIN32) 172 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
187 size_t totalSize =
sizeof(*bool_t) * numElements;
205 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
212 size_t totalSize =
sizeof(*char_t) * numElements;
221 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
225 const int16_t* short_t,
228 size_t totalSize =
sizeof(*short_t) * numElements;
238 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
242 const int32_t* long_t,
245 size_t totalSize =
sizeof(*long_t) * numElements;
255 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
259 const wchar_t* wchar,
270 const int64_t* longlong_t,
273 size_t totalSize =
sizeof(*longlong_t) * numElements;
283 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
287 const float* float_t,
290 size_t totalSize =
sizeof(*float_t) * numElements;
300 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
304 const double* double_t,
307 size_t totalSize =
sizeof(*double_t) * numElements;
317 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
321 const long double* ldouble_t,
324 size_t totalSize = 16 * numElements;
328 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16 329 for (
size_t idx = 0; idx < numElements; ++idx)
331 __float128 tmp = ldouble_t[idx];
336 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16 340 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 341 for (
size_t idx = 0; idx < numElements; ++idx)
343 m_currentPosition << static_cast<long double>(0);
345 m_currentPosition << ldouble_t[idx];
346 m_currentPosition += 8;
349 #error unsupported long double type and no __float128 available 350 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 351 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16 352 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16 357 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
380 throw BadParamException(
"Got unexpected byte value in deserialize for bool (expected 0 or 1)");
383 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
403 reinterpret_cast<char*
>(calloc(length + ((&
m_currentPosition)[length - 1] ==
'\0' ? 0 : 1),
411 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
430 string_t =
reinterpret_cast<wchar_t*
>(calloc(length + 1,
sizeof(
wchar_t)));
433 for (
size_t idx = 0; idx < length; ++idx)
437 string_t[idx] =
static_cast<wchar_t>(temp);
443 #endif // if defined(_WIN32) 449 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
455 const char* returnedValue =
"";
456 state state_before_error(*
this);
462 return returnedValue;
468 if (returnedValue[length - 1] ==
'\0')
472 return returnedValue;
483 std::wstring returnedValue = L
"";
487 uint32_t bytesLength = length * 4;
489 if (bytesLength == 0)
491 return returnedValue;
496 returnedValue.resize(length);
498 if (returnedValue[length - 1] == L
'\0')
501 returnedValue.erase(length);
503 return returnedValue;
515 size_t totalSize =
sizeof(*bool_t) * numElements;
526 bool_t[
count] =
true;
530 bool_t[
count] =
false;
537 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
544 size_t totalSize =
sizeof(*char_t) * numElements;
553 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
560 size_t totalSize =
sizeof(*short_t) * numElements;
570 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
577 size_t totalSize =
sizeof(*long_t) * numElements;
587 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
598 wchar[
count] =
static_cast<wchar_t>(value);
607 size_t totalSize =
sizeof(*longlong_t) * numElements;
617 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
624 size_t totalSize =
sizeof(*float_t) * numElements;
634 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
641 size_t totalSize =
sizeof(*double_t) * numElements;
651 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
655 long double* ldouble_t,
658 size_t totalSize = 16 * numElements;
662 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16 663 for (
size_t idx = 0; idx < numElements; ++idx)
668 ldouble_t[idx] =
static_cast<long double>(tmp);
671 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16 675 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 676 for (
size_t idx = 0; idx < numElements; ++idx)
683 #error unsupported long double type and no __float128 available 684 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 685 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16 686 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16 691 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
695 const std::vector<bool>& vector_t)
697 state state_before_error(*
this);
699 *this << static_cast<int32_t>(vector_t.size());
701 size_t totalSize = vector_t.size() *
sizeof(bool);
708 std::vector<bool>::const_reference ref = vector_t[
count];
720 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
727 std::vector<bool>& vector_t)
729 uint32_t seqLength = 0;
730 state state_before_error(*
this);
734 size_t totalSize = seqLength *
sizeof(bool);
738 vector_t.resize(seqLength);
746 vector_t[
count] =
true;
750 vector_t[
count] =
false;
757 throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
764 std::string*& sequence_t,
767 uint32_t seqLength = 0;
768 state state_before_error(*
this);
774 sequence_t =
new std::string[seqLength];
779 delete [] sequence_t;
785 numElements = seqLength;
790 std::wstring*& sequence_t,
793 uint32_t seqLength = 0;
794 state state_before_error(*
this);
800 sequence_t =
new std::wstring[seqLength];
805 delete [] sequence_t;
811 numElements = seqLength;
virtual Cdr_DllAPI void raise() const =0
This function throws the object as exception.
This class stores the current state of a CDR serialization.
This abstract class is used to create exceptions.
typename detail::char_t_impl< S >::type char_t
This class is thrown as an exception when the buffer's internal memory reachs its size limit...
FastCdr(FastBuffer &cdrBuffer)
This constructor creates a eprosima::fastcdr::FastCdr object that can serialize/deserialize the assig...
This class offers an interface to serialize/deserialize some basic types using a modified CDR protoco...
FastCdr & serializeBoolSequence(const std::vector< bool > &vector_t)
static Cdr_DllAPI const char *const NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
Default message used in the library.
FastCdr & deserializeStringSequence(std::string *&sequence_t, size_t &numElements)
char * getCurrentPosition()
This function returns the current position in the CDR stream.
iterator begin()
This function returns a iterator that points to the begining of the stream.
FastCdr & deserializeArray(uint8_t *octet_t, size_t numElements)
This function deserializes an array of octets.
uint32_t size_to_uint32(size_t val)
void rmemcopy(void *dst, const size_t size)
This function copies from the raw buffer to a external buffer.
FastCdr & deserializeBoolSequence(std::vector< bool > &vector_t)
constexpr auto count() -> size_t
FastCdr & deserializeWStringSequence(std::wstring *&sequence_t, size_t &numElements)
FastCdr & serializeArray(const uint8_t *octet_t, size_t numElements)
This function serializes an array of octets.
FastBuffer::iterator m_currentPosition
The current position in the serialization/deserialization process.
const char * readString(uint32_t &length)
FastBuffer & m_cdrBuffer
Reference to the buffer that will be serialized/deserialized.
state(const FastCdr &fastcdr)
Default constructor.
const FastBuffer::iterator m_currentPosition
The position in the buffer when the state was created.
void reset()
This function resets the current position in the buffer to the begining.
This class represents a stream of bytes that contains (or will contain) serialized data...
bool jump(size_t numBytes)
This function skips a number of bytes in the CDR stream buffer.
FastCdr::state getState()
This function returns the current state of the CDR stream.
bool resize(size_t minSizeInc)
This function resizes the raw buffer. It will call the user's defined function for this purpose...
bool resize(size_t minSizeInc)
FastCdr & serialize(const uint8_t octet_t)
This function serializes an octet.
void memcopy(const void *src, const size_t size)
This function copies a buffer into the raw buffer.
iterator end()
This function returns a iterator that points to the end of the stream.
FastCdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
FastBuffer::iterator m_lastPosition
The last position in the buffer;.
std::wstring readWString(uint32_t &length)
void setState(FastCdr::state &state)
This function sets a previous state of the CDR stream;.