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 #include <vlutil/vlUtil.h>
17 
18 namespace rti1516e
19 {
21  const int endianChecker = 1;
22  #define is_bigendian() ( (*(char*)&endianChecker) == 0 )
23 
25  inline void swapByteArray( char * byteArray, int theSize )
26  {
27  int theEnd = 0;
28  for( int i = 0; i < ( theSize >> 1 ); ++i )
29  {
30  theEnd = ( theSize - 1 ) - i;
31  byteArray[ i ] ^= byteArray[ theEnd ];
32  byteArray[ theEnd ] ^= byteArray[ i ];
33  byteArray[ i ] ^= byteArray[ theEnd ];
34  }
35  }
36 
38  inline unsigned short endianSwap16Bit( unsigned short rhs )
39  {
40  unsigned short msbyte = rhs & 0x00ff;
41  unsigned short lsbyte = ( rhs & 0xff00 ) >> 8;
42  return ( msbyte << 8 ) | lsbyte;
43  }
44 
46  inline unsigned int endianSwap32Bit( unsigned int rhs )
47  {
48  unsigned short msword = endianSwap16Bit( rhs & 0x0000ffff );
49  unsigned short lsword = endianSwap16Bit(( rhs & 0xffff0000 ) >> 16 );
50  return ( msword << 16 ) | lsword;
51  }
52 
54  inline Integer64 endianSwap64Bit( Integer64 rhs )
55  {
57  unsigned int mspart = endianSwap32Bit( static_cast<unsigned int>(rhs & 0xffffffff) );
58  unsigned int lspart = endianSwap32Bit(static_cast<unsigned int>(( rhs >> 32 ) & 0xffffffff) );
59  return ( Integer64( mspart ) << 32 ) | lspart;
60  }
61 
63  inline float endianSwap32BitFloat( float rhs )
64  {
65  union v
66  {
67  float f;
68  unsigned int i;
69  };
70 
71  v val;
72  val.f = rhs;
73  val.i = endianSwap32Bit( val.i );
74 
75  return val.f;
76  }
77 
78  inline double endianSwap64BitDouble( double rhs )
79  {
80  union v
81  {
82  double d;
83  Integer64 i;
84  };
85 
86  v val;
87  val.d = rhs;
88  val.i = endianSwap64Bit( val.i );
89  return val.d;
90  }
91 
93  inline void appendBytes( std::vector<Octet>& wrapper, const char* bytes, size_t length )
94  {
95  // Resize the buffer and then write to it (this is efficient if caller
96  // has already reserved the space - otherwise buffer may re-alloc)
97  unsigned int currentBufferSize = wrapper.size();
98  wrapper.resize( currentBufferSize + length );
99  memcpy( &wrapper[ currentBufferSize ], bytes, length );
100  }
101 
103  inline unsigned int paddingSizeInBytes( unsigned int bufferLength, unsigned int elementOctetBoundary )
104  {
105  return MAKRti::alignedPadding(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
void appendBytes(std::vector< Octet > &wrapper, const char *bytes, size_t length)
append to a octet vector
Definition: encodingImplHelpers.h:93
const int endianChecker
This checks whether the machine is Big Endian or Little Endian.
Definition: encodingImplHelpers.h:21
float endianSwap32BitFloat(float rhs)
swap 32 bit float
Definition: encodingImplHelpers.h:63
unsigned int paddingSizeInBytes(unsigned int bufferLength, unsigned int elementOctetBoundary)
Get the padding for this element.
Definition: encodingImplHelpers.h:103
unsigned short endianSwap16Bit(unsigned short rhs)
swap 16 bits
Definition: encodingImplHelpers.h:38
void swapByteArray(char *byteArray, int theSize)
Swap the byte array in memory.
Definition: encodingImplHelpers.h:25
double endianSwap64BitDouble(double rhs)
Definition: encodingImplHelpers.h:78
void insertBytes(std::vector< Octet > &wrapper, size_t length)
Insert bytes into the octet buffer.
Definition: encodingImplHelpers.h:109
Integer64 endianSwap64Bit(Integer64 rhs)
swap 64 bits
Definition: encodingImplHelpers.h:54
unsigned int endianSwap32Bit(unsigned int rhs)
swap 32 bits
Definition: encodingImplHelpers.h:46

Document ID: Generated on Thu May 11 15:55:32 EDT 2023 from SVN revision 254743
Copyright © 2005-2020 MAK Technologies Inc. All Rights Reserved (www.mak.com)