PcapPlusPlus  24.09
GeneralUtils.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <stdint.h>
5 #include <type_traits>
6 
8 
13 namespace pcpp
14 {
26  std::string byteArrayToHexString(const uint8_t* byteArr, size_t byteArrSize, int stringSizeLimit = -1);
27 
41  size_t hexStringToByteArray(const std::string& hexString, uint8_t* resultByteArr, size_t resultByteArrSize);
42 
52  char* cross_platform_memmem(const char* haystack, size_t haystackLen, const char* needle, size_t needleLen);
53 
59  template <int alignment> static int align(int number)
60  {
61  // Only works for alignment with power of 2
62  constexpr bool isPowerOfTwo = alignment && ((alignment & (alignment - 1)) == 0);
63  static_assert(isPowerOfTwo, "Alignment must be a power of 2");
64  int mask = alignment - 1;
65  return (number + mask) & ~mask;
66  }
67 
72  template <typename EnumClass, typename std::enable_if<std::is_enum<EnumClass>::value, bool>::type = false>
74  {
75  size_t operator()(EnumClass value) const
76  {
77  return static_cast<typename std::underlying_type<EnumClass>::type>(value);
78  }
79  };
80 } // namespace pcpp
The main namespace for the PcapPlusPlus lib.
char * cross_platform_memmem(const char *haystack, size_t haystackLen, const char *needle, size_t needleLen)
std::string byteArrayToHexString(const uint8_t *byteArr, size_t byteArrSize, int stringSizeLimit=-1)
size_t hexStringToByteArray(const std::string &hexString, uint8_t *resultByteArr, size_t resultByteArrSize)
Definition: GeneralUtils.h:74