13#ifndef RTI_XCDR_STREAM_HPP_
14#define RTI_XCDR_STREAM_HPP_
16#include "xcdr/xcdr_stream.h"
18namespace rti {
namespace xcdr {
21#define RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_BODY(\
25 static void serialize_fast(RTIXCdrStream *stream, const TYPE* v)\
27 RTIXCdrStream_ ## SERIALIZE_MACRO ## ByteFast(stream, (CDR_TYPE *) v);\
29 static void deserialize_fast(RTIXCdrStream *stream, TYPE* v)\
31 RTIXCdrStream_de ## SERIALIZE_MACRO ## ByteFast(stream, (CDR_TYPE *) v);\
33 static bool serialize(RTIXCdrStream *stream, const TYPE* v)\
35 return RTIXCdrStream_ ## SERIALIZE_MACRO ## Byte(stream, (CDR_TYPE *) v, RTI_XCDR_TRUE);\
37 static bool deserialize(RTIXCdrStream *stream, TYPE* v)\
39 return RTIXCdrStream_de ## SERIALIZE_MACRO ## Byte(stream, (CDR_TYPE *) v, RTI_XCDR_TRUE);\
42#define RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
47struct primitive_type_traits<TYPE> {\
48RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_BODY(TYPE, CDR_TYPE, SERIALIZE_MACRO)\
51#define RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_W_ALIGNMENT_PARAM(\
57struct primitive_type_traits<TYPE> {\
58 static void serialize_fast(RTIXCdrStream *stream, const TYPE* v)\
60 RTIXCdrStream_ ## SERIALIZE_MACRO ## ByteFast(stream, (CDR_TYPE *) v);\
62 static void deserialize_fast(RTIXCdrStream *stream, TYPE* v)\
64 RTIXCdrStream_de ## SERIALIZE_MACRO ## ByteFast(stream, (CDR_TYPE *) v);\
66 static bool serialize(RTIXCdrStream *stream, const TYPE* v)\
68 return RTIXCdrStream_ ## SERIALIZE_MACRO ## Byte(stream, (CDR_TYPE *) v, RTI_XCDR_TRUE, ALIGNMENT);\
70 static bool deserialize(RTIXCdrStream *stream, TYPE* v)\
72 return RTIXCdrStream_de ## SERIALIZE_MACRO ## Byte(stream, (CDR_TYPE *) v, RTI_XCDR_TRUE, ALIGNMENT);\
76#define RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_NO_ALIGN_PARAM(\
81struct primitive_type_traits<TYPE> {\
82 static void serialize_fast(RTIXCdrStream *stream, const TYPE* v)\
84 RTIXCdrStream_ ## SERIALIZE_MACRO ## ByteFast(stream, (CDR_TYPE *) v);\
86 static void deserialize_fast(RTIXCdrStream *stream, TYPE* v)\
88 RTIXCdrStream_de ## SERIALIZE_MACRO ## ByteFast(stream, (CDR_TYPE *) v);\
90 static bool serialize(RTIXCdrStream *stream, const TYPE* v)\
92 return RTIXCdrStream_ ## SERIALIZE_MACRO ## Byte(stream, (CDR_TYPE *) v);\
94 static bool deserialize(RTIXCdrStream *stream, TYPE* v)\
96 return RTIXCdrStream_de ## SERIALIZE_MACRO ## Byte(stream, (CDR_TYPE *) v);\
103struct primitive_type_traits {
104 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_BODY(T, RTIXCdr4Byte, serialize4)
107RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_NO_ALIGN_PARAM(\
108 char, RTIXCdr1Byte, serialize1);
119#if !defined(RTI_AVOID_FIXED_WIDTH_INTEGERS)
120RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_NO_ALIGN_PARAM(\
121 uint8_t, RTIXCdr1Byte, serialize1);
123RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
124 int16_t, RTIXCdr2Byte, serialize2);
125RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
126 uint16_t, RTIXCdr2Byte, serialize2);
128RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
129 int32_t, RTIXCdr4Byte, serialize4);
130RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
131 uint32_t, RTIXCdr4Byte, serialize4);
133typedef uint32_t length_t;
135RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_NO_ALIGN_PARAM(\
136 unsigned char, RTIXCdr1Byte, serialize1);
138RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
139 short, RTIXCdr2Byte, serialize2);
140RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
141 unsigned short, RTIXCdr2Byte, serialize2);
145typedef unsigned int length_t;
148RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
149 float, RTIXCdr4Byte, serialize4);
151RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_W_ALIGNMENT_PARAM(\
154RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_W_ALIGNMENT_PARAM(\
156RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_W_ALIGNMENT_PARAM(\
157 double, RTIXCdr8Byte, serialize8, 4);
163void serialize_fast(RTIXCdrStream& stream,
const T& value)
165 primitive_type_traits<T>::serialize_fast(&stream, &value);
169void deserialize_fast(RTIXCdrStream& stream, T& value)
171 primitive_type_traits<T>::deserialize_fast(&stream, &value);
178 RTIXCdrStream_set(&stream_, NULL, 0);
181 explicit Stream(
const RTIXCdrStream& c_stream)
188 Stream(
const Stream& other)
190 stream_ = other.stream_;
196 unsigned char *buffer,
200 RTIXCdrFlatData_initializeStream(
207 Stream& operator=(
const Stream& other)
209 stream_ = other.stream_;
213 bool skip(length_t size)
215 if (!check_size(size)) {
218 RTIXCdrStream_increaseCurrentPosition(&stream_, size);
222 void skip_fast(length_t size)
224 RTIXCdrStream_increaseCurrentPosition(&stream_, size);
227 void skip_back(length_t bytes)
229 RTIXCdrStream_increaseCurrentPosition(
231 -
static_cast<int>(bytes));
234 unsigned char * buffer()
236 return reinterpret_cast<unsigned char*
>(stream_._buffer);
239 const unsigned char * buffer()
const
241 return reinterpret_cast<unsigned char*
>(stream_._buffer);
244 unsigned char * current_position()
246 return reinterpret_cast<unsigned char*
>(
247 RTIXCdrStream_getCurrentPosition(&stream_));
250 void current_position(
unsigned char * pos)
252 RTIXCdrStream_setCurrentPosition(
254 reinterpret_cast<char*
>(pos));
257 length_t used_size()
const
259 return static_cast<length_t
>(
260 RTIXCdrStream_getCurrentPosition(&stream_) - stream_._buffer);
263 length_t remaining_size()
const
265 return total_size() - used_size();
268 length_t total_size()
const
270 return stream_._bufferLength;
273 bool needs_byte_swap()
const
275 return stream_._needByteSwap == RTI_XCDR_TRUE;
278 template <
typename T>
279 bool serialize(T value)
281 return primitive_type_traits<T>::serialize(&stream_, &value);
284 template <
typename T>
285 void serialize_fast(T value)
287 primitive_type_traits<T>::serialize_fast(&stream_, &value);
290 template <
typename T>
291 bool serialize_no_align(T value)
293 if (!check_size(
sizeof(T))) {
296 primitive_type_traits<T>::serialize_fast(&stream_, &value);
300 template <
typename T>
304 primitive_type_traits<T>::deserialize_fast(&stream_, &value);
308 void serialize_fast(
const void *array, length_t bytes)
310 RTIXCdrStream_serializeNByteFast(&stream_, array, bytes);
313 char * serialize_dheader()
315 return RTIXCdrStream_serializeDHeader(&stream_);
318 bool finish_dheader(
char *dheader_position)
320 return RTIXCdrStream_serializeDHeaderLength(&stream_, dheader_position)
324 bool serialize_emheader(
326 RTIXCdrUnsignedLong parameter_id,
327 RTIXCdrUnsignedLong lc,
328 bool must_understand =
false)
330 RTIXCdrBoolean failure = 0;
331 position = RTIXCdrStream_serializeV2ParameterHeader(
335 must_understand ? RTI_XCDR_TRUE : RTI_XCDR_FALSE,
338 return failure == RTI_XCDR_FALSE;
341 void finish_emheader(
char * emheader_position)
343 RTIXCdrStream_finishV2ParameterHeader(&stream_, emheader_position);
346 bool align(
unsigned int alignment)
348 return RTIXCdrStream_align(&stream_, (RTIXCdrAlignment) alignment)
352 bool check_size(length_t size)
const
354 bool result = RTIXCdrStream_checkSize(&stream_, size) == RTI_XCDR_TRUE;
358 bool need_byte_swap()
const
360 return stream_._needByteSwap != 0;
363 RTIXCdrStream& c_stream()
379 explicit Memento(Stream& stream) :
381 original_position_(stream.current_position()),
382 relative_buffer_(stream.c_stream()._relativeBuffer)
395 if (original_position_ != NULL) {
396 stream_.current_position(original_position_);
397 stream_.c_stream()._relativeBuffer = relative_buffer_;
402 unsigned char * discard()
404 unsigned char *pos = original_position_;
405 original_position_ = NULL;
411 unsigned char *original_position_;
412 char *relative_buffer_;
417 RTIXCdrStream stream_;
RTICdrLongLong DDS_LongLong
Defines an extra-long integer data type, equivalent to IDL/CDR long long.
Definition: dds_c.1.0/interface/common.ifc:254
RTICdrUnsignedLongLong DDS_UnsignedLongLong
Defines an unsigned extra-long data type, equivalent to IDL/CDR unsigned long long.
Definition: dds_c.1.0/interface/common.ifc:259
The RTI namespace.
Definition: AggregationBuilders.hpp:17