definition.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. namespace sunrise::middleware::bap::activity_host_manager::request::selection {
  6. /** The descriptor schema holds 16 skull selection entries. */
  7. inline constexpr std::size_t kActivityManagerSkullCapacity = 16;
  8. /** The descriptor has one fixed 40-byte signed package-name field. */
  9. inline constexpr std::size_t kActivityManagerPackageNameCapacity = 40;
  10. /**
  11. * Storage for one descriptor's exact bits, which another message replays as-is. With every
  12. * dynamic count at its largest the descriptor is 1,814 bits, and the common form is 372, so this
  13. * holds the biggest encoding the schema can make.
  14. */
  15. inline constexpr std::size_t kActivityManagerDescriptorCapacity = 232;
  16. /** Two biased scalar values from one skull-selection entry. */
  17. struct ActivityManagerSkullValue final {
  18. /** 2-bit value with the required bias of 1 removed. */
  19. std::int8_t group{};
  20. /** 7-bit value with the required bias of 1 removed. */
  21. std::int8_t value{};
  22. };
  23. /** Safe scalar fields decoded from one service-6 field-one activity selection. */
  24. struct ActivityManagerSelection final {
  25. /** 2-bit root request kind, required bias of 1 removed. */
  26. std::int8_t requestKind{};
  27. /** 4-bit selection reason, required bias of 1 removed. */
  28. std::int8_t reason{};
  29. /** 12-bit source activity index, required bias of 1 removed. */
  30. std::int16_t sourceActivityIndex{};
  31. /** 12-bit destination activity index, required bias of 1 removed. */
  32. std::int16_t activityIndex{};
  33. /** True when the optional 9-bit element index was present. */
  34. bool hasElementIndex{};
  35. /** Element index, required bias of 1 removed. */
  36. std::int16_t elementIndex{};
  37. /** Number of filled entries in skulls. */
  38. std::uint8_t skullCount{};
  39. /** Gameplay selections. Entries past skullCount stay zero. */
  40. std::array<ActivityManagerSkullValue, kActivityManagerSkullCapacity> skulls{};
  41. /** True when the optional arrival-bubble hash was present. */
  42. bool hasArrivalBubbleHash{};
  43. /** Unsigned arrival-bubble hash from the descriptor. */
  44. std::uint32_t arrivalBubbleHash{};
  45. /** True when the optional spawn-set hash was present. */
  46. bool hasSpawnSetHash{};
  47. /** Unsigned spawn-set hash from the descriptor. */
  48. std::uint32_t spawnSetHash{};
  49. /** True when the fixed package-name field was present. */
  50. bool hasPackageName{};
  51. /** Length of the valid lowercase prefix, 1 to 40. */
  52. std::uint8_t packageNameLength{};
  53. /** Checked package-name bytes, then zero padding. */
  54. std::array<std::int8_t, kActivityManagerPackageNameCapacity> packageName{};
  55. /** Last root boolean. Its gameplay meaning is not known. */
  56. bool trailingFlag{};
  57. /**
  58. * The descriptor's own bits, left-aligned, exactly as the client encoded them. The host echoes
  59. * this descriptor back in another message, and it carries fields with no known name.
  60. * Re-encoding from the scalars above would drop those, so the bits are replayed instead.
  61. */
  62. std::array<std::byte, kActivityManagerDescriptorCapacity> descriptorBits{};
  63. /** Meaningful bits in descriptorBits. The last byte may hold padding in its low bits. */
  64. std::size_t descriptorBitLength{};
  65. };
  66. /**
  67. * Optional typed selections from a service-6 protobuf with valid structure. The request carries
  68. * the same descriptor twice, in protobuf field one and inside field two, and either copy may be
  69. * missing or unreadable while the other is fine.
  70. */
  71. struct ActivityManagerSelectionResult final {
  72. /** False when protobuf field one is missing, empty or unreadable. */
  73. bool hasSelection{};
  74. /** Field-one output. Valid only when hasSelection is true. */
  75. ActivityManagerSelection selection{};
  76. /** False when field two is missing or its descriptor did not read back. */
  77. bool hasSecondary{};
  78. /** Field-two output. Valid only when hasSecondary is true. */
  79. ActivityManagerSelection secondary{};
  80. };
  81. } // namespace sunrise::middleware::bap::activity_host_manager::request::selection