1 #ifndef _ots_BinaryStringMacros_h_
2 #define _ots_BinaryStringMacros_h_
4 #include "otsdaq-core/Macros/CoutMacros.h"
27 static std::string binaryToHexString(
const char* binaryBuffer,
28 unsigned int numberOfBytes,
29 const std::string& resultPreamble =
"",
30 const std::string& resultDelimiter =
"");
31 static std::string binaryTo8ByteHexString(
const std::string& binaryBuffer,
32 const std::string& resultPreamble =
"0x",
33 const std::string& resultDelimiter =
" ");
36 static void insertValueInBinaryString(std::string& binaryBuffer,
38 unsigned int byteIndex = 0,
39 unsigned int bitIndex = 0)
41 __COUTV__(
sizeof(value));
43 __COUT__ <<
"Original size of binary buffer: " << binaryBuffer.size() << __E__;
45 byteIndex += bitIndex / 8;
48 binaryBuffer.resize(byteIndex +
sizeof(value) + (bitIndex ? 1 : 0));
54 unsigned char keepMask = ((
unsigned char)(-1)) >> bitIndex;
57 binaryBuffer[byteIndex] = (binaryBuffer[byteIndex] & keepMask) |
58 (((
unsigned char*)(&value))[0] << bitIndex);
61 for(
unsigned int i = 1; i <
sizeof(value); ++i)
68 memcpy((
void*)&binaryBuffer[byteIndex + 0] ,
71 __COUT__ <<
"Final size of binary buffer: " << binaryBuffer.size() << __E__;
75 static void insertValueInBinaryString(std::string& binaryBuffer,
76 const std::string& value,
77 unsigned int byteIndex = 0,
78 unsigned int bitIndex = 0)