serialization.ipp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Copyright (c) 2018-2023 Marcelo Zimbres Silva ([email protected])
  2. *
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE.txt)
  5. */
  6. #include <boost/redis/resp3/serialization.hpp>
  7. #include <boost/redis/resp3/parser.hpp>
  8. namespace boost::redis::resp3 {
  9. void boost_redis_to_bulk(std::string& payload, std::string_view data)
  10. {
  11. auto const str = std::to_string(data.size());
  12. payload += to_code(type::blob_string);
  13. payload.append(std::cbegin(str), std::cend(str));
  14. payload += parser::sep;
  15. payload.append(std::cbegin(data), std::cend(data));
  16. payload += parser::sep;
  17. }
  18. void add_header(std::string& payload, type t, std::size_t size)
  19. {
  20. auto const str = std::to_string(size);
  21. payload += to_code(t);
  22. payload.append(std::cbegin(str), std::cend(str));
  23. payload += parser::sep;
  24. }
  25. void add_blob(std::string& payload, std::string_view blob)
  26. {
  27. payload.append(std::cbegin(blob), std::cend(blob));
  28. payload += parser::sep;
  29. }
  30. void add_separator(std::string& payload)
  31. {
  32. payload += parser::sep;
  33. }
  34. } // boost::redis::resp3