family_unsubscription.cpp 1.2 KB

123456789101112131415161718192021222324252627282930
  1. #include "family_unsubscription.h"
  2. #include "../encoding/byte_order.h"
  3. namespace sunrise::middleware::bap::family_unsubscription {
  4. namespace {
  5. /** The 1-byte family selector starts the request body, at the same offset svc 12 uses. */
  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-14 body is exactly the family selector and the root id, the same as svc 12. */
  10. constexpr std::size_t kBodySize = kFamilyRootOffset + encoding::kU64Size;
  11. } // namespace
  12. /** Decodes one fixed authenticated family-unsubscription request. */
  13. bool parse(std::span<const std::byte> input, Request& request) noexcept {
  14. request = {};
  15. // The native decoder refuses any svc-14 body that is not exactly this size.
  16. if (input.size() != kBodySize) {
  17. return false;
  18. }
  19. request.familyType = std::to_integer<std::uint8_t>(input[kFamilyTypeOffset]);
  20. request.familyRootSoid = encoding::read_u64_be(std::span<const std::byte, encoding::kU64Size>(
  21. input.data() + kFamilyRootOffset, encoding::kU64Size));
  22. return true;
  23. }
  24. } // namespace sunrise::middleware::bap::family_unsubscription