• How to send custom message from device to host using script node?

I want to create a custom message and it seems like I need to use a buffer message.

How could I send a message that is a vector of dictionaries in the Script Node to my C++ project. How would I cast the buffer data to the appropriate C++ structure?

    Hi AdamPolak
    Sorry I am unfamiliar with cpp. Chat gpt gave me the following script:

    #include <iostream>
    #include <string>
    #include <vector>
    #include <cstring>
    
    struct MyData {
        std::string key1;
        int key2;
    };
    
    int main() {
        // Assuming 'buffer' is the received buffer message
        std::string buffer = "...";  // Replace '...' with the actual buffer message
    
        // Extract the size of the buffer from the first 4 bytes
        std::uint32_t buffer_size;
        std::memcpy(&buffer_size, buffer.data(), sizeof(buffer_size));
    
        // Extract the data from the buffer
        std::string data(buffer.data() + sizeof(buffer_size), buffer_size);
    
        // Deserialize the JSON data to vector of MyData structures
        std::vector<MyData> my_data;
        // ... Perform deserialization from 'data' to 'my_data' using your preferred JSON library
    
        // Print the received data
        for (const auto& item : my_data) {
            std::cout << "key1: " << item.key1 << ", key2: " << item.key2 << std::endl;
        }
    
        return 0;
    }
    
    Let me know if this helps,
    Jaka