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 <rtiApiTypes.h>
15 
16 #include <vlutil/vlUtil.h>
17 
18 #include <RTI/encoding/EncodingConfig.h>
19 
20 #include <typeinfo>
21 #include <cstring>
22 
23 namespace RTI_API
24 {
26  const int endianChecker = 1;
27  #define IS_MACHINE_BIG_ENDIAN() ( (*(char*)&endianChecker) == 0 )
28 
30  inline void swapByteArray( char * byteArray, int theSize )
31  {
32  int theEnd = 0;
33  for( int i = 0; i < ( theSize >> 1 ); ++i )
34  {
35  theEnd = ( theSize - 1 ) - i;
36  byteArray[ i ] ^= byteArray[ theEnd ];
37  byteArray[ theEnd ] ^= byteArray[ i ];
38  byteArray[ i ] ^= byteArray[ theEnd ];
39  }
40  }
41 
43  inline unsigned short endianSwap16Bit( unsigned short rhs )
44  {
45  unsigned short msbyte = rhs & 0x00ff;
46  unsigned short lsbyte = ( rhs & 0xff00 ) >> 8;
47  return ( msbyte << 8 ) | lsbyte;
48  }
49 
50  template<typename T>
51  inline Integer64 valueHash(T value)
52  {
53  return static_cast<Integer64>(value);
54  }
55 
56  inline Integer64 valueHash(OctetPair value)
57  {
58  return (static_cast<Integer64>(value.first) << 8) + value.second;
59  }
60 
62  inline unsigned int endianSwap32Bit( unsigned int rhs )
63  {
64  unsigned short msword = endianSwap16Bit( rhs & 0x0000ffff );
65  unsigned short lsword = endianSwap16Bit(( rhs & 0xffff0000 ) >> 16 );
66  return ( msword << 16 ) | lsword;
67  }
68 
70  inline Integer64 endianSwap64Bit( Integer64 rhs )
71  {
73  unsigned int mspart = endianSwap32Bit( static_cast<unsigned int>(rhs & 0xffffffff) );
74  unsigned int lspart = endianSwap32Bit(static_cast<unsigned int>(( rhs >> 32 ) & 0xffffffff) );
75  return ( Integer64( mspart ) << 32 ) | lspart;
76  }
77 
79  inline float endianSwap32BitFloat( float rhs )
80  {
81  union v
82  {
83  float f;
84  unsigned int i;
85  };
86 
87  v val;
88  val.f = rhs;
89  val.i = endianSwap32Bit( val.i );
90 
91  return val.f;
92  }
93 
94  inline double endianSwap64BitDouble( double rhs )
95  {
96  union v
97  {
98  double d;
99  Integer64 i;
100  };
101 
102  v val;
103  val.d = rhs;
104  val.i = endianSwap64Bit( val.i );
105  return val.d;
106  }
107 
109  inline void appendBytes( std::vector<Octet>& wrapper, const char* bytes, size_t length )
110  {
111  // Resize the buffer and then write to it (this is efficient if caller
112  // has already reserved the space - otherwise buffer may re-alloc)
113  unsigned int currentBufferSize = wrapper.size();
114  wrapper.resize( currentBufferSize + length );
115  memcpy( &wrapper[ currentBufferSize ], bytes, length );
116  }
117 
119  inline unsigned int paddingSizeInBytes( unsigned int bufferLength, unsigned int elementOctetBoundary )
120  {
121  return MAKRti::alignedPadding(bufferLength, elementOctetBoundary);
122  }
123 
125  inline void insertBytes( std::vector<Octet>& wrapper, size_t length )
126  {
129  unsigned int currentBufferSize = wrapper.size();
130  wrapper.resize( currentBufferSize + length );
131  }
132 }
133 
134 #endif
void swapByteArray(char *byteArray, int theSize)
Swap the byte array in memory.
Definition: encodingImplHelpers.h:30
unsigned int paddingSizeInBytes(unsigned int bufferLength, unsigned int elementOctetBoundary)
Get the padding for this element.
Definition: encodingImplHelpers.h:119
const int endianChecker
This checks whether the machine is Big Endian or Little Endian.
Definition: encodingImplHelpers.h:26
void appendBytes(std::vector< Octet > &wrapper, const char *bytes, size_t length)
append to a octet vector
Definition: encodingImplHelpers.h:109
Integer64 endianSwap64Bit(Integer64 rhs)
swap 64 bits
Definition: encodingImplHelpers.h:70
unsigned short endianSwap16Bit(unsigned short rhs)
swap 16 bits
Definition: encodingImplHelpers.h:43
unsigned int endianSwap32Bit(unsigned int rhs)
swap 32 bits
Definition: encodingImplHelpers.h:62
double endianSwap64BitDouble(double rhs)
Definition: encodingImplHelpers.h:94
void insertBytes(std::vector< Octet > &wrapper, size_t length)
Insert bytes into the octet buffer.
Definition: encodingImplHelpers.h:125
float endianSwap32BitFloat(float rhs)
swap 32 bit float
Definition: encodingImplHelpers.h:79
Integer64 valueHash(T value)
Definition: encodingImplHelpers.h:51

Document ID: Generated on Sun Jul 20 16:15:30 EDT 2025 from SVN revision 277985
Copyright © 2005-2025 MAK Technologies Inc. All Rights Reserved (www.mak.com)