13 #ifndef RTI_XCDR_STREAM_HPP_ 14 #define RTI_XCDR_STREAM_HPP_ 16 #include "xcdr/xcdr_stream.h" 18 namespace 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(\ 47 struct primitive_type_traits<TYPE> {\ 48 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_BODY(TYPE, CDR_TYPE, SERIALIZE_MACRO)\ 51 #define RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_W_ALIGNMENT_PARAM(\ 57 struct 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(\ 81 struct 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);\ 102 template <
typename T>
103 struct primitive_type_traits {
104 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_BODY(T, RTIXCdr4Byte, serialize4)
107 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_NO_ALIGN_PARAM(\
108 char, RTIXCdr1Byte, serialize1);
119 #if !defined(RTI_AVOID_FIXED_WIDTH_INTEGERS) 120 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_NO_ALIGN_PARAM(\
121 uint8_t, RTIXCdr1Byte, serialize1);
123 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
124 int16_t, RTIXCdr2Byte, serialize2);
125 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
126 uint16_t, RTIXCdr2Byte, serialize2);
128 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
129 int32_t, RTIXCdr4Byte, serialize4);
130 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
131 uint32_t, RTIXCdr4Byte, serialize4);
133 typedef uint32_t length_t;
135 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_NO_ALIGN_PARAM(\
136 unsigned char, RTIXCdr1Byte, serialize1);
138 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
139 short, RTIXCdr2Byte, serialize2);
140 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
141 unsigned short, RTIXCdr2Byte, serialize2);
145 typedef unsigned int length_t;
148 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS(\
149 float, RTIXCdr4Byte, serialize4);
151 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_W_ALIGNMENT_PARAM(\
154 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_W_ALIGNMENT_PARAM(\
156 RTI_XCDR_SPECIALIZE_PRIMITIVE_TYPE_TRAITS_W_ALIGNMENT_PARAM(\
157 double, RTIXCdr8Byte, serialize8, 4);
162 template <
typename T>
163 void serialize_fast(RTIXCdrStream& stream,
const T& value)
165 primitive_type_traits<T>::serialize_fast(&stream, &value);
168 template <
typename T>
169 void 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 bool skip(length_t size)
209 if (!check_size(size)) {
212 RTIXCdrStream_increaseCurrentPosition(&stream_, size);
216 void skip_fast(length_t size)
218 RTIXCdrStream_increaseCurrentPosition(&stream_, size);
221 void skip_back(length_t bytes)
223 RTIXCdrStream_increaseCurrentPosition(
225 -static_cast<int>(bytes));
228 unsigned char * buffer()
230 return reinterpret_cast<unsigned char*
>(stream_._buffer);
233 const unsigned char * buffer()
const 235 return reinterpret_cast<unsigned char*
>(stream_._buffer);
238 unsigned char * current_position()
240 return reinterpret_cast<unsigned char*
>(
241 RTIXCdrStream_getCurrentPosition(&stream_));
244 void current_position(
unsigned char * pos)
246 RTIXCdrStream_setCurrentPosition(
248 reinterpret_cast<char*>(pos));
251 length_t used_size()
const 253 return static_cast<length_t
>(
254 RTIXCdrStream_getCurrentPosition(&stream_) - stream_._buffer);
257 length_t remaining_size()
const 259 return total_size() - used_size();
262 length_t total_size()
const 264 return stream_._bufferLength;
267 bool needs_byte_swap()
const 269 return stream_._needByteSwap == RTI_XCDR_TRUE;
272 template <
typename T>
273 bool serialize(T value)
275 return primitive_type_traits<T>::serialize(&stream_, &value);
278 template <
typename T>
279 void serialize_fast(T value)
281 primitive_type_traits<T>::serialize_fast(&stream_, &value);
284 template <
typename T>
285 bool serialize_no_align(T value)
287 if (!check_size(
sizeof(T))) {
290 primitive_type_traits<T>::serialize_fast(&stream_, &value);
294 template <
typename T>
298 primitive_type_traits<T>::deserialize_fast(&stream_, &value);
302 void serialize_fast(
const void *array, length_t bytes)
304 RTIXCdrStream_serializeNByteFast(&stream_, array, bytes);
307 char * serialize_dheader()
309 return RTIXCdrStream_serializeDHeader(&stream_);
312 bool finish_dheader(
char *dheader_position)
314 return RTIXCdrStream_serializeDHeaderLength(&stream_, dheader_position)
318 bool serialize_emheader(
320 RTIXCdrUnsignedLong parameter_id,
321 RTIXCdrUnsignedLong lc,
322 bool must_understand =
false)
324 RTIXCdrBoolean failure = 0;
325 position = RTIXCdrStream_serializeV2ParameterHeader(
329 must_understand ? RTI_XCDR_TRUE : RTI_XCDR_FALSE,
332 return failure == RTI_XCDR_FALSE;
335 void finish_emheader(
char * emheader_position)
337 RTIXCdrStream_finishV2ParameterHeader(&stream_, emheader_position);
340 bool align(
unsigned int alignment)
342 return RTIXCdrStream_align(&stream_, (RTIXCdrAlignment) alignment)
346 bool check_size(length_t size)
const 348 bool result = RTIXCdrStream_checkSize(&stream_, size) == RTI_XCDR_TRUE;
352 bool need_byte_swap()
const 354 return stream_._needByteSwap != 0;
357 RTIXCdrStream& c_stream()
373 explicit Memento(Stream& stream) :
375 original_position_(stream.current_position()),
376 relative_buffer_(stream.c_stream()._relativeBuffer)
389 if (original_position_ != NULL) {
390 stream_.current_position(original_position_);
391 stream_.c_stream()._relativeBuffer = relative_buffer_;
396 unsigned char * discard()
398 unsigned char *pos = original_position_;
399 original_position_ = NULL;
405 unsigned char *original_position_;
406 char *relative_buffer_;
411 RTIXCdrStream stream_;
416 #endif // RTI_XCDR_STREAM_HPP_ 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
Definition: AggregationBuilders.hpp:17