Serialize an OSC message to wire format.
68{
69 if (address.empty() || address[0] != '/') {
70 return {};
71 }
72
73 std::vector<uint8_t> out;
74 out.reserve(256);
75
77
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>) {
83 type_tags += 'i';
84 } else if constexpr (std::is_same_v<T, float>) {
85 type_tags += 'f';
86 } else if constexpr (std::is_same_v<T, std::string>) {
87 type_tags += 's';
88 } else if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
89 type_tags += 'b';
90 }
91 },
92 arg);
93 }
95
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>>) {
107 }
108 },
109 arg);
110 }
111
112 return out;
113}
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.
void write_string(std::vector< uint8_t > &out, const std::string &str)
Append a null-terminated string padded to 4-byte boundary.
void write_float(std::vector< uint8_t > &out, float val)
Append a big-endian IEEE 754 float.