Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PayloadEntries.hpp 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright 2016, 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 <cstdint>
  22. #include <utility>
  23. namespace ableton
  24. {
  25. namespace discovery
  26. {
  27. namespace test
  28. {
  29. // Test payload entries
  30. // A fixed-size entry type
  31. struct Foo
  32. {
  33. enum
  34. {
  35. key = '_foo'
  36. };
  37. std::int32_t fooVal;
  38. friend std::uint32_t sizeInByteStream(const Foo& foo)
  39. {
  40. // Namespace qualification is needed to avoid ambiguous function definitions
  41. return discovery::sizeInByteStream(foo.fooVal);
  42. }
  43. template <typename It>
  44. friend It toNetworkByteStream(const Foo& foo, It out)
  45. {
  46. return discovery::toNetworkByteStream(foo.fooVal, std::move(out));
  47. }
  48. template <typename It>
  49. static std::pair<Foo, It> fromNetworkByteStream(It begin, It end)
  50. {
  51. auto result = Deserialize<decltype(fooVal)>::fromNetworkByteStream(
  52. std::move(begin), std::move(end));
  53. return std::make_pair(Foo{std::move(result.first)}, std::move(result.second));
  54. }
  55. };
  56. // A variable-size entry type
  57. struct Bar
  58. {
  59. enum
  60. {
  61. key = '_bar'
  62. };
  63. std::vector<std::uint64_t> barVals;
  64. friend std::uint32_t sizeInByteStream(const Bar& bar)
  65. {
  66. return discovery::sizeInByteStream(bar.barVals);
  67. }
  68. template <typename It>
  69. friend It toNetworkByteStream(const Bar& bar, It out)
  70. {
  71. return discovery::toNetworkByteStream(bar.barVals, out);
  72. }
  73. template <typename It>
  74. static std::pair<Bar, It> fromNetworkByteStream(It begin, It end)
  75. {
  76. auto result = Deserialize<decltype(barVals)>::fromNetworkByteStream(
  77. std::move(begin), std::move(end));
  78. return std::make_pair(Bar{std::move(result.first)}, std::move(result.second));
  79. }
  80. };
  81. } // namespace test
  82. } // namespace discovery
  83. } // namespace ableton