start_activity.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <cstddef>
  3. #include <cstdint>
  4. #include <span>
  5. namespace sunrise::middleware::bap::activity_message::start_activity {
  6. /** The client asks to start a different activity from inside the world. */
  7. inline constexpr std::uint32_t kMessageType = 11;
  8. /** The bounded selector opens the body. */
  9. inline constexpr std::uint8_t kSelectorWidth = 4;
  10. /** Both activity indices are twelve bits wide. */
  11. inline constexpr std::uint8_t kActivityIndexWidth = 12;
  12. /** The optional activity element is nine bits wide. */
  13. inline constexpr std::uint8_t kElementWidth = 9;
  14. /** The two optional identity words are full width. */
  15. inline constexpr std::uint8_t kIdentityWidth = 64;
  16. /** Every optional field is introduced by one presence bit. */
  17. inline constexpr std::uint8_t kPresenceWidth = 1;
  18. /** The selector, both indices, and the optional element all carry a bias of one. */
  19. inline constexpr std::int32_t kIndexBias = 1;
  20. /** A biased field that decodes to this value names nothing. */
  21. inline constexpr std::int32_t kAbsentIndex = -1;
  22. /**
  23. * The part of a start-new-activity request whose grammar is recovered.
  24. * The body continues with a nested selection record of unresolved shape, so everything from that
  25. * record on is retained as one bounded tail instead of being walked.
  26. */
  27. struct StartActivity {
  28. /** Bounded selector. Its value meanings are not recovered. */
  29. std::int32_t selector{};
  30. /** Activity index the client is leaving. */
  31. std::int32_t sourceActivityIndex{};
  32. /** Activity index the client is asking for. */
  33. std::int32_t destinationActivityIndex{};
  34. /** Optional activity element, or the absent index when the body carried none. */
  35. std::int32_t element{kAbsentIndex};
  36. /** Optional opaque identity. */
  37. std::int64_t identity{};
  38. /** Optional account or selection identity, read as unsigned. */
  39. std::uint64_t selectionIdentity{};
  40. /** Bits left after the last recovered field. Their grammar is unresolved. */
  41. std::uint32_t tailBits{};
  42. bool hasElement{};
  43. bool hasIdentity{};
  44. bool hasSelectionIdentity{};
  45. };
  46. /**
  47. * Parses a start-new-activity request as far as its recovered grammar reaches.
  48. * @param input Activity payload after the envelope.
  49. * @param request Cleared first, then filled with every field that was reached.
  50. * @param consumedBits Receives the bits the recovered fields used.
  51. * @return True when every recovered field was present.
  52. */
  53. [[nodiscard]] bool parse_start_activity(std::span<const std::byte> input,
  54. StartActivity& request,
  55. std::size_t& consumedBits) noexcept;
  56. } // namespace sunrise::middleware::bap::activity_message::start_activity