codecs.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. // Define machine endianness. This is for GCC:
  3. #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  4. #define PLAIN32_LITTLE_ENDIAN 1
  5. #else
  6. #define PLAIN32_LITTLE_ENDIAN 0
  7. #endif
  8. // This is for Clang:
  9. #ifdef __LITTLE_ENDIAN__
  10. #define PLAIN32_LITTLE_ENDIAN 1
  11. #endif
  12. #ifdef __BIG_ENDIAN__
  13. #define PLAIN32_LITTLE_ENDIAN 0
  14. #endif
  15. // Endian conversion functions
  16. #if PLAIN32_LITTLE_ENDIAN
  17. #if defined(_WIN64) || defined(__WIN32__) || defined(_WIN32)
  18. #define cpu_to_be32(x) _byteswap_ulong(x)
  19. #define cpu_to_be64(x) _byteswap_uint64(x)
  20. #define be32_to_cpu(x) _byteswap_ulong(x)
  21. #define be64_to_cpu(x) _byteswap_uint64(x)
  22. #else
  23. #define cpu_to_be32(x) __builtin_bswap32(x)
  24. #define cpu_to_be64(x) __builtin_bswap64(x)
  25. #define be32_to_cpu(x) __builtin_bswap32(x)
  26. #define be64_to_cpu(x) __builtin_bswap64(x)
  27. #endif
  28. #else
  29. #define cpu_to_be32(x) (x)
  30. #define cpu_to_be64(x) (x)
  31. #define be32_to_cpu(x) (x)
  32. #define be64_to_cpu(x) (x)
  33. #endif
  34. // These tables are used by all codecs
  35. // for fallback plain encoding/decoding:
  36. extern const uint8_t plain32_base64_table_enc[];
  37. extern const uint8_t plain32_base64_table_dec[];