activity_state_refresh_parser.cpp 1006 B

12345678910111213141516171819202122232425262728293031
  1. #include "activity_state_refresh_parser.h"
  2. #include <bit>
  3. #include "../../encoding/byte_order.h"
  4. namespace sunrise::middleware::bap::activity_message::state_refresh {
  5. namespace {
  6. /** The bubble field uses the signed 32-bit midpoint as its wire bias. */
  7. constexpr std::uint32_t kBubbleIndexBias = 0x80000000U;
  8. } // namespace
  9. /** Parses the fixed state-refresh request prefix. */
  10. bool parse_state_refresh(std::span<const std::byte> input, StateRefresh& refresh) noexcept {
  11. refresh = {};
  12. if (input.size() != kEncodedSize) {
  13. return false;
  14. }
  15. StateRefresh parsed{};
  16. parsed.membershipRevision = encoding::read_u32_be(input.first<encoding::kU32Size>());
  17. const std::uint32_t bubbleWire =
  18. encoding::read_u32_be(input.subspan<encoding::kU32Size, encoding::kU32Size>());
  19. parsed.bubbleIndex = std::bit_cast<std::int32_t>(bubbleWire - kBubbleIndexBias);
  20. refresh = parsed;
  21. return true;
  22. }
  23. } // namespace sunrise::middleware::bap::activity_message::state_refresh