family_subscription.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #include "family_subscription.h"
  2. #include "../encoding/byte_order.h"
  3. namespace sunrise::middleware::bap::family_subscription {
  4. namespace {
  5. /** The 1-byte family selector starts the authenticated request body. */
  6. constexpr std::size_t kFamilyTypeOffset = 0;
  7. /** The 8-byte big-endian root id follows the family selector. */
  8. constexpr std::size_t kFamilyRootOffset = kFamilyTypeOffset + sizeof(std::uint8_t);
  9. /** The svc-12 body is exactly the family selector and the root id. */
  10. constexpr std::size_t kBodySize = kFamilyRootOffset + encoding::kU64Size;
  11. } // namespace
  12. /** Decodes the fixed authenticated family-subscription selector. */
  13. bool parse(std::span<const std::byte> input, queuez::Subscription& subscription) noexcept {
  14. subscription = {};
  15. // The native decoder refuses any svc-12 body that is not exactly this size.
  16. if (input.size() != kBodySize) {
  17. return false;
  18. }
  19. subscription.familyType = std::to_integer<std::uint8_t>(input[kFamilyTypeOffset]);
  20. subscription.familyRootSoid =
  21. encoding::read_u64_be(std::span<const std::byte, encoding::kU64Size>(
  22. input.data() + kFamilyRootOffset, encoding::kU64Size));
  23. return true;
  24. }
  25. } // namespace sunrise::middleware::bap::family_subscription