byte_to_hex.hpp 975 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MYSQL_IMPL_INTERNAL_BYTE_TO_HEX_HPP
  8. #define BOOST_MYSQL_IMPL_INTERNAL_BYTE_TO_HEX_HPP
  9. #include <boost/config.hpp>
  10. namespace boost {
  11. namespace mysql {
  12. namespace detail {
  13. // We implement the translation to hex ourselves, since it's easy enough.
  14. // We use a table to look up characters
  15. BOOST_INLINE_CONSTEXPR char byte_to_hex_table[16] =
  16. {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  17. // it should point to a buffer of size 2, at least
  18. inline char* byte_to_hex(unsigned char byte, char* it)
  19. {
  20. *it++ = byte_to_hex_table[(byte & ~15) >> 4];
  21. *it++ = byte_to_hex_table[byte & 15];
  22. return it;
  23. }
  24. } // namespace detail
  25. } // namespace mysql
  26. } // namespace boost
  27. #endif