10 if (
size < 4 || data[0] !=
'/') {
17 if (address.empty() || offset >=
size) {
21 std::string type_tags;
22 if (offset <
size && data[offset] ==
',') {
24 if (!type_tags.empty() && type_tags[0] ==
',') {
25 type_tags = type_tags.substr(1);
29 std::vector<InputValue::OSCArg> arguments;
30 arguments.reserve(type_tags.size());
32 for (
char tag : type_tags) {
39 if (offset + 4 <=
size) {
45 if (offset + 4 <=
size) {
67 const std::vector<InputValue::OSCArg>& args)
69 if (address.empty() || address[0] !=
'/') {
73 std::vector<uint8_t> out;
78 std::string type_tags =
",";
79 for (
const auto& arg : args) {
80 std::visit([&type_tags](
const auto& val) {
81 using T = std::decay_t<
decltype(val)>;
82 if constexpr (std::is_same_v<T, int32_t>) {
84 }
else if constexpr (std::is_same_v<T, float>) {
86 }
else if constexpr (std::is_same_v<T, std::string>) {
88 }
else if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
96 for (
const auto& arg : args) {
97 std::visit([&out](
const auto& val) {
98 using T = std::decay_t<
decltype(val)>;
99 if constexpr (std::is_same_v<T, int32_t>) {
101 }
else if constexpr (std::is_same_v<T, float>) {
103 }
else if constexpr (std::is_same_v<T, std::string>) {
105 }
else if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
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.
static std::vector< uint8_t > serialize(const std::string &address, const std::vector< InputValue::OSCArg > &args)
Serialize an OSC message to wire format.
void write_int32(std::vector< uint8_t > &out, int32_t val)
Append a big-endian int32.
void write_blob(std::vector< uint8_t > &out, const std::vector< uint8_t > &blob)
Append a length-prefixed blob padded to 4-byte boundary.
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.
void write_string(std::vector< uint8_t > &out, const std::string &str)
Append a null-terminated string padded to 4-byte boundary.
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.
void write_float(std::vector< uint8_t > &out, float val)
Append a big-endian IEEE 754 float.