MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MessageUtils.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
8// ─────────────────────────────────────────────────────────────────────────────
9// OSC
10// ─────────────────────────────────────────────────────────────────────────────
11
12/**
13 * @brief Parse a NetworkMessage payload as an OSC message.
14 *
15 * Intended for coroutine consumers that receive a Core::NetworkMessage from
16 * co_await source->next_message() and need a typed value without manual
17 * parsing or visitor boilerplate.
18 *
19 * @code
20 * auto msg = co_await source->next_message();
21 * if (auto osc = Portal::Network::as_osc(msg)) {
22 * float val = osc->get_float(0).value_or(0.0f);
23 * }
24 * @endcode
25 *
26 * @param msg NetworkMessage received from a NetworkSource.
27 * @return Parsed OSCMessage, or std::nullopt if the payload is not valid OSC.
28 */
29[[nodiscard]] MAYAFLUX_API std::optional<Core::InputValue::OSCMessage>
30as_osc(const Core::NetworkMessage& msg);
31
32/**
33 * @brief Serialize an OSC message to wire bytes for sending via NetworkService.
34 *
35 * @code
36 * auto bytes = Portal::Network::serialize_osc("/synth/freq", {{ 440.0f }});
37 * svc->send(endpoint_id, bytes.data(), bytes.size());
38 * @endcode
39 *
40 * @param address OSC address string (must begin with '/').
41 * @param args Typed argument list.
42 * @return Serialized bytes, or empty vector on invalid address.
43 */
44[[nodiscard]] MAYAFLUX_API std::vector<uint8_t>
45serialize_osc(const std::string& address,
46 const std::vector<Core::InputValue::OSCArg>& args);
47
48} // namespace MayaFlux::Portal::Network
std::optional< Core::InputValue::OSCMessage > as_osc(const Core::NetworkMessage &msg)
Parse a NetworkMessage payload as an OSC message.
std::vector< uint8_t > serialize_osc(const std::string &address, const std::vector< Core::InputValue::OSCArg > &args)
Serialize an OSC message to wire bytes for sending via NetworkService.