MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ parse()

std::optional< InputValue > MayaFlux::Core::OscParser::parse ( const uint8_t *  data,
size_t  size,
uint32_t  device_id = 0 
)
static

Parse a single OSC message from raw bytes.

Parameters
dataPointer to datagram payload.
sizePayload size in bytes.
device_idDevice id to stamp on the resulting InputValue.
Returns
Parsed InputValue with Type::OSC, or nullopt on parse failure.

Definition at line 7 of file OscParser.cpp.

9{
10 if (size < 4 || data[0] != '/') {
11 return std::nullopt;
12 }
13
14 size_t offset = 0;
15
16 std::string address = Transitive::Protocol::read_string(data, size, offset);
17 if (address.empty() || offset >= size) {
18 return std::nullopt;
19 }
20
21 std::string type_tags;
22 if (offset < size && data[offset] == ',') {
23 type_tags = Transitive::Protocol::read_string(data, size, offset);
24 if (!type_tags.empty() && type_tags[0] == ',') {
25 type_tags = type_tags.substr(1);
26 }
27 }
28
29 std::vector<InputValue::OSCArg> arguments;
30 arguments.reserve(type_tags.size());
31
32 for (char tag : type_tags) {
33 if (offset > size) {
34 break;
35 }
36
37 switch (tag) {
38 case 'i':
39 if (offset + 4 <= size) {
40 arguments.emplace_back(Transitive::Protocol::read_int32(data, offset));
41 }
42 break;
43
44 case 'f':
45 if (offset + 4 <= size) {
46 arguments.emplace_back(Transitive::Protocol::read_float(data, offset));
47 }
48 break;
49
50 case 's':
51 arguments.emplace_back(Transitive::Protocol::read_string(data, size, offset));
52 break;
53
54 case 'b':
55 arguments.emplace_back(Transitive::Protocol::read_blob(data, size, offset));
56 break;
57
58 default:
59 break;
60 }
61 }
62
63 return InputValue::make_osc(std::move(address), std::move(arguments), device_id);
64}
Range size
std::vector< uint8_t > read_blob(const uint8_t *data, size_t max_len, size_t &offset)
Read a length-prefixed blob from a byte buffer.
int32_t read_int32(const uint8_t *data, size_t &offset)
Read a big-endian int32 from a byte buffer.
std::string read_string(const uint8_t *data, size_t max_len, size_t &offset)
Read a null-terminated string from a byte buffer.
float read_float(const uint8_t *data, size_t &offset)
Read a big-endian IEEE 754 float from a byte buffer.
static InputValue make_osc(std::string addr, std::vector< OSCArg > args, uint32_t dev_id)

References MayaFlux::Core::InputValue::make_osc(), MayaFlux::Transitive::Protocol::read_blob(), MayaFlux::Transitive::Protocol::read_float(), MayaFlux::Transitive::Protocol::read_int32(), MayaFlux::Transitive::Protocol::read_string(), and size.

Referenced by MayaFlux::Portal::Network::as_osc(), and MayaFlux::Core::InputManager::setup_osc_bridge().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: