PcapPlusPlus  Next
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 
11 namespace pcpp
12 {
22  std::string byteArrayToHexString(const uint8_t* byteArr, size_t byteArrSize, int stringSizeLimit = -1);
23 
35  size_t hexStringToByteArray(const std::string& hexString, uint8_t* resultByteArr, size_t resultByteArrSize);
36 
44  char* cross_platform_memmem(const char* haystack, size_t haystackLen, const char* needle, size_t needleLen);
45 
49  template <int alignment> static int align(int number)
50  {
51  // Only works for alignment with power of 2
52  constexpr bool isPowerOfTwo = alignment && ((alignment & (alignment - 1)) == 0);
53  static_assert(isPowerOfTwo, "Alignment must be a power of 2");
54  int mask = alignment - 1;
55  return (number + mask) & ~mask;
56  }
57 
60  template <typename EnumClass, typename std::enable_if<std::is_enum<EnumClass>::value, bool>::type = false>
62  {
63  size_t operator()(EnumClass value) const
64  {
65  return static_cast<typename std::underlying_type<EnumClass>::type>(value);
66  }
67  };
68 } // 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:62