MAK RTIspy API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
encodingImplHelpers.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2010 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: encodingImplHelpers.h,v $ $Revision: 1.0 $ $State: Exp $
7 *********************************************************************/
10 
11 #ifndef encodingImplHelpers_H_
12 #define encodingImplHelpers_H_
13 
14 #include <typeinfo>
15 #include <cstring>
16 
17 namespace rti1516e
18 {
20  const int endianChecker = 1;
21  #define is_bigendian() ( (*(char*)&endianChecker) == 0 )
22 
24  inline void swapByteArray( char * byteArray, int theSize )
25  {
26  int theEnd = 0;
27  for( int i = 0; i < ( theSize >> 1 ); ++i )
28  {
29  theEnd = ( theSize - 1 ) - i;
30  byteArray[ i ] ^= byteArray[ theEnd ];
31  byteArray[ theEnd ] ^= byteArray[ i ];
32  byteArray[ i ] ^= byteArray[ theEnd ];
33  }
34  }
35 
37  inline unsigned short endianSwap16Bit( unsigned short rhs )
38  {
39  unsigned short msbyte = rhs & 0x00ff;
40  unsigned short lsbyte = ( rhs & 0xff00 ) >> 8;
41  return ( msbyte << 8 ) | lsbyte;
42  }
43 
45  inline unsigned int endianSwap32Bit( unsigned int rhs )
46  {
47  unsigned short msword = endianSwap16Bit( rhs & 0x0000ffff );
48  unsigned short lsword = endianSwap16Bit(( rhs & 0xffff0000 ) >> 16 );
49  return ( msword << 16 ) | lsword;
50  }
51 
54  {
56  unsigned int mspart = endianSwap32Bit( static_cast<unsigned int>(rhs & 0xffffffff) );
57  unsigned int lspart = endianSwap32Bit(static_cast<unsigned int>(( rhs >> 32 ) & 0xffffffff) );
58  return ( Integer64( mspart ) << 32 ) | lspart;
59  }
60 
62  inline float endianSwap32BitFloat( float rhs )
63  {
64  union v
65  {
66  float f;
67  unsigned int i;
68  };
69 
70  v val;
71  val.f = rhs;
72  val.i = endianSwap32Bit( val.i );
73 
74  return val.f;
75  }
76 
77  inline double endianSwap64BitDouble( double rhs )
78  {
79  union v
80  {
81  double d;
82  Integer64 i;
83  };
84 
85  v val;
86  val.d = rhs;
87  val.i = endianSwap64Bit( val.i );
88  return val.d;
89  }
90 
92  inline void appendBytes( std::vector<Octet>& wrapper, const char* bytes, size_t length )
93  {
94  // Resize the buffer and then write to it (this is efficient if caller
95  // has already reserved the space - otherwise buffer may re-alloc)
96  unsigned int currentBufferSize = wrapper.size();
97  wrapper.resize( currentBufferSize + length );
98  memcpy( &wrapper[ currentBufferSize ], bytes, length );
99  }
100 
102  inline unsigned int paddingSizeInBytes( unsigned int bufferLength, unsigned int elementOctetBoundary )
103  {
104  if ( bufferLength == 0 ) return 0;
105  return bufferLength % elementOctetBoundary;
106  }
107 
109  inline void insertBytes( std::vector<Octet>& wrapper, size_t length )
110  {
113  unsigned int currentBufferSize = wrapper.size();
114  wrapper.resize( currentBufferSize + length );
115  }
116 }
117 
118 #endif

Document ID: Generated on Wed Mar 11 20:26:49 EDT 2015 from SVN revision 150939
Copyright © 2005-2015 VT MÄK Inc. All Rights Reserved (www.mak.com)