opcode505_codec.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "opcode505_codec.h"
  2. #include <algorithm>
  3. #include <array>
  4. namespace sunrise::middleware::web_service::messages::opcode505 {
  5. /** Reports whether this request is the change-character transition. */
  6. bool parse_request(const Message& message) noexcept {
  7. return message.opcode == kOpcode;
  8. }
  9. /** Encodes the successful response with the family-4 version to wait for. */
  10. bool encode_response(const Message& message,
  11. std::int32_t nextVersion,
  12. std::span<std::byte> output,
  13. std::size_t& written) noexcept {
  14. written = 0;
  15. if (!parse_request(message) || output.size() < kResponseSize) {
  16. return false;
  17. }
  18. std::array<std::byte, kResponseSize> staged{};
  19. StatusResponse status{};
  20. status.value = nextVersion;
  21. std::size_t stagedSize = 0;
  22. if (!sunrise::middleware::web_service::encode_response(
  23. message, ResponseShape::statusPair, status, staged, stagedSize)) {
  24. return false;
  25. }
  26. std::copy_n(staged.begin(), stagedSize, output.begin());
  27. written = stagedSize;
  28. return true;
  29. }
  30. } // namespace sunrise::middleware::web_service::messages::opcode505