$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef _ots_BinaryStringMacros_h_ 00002 #define _ots_BinaryStringMacros_h_ 00003 00004 #include "otsdaq-core/Macros/CoutMacros.h" 00005 00006 #include <map> 00007 #include <set> 00008 #include <typeinfo> // operator typeid 00009 #include <vector> 00010 00011 namespace ots 00012 { 00013 struct BinaryStringMacros 00014 { 00015 private: // private constructor because all static members, should never instantiate 00016 // this class 00017 BinaryStringMacros(void); 00018 ~BinaryStringMacros(void); 00019 00020 public: 00021 // Here is the list of static helper functions: 00022 // 00023 // binaryToHexString 00024 // binaryTo8ByteHexString 00025 // 00026 00027 static std::string binaryToHexString(const char* binaryBuffer, 00028 unsigned int numberOfBytes, 00029 const std::string& resultPreamble = "", 00030 const std::string& resultDelimiter = ""); 00031 static std::string binaryTo8ByteHexString(const std::string& binaryBuffer, 00032 const std::string& resultPreamble = "0x", 00033 const std::string& resultDelimiter = " "); 00034 00035 template<class T> 00036 static void insertValueInBinaryString(std::string& binaryBuffer, 00037 T value, 00038 unsigned int byteIndex = 0, 00039 unsigned int bitIndex = 0) 00040 { 00041 __COUTV__(sizeof(value)); 00042 00043 __COUT__ << "Original size of binary buffer: " << binaryBuffer.size() << __E__; 00044 00045 byteIndex += bitIndex / 8; 00046 bitIndex %= 8; 00047 00048 binaryBuffer.resize(byteIndex + sizeof(value) + (bitIndex ? 1 : 0)); 00049 00050 if(bitIndex) 00051 { 00052 // special handling for bit shift on every byte 00053 00054 unsigned char keepMask = ((unsigned char)(-1)) >> bitIndex; 00055 00056 // first byte is a mix of what's there and value 00057 binaryBuffer[byteIndex] = (binaryBuffer[byteIndex] & keepMask) | 00058 (((unsigned char*)(&value))[0] << bitIndex); 00059 00060 // middle bytes are mix of value i-1 and i 00061 for(unsigned int i = 1; i < sizeof(value); ++i) 00062 { 00063 } 00064 00065 // last bytes is mix of value and what's there 00066 } 00067 00068 memcpy((void*)&binaryBuffer[byteIndex + 0] /*dest*/, 00069 (void*)&value /*src*/, 00070 sizeof(value) /*numOfBytes*/); 00071 __COUT__ << "Final size of binary buffer: " << binaryBuffer.size() << __E__; 00072 00073 } // end insertValueInBinaryString 00074 // specialized for string value 00075 static void insertValueInBinaryString(std::string& binaryBuffer, 00076 const std::string& value, 00077 unsigned int byteIndex = 0, 00078 unsigned int bitIndex = 0) 00079 { 00080 } 00081 00082 }; // end BinaryStringMacros static class 00083 } // namespace ots 00084 #endif