view_message.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include "../../encoding/bit_reader.h"
  6. #include "../../encoding/bit_writer.h"
  7. namespace sunrise::middleware::gameplay::group {
  8. /** Registry id of view establishment. */
  9. inline constexpr std::uint8_t kViewMessageId = 40;
  10. /** Declared decoded size the registry holds. */
  11. inline constexpr std::uint32_t kViewMessageSize = 40;
  12. /** The list carries at most 16 bytes. */
  13. inline constexpr std::size_t kViewListCapacity = 16;
  14. /** The kind field is 3 bits and its largest named value is 5. */
  15. inline constexpr std::uint8_t kMaximumViewKind = 5;
  16. /**
  17. * One view-establishment body.
  18. * Both sides must agree on it. A mismatch produces no replicated entities at all.
  19. */
  20. struct ViewEstablishment {
  21. std::array<std::byte, kViewListCapacity> list{};
  22. /** Token both sides bind. */
  23. std::uint64_t sessionToken{};
  24. /** Present optional value, or absent when the sender sent none. */
  25. std::int32_t optionalValue{};
  26. std::uint8_t kind{};
  27. std::uint8_t listCount{};
  28. bool hasOptionalValue{};
  29. bool hasList{};
  30. };
  31. /** Reads a view-establishment body. @return True when the selected form was complete. */
  32. [[nodiscard]] bool read_view(encoding::bits::Reader& reader, ViewEstablishment& output) noexcept;
  33. /** Writes a view-establishment body. @return True when the selected form fit. */
  34. [[nodiscard]] bool write_view(encoding::bits::Writer& writer,
  35. const ViewEstablishment& body) noexcept;
  36. /**
  37. * Compares two views for replication compatibility.
  38. * @param left One side's view.
  39. * @param right The other side's view.
  40. * @return True when the token, kind, and list all match.
  41. */
  42. [[nodiscard]] bool compatible(const ViewEstablishment& left,
  43. const ViewEstablishment& right) noexcept;
  44. } // namespace sunrise::middleware::gameplay::group