ChannelId.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright 2025, Ableton AG, Berlin. All rights reserved.
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * If you would like to incorporate Link into a proprietary software application,
  17. * please contact <link-devs@ableton.com>.
  18. */
  19. #pragma once
  20. #include <ableton/discovery/NetworkByteStreamSerializable.hpp>
  21. #include <ableton/link_audio/Id.hpp>
  22. namespace ableton
  23. {
  24. namespace link_audio
  25. {
  26. struct ChannelId
  27. {
  28. static const std::int32_t key = 'chid';
  29. static_assert(key == 0x63686964, "Unexpected byte order");
  30. friend bool operator==(const ChannelId& lhs, const ChannelId& rhs)
  31. {
  32. return lhs.id == rhs.id;
  33. }
  34. // Model the NetworkByteStreamSerializable concept
  35. friend std::uint32_t sizeInByteStream(const ChannelId& cid)
  36. {
  37. return discovery::sizeInByteStream(cid.id);
  38. }
  39. template <typename It>
  40. friend It toNetworkByteStream(const ChannelId& cid, It out)
  41. {
  42. return discovery::toNetworkByteStream(cid.id, std::move(out));
  43. }
  44. template <typename It>
  45. static std::pair<ChannelId, It> fromNetworkByteStream(It begin, It end)
  46. {
  47. auto [result, itEnd] = discovery::Deserialize<Id>::fromNetworkByteStream(begin, end);
  48. return std::make_pair(ChannelId{std::move(result)}, itEnd);
  49. }
  50. Id id;
  51. };
  52. } // namespace link_audio
  53. } // namespace ableton