MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
OscParser.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "InputBinding.hpp"
4
5namespace MayaFlux::Core {
6
7/**
8 * @class OscParser
9 * @brief Stateless OSC message parser: raw UDP bytes -> InputValue
10 *
11 * Parses OSC 1.0 messages from raw datagram bytes. Does not handle
12 * bundles (yet). Does not own a socket. Does not know about
13 * NetworkService. Pure function: bytes in, optional InputValue out.
14 *
15 * OSC wire format:
16 * [address string, null-padded to 4-byte boundary]
17 * [type tag string starting with ',', null-padded to 4-byte boundary]
18 * [arguments, each padded to 4-byte boundary]
19 *
20 * Supported type tags:
21 * 'i' -> int32_t (big-endian)
22 * 'f' -> float (big-endian IEEE 754)
23 * 's' -> null-terminated string (padded to 4 bytes)
24 * 'b' -> blob: [int32 size][data, padded to 4 bytes]
25 *
26 * @code
27 * auto result = OscParser::parse(data, size);
28 * if (result) {
29 * input_manager->enqueue(*result);
30 * }
31 * @endcode
32 */
33class OscParser {
34public:
35 /**
36 * @brief Parse a single OSC message from raw bytes
37 * @param data Pointer to datagram payload.
38 * @param size Payload size in bytes.
39 * @param device_id Device id to stamp on the resulting InputValue.
40 * @return Parsed InputValue with Type::OSC, or nullopt on parse failure.
41 */
42 static std::optional<InputValue> parse(const uint8_t* data, size_t size,
43 uint32_t device_id = 0);
44
45 /**
46 * @brief Serialize an OSC message to wire format
47 * @param address OSC address string (must start with '/').
48 * @param args Typed arguments.
49 * @return Serialized bytes, or empty on error.
50 */
51 static std::vector<uint8_t> serialize(const std::string& address,
52 const std::vector<InputValue::OSCArg>& args);
53};
54
55} // namespace MayaFlux::Core
Range size
static std::optional< InputValue > parse(const uint8_t *data, size_t size, uint32_t device_id=0)
Parse a single OSC message from raw bytes.
Definition OscParser.cpp:7
static std::vector< uint8_t > serialize(const std::string &address, const std::vector< InputValue::OSCArg > &args)
Serialize an OSC message to wire format.
Definition OscParser.cpp:66
Stateless OSC message parser: raw UDP bytes -> InputValue.
Definition OscParser.hpp:33