<commit_before>
#include <cstdio>
#include <string>
#include <iostream>

#include <array>
#include <vector>

#include <unistd.h>

#include <lo/lo.h>

int test1(const char *path, const char *types,
          lo_arg **argv, int argc, lo_message m,
          void *data)
{
    printf("path: %s\n", path);
    printf("types: %s\n", types);
    printf("i: %d\n", argv[0]->i);
    return 0;
}

int test2(lo_arg **argv, int argc)
{
    printf("in test2: %d\n", argv[0]->i);
    return 0;
}

int test3(lo_arg **argv, int argc, lo_message msg)
{
    printf("in test3\n");
    return 0;
}

void init(lo::Server &s)
{
    int j = 234;

    std::cout << "URL: " << s.url() << std::endl;

    class test3
    {
    public:
        test3(int j, std::string s) : _s(s), _j(j) {};
        int operator () (lo_arg **argv, int argc, lo_message msg)
        {
            std::cout << _s << ": " << _j << ", " << argv[0]->i << std::endl;
            return 0;
        }
    private:
        std::string _s;
        int _j;
    };

    s.add_method("test0", "i", test3(j,"test0"));
    s.del_method("test0", "i");

    s.add_method("test1", "i", test1, 0);
    s.add_method("test2", "i", test2);
    s.add_method("test3", "i", test3(j, "test3"));

    s.add_method("test4", "i",
                  [j](lo_arg **argv, int argc)
                  {
                      printf("test4: %d, %d\n", j, argv[0]->i);
                      return 0;
                  });

    j *= 2;
    s.add_method("test5", "i",
                  [j](lo_arg **argv, int argc, lo_message msg)
                  {
                      printf("test5: %d, %d -- ", j, argv[0]->i);
                      lo_message_pp(msg);
                      return 0;
                  });

    j *= 2;
    s.add_method("test6", "i",
                  [j](lo_message msg)
                  {
                      printf("test6: %d -- ", j);
                      lo_message_pp(msg);
                      return 0;
                  });

    j *= 2;
    s.add_method("test7", "i", [j](){printf("test7: %d\n", j); return 0;});
    j *= 2;
    s.add_method("test8", "i", [j](){printf("test8a: %d\n", j);});
    j *= 2;
    s.add_method("test8", "i", [j](){printf("test8b: %d\n", j);});

    j*=2;
    s.add_method("test9", "i", [j](const char *path, const char *types, lo_arg **argv, int argc)
                  {printf("test9: %d, %s, %s, %d\n", j, path, types, argv[0]->i); return 0;});
    j*=2;
    s.add_method("test10", "i", [j](const char *types, lo_arg **argv, int argc)
                  {printf("test10: %d, %s, %d\n", j, types, argv[0]->i); return 0;});
    j*=2;
    s.add_method("test11", "i", [j](const char *types, lo_arg **argv, int argc, lo_message msg)
                  {printf("test11: %d, %s, %d -- ", j, types, argv[0]->i); lo_message_pp(msg); return 0;});

    j*=2;
    s.add_method("test9", "i", [j](const char *path, const char *types, lo_arg **argv, int argc)
                  {printf("test9: %d, %s, %s, %d\n", j, path, types, argv[0]->i);});
    j*=2;
    s.add_method("test10", "i", [j](const char *types, lo_arg **argv, int argc)
                  {printf("test10: %d, %s, %d\n", j, types, argv[0]->i);});
    j*=2;
    s.add_method("test11", "is", [j](const char *types, lo_arg **argv, int argc, lo_message msg)
                 {printf("test11: %d, %s, %d, %s -- ", j, types, argv[0]->i, &argv[1]->s); lo_message_pp(msg);});

    s.add_method(0, 0, [](const char *path, lo_message m){printf("%s ", path); lo_message_pp(m);});

    j*=2;
    s.add_bundle_handlers(
        [j](lo_timetag time){ printf("Bundle start handler! (j=%d)\n", j); },
        [j](){ printf("Bundle end handler! (j=%d)\n", j); } );
}

int main()
{
    int context = 999;
    lo::ServerThread st(9000,
                        [=](int num, const char *msg, const char *where)
                        {printf("error handler: %d\n", context);});
    if (!st.is_valid()) {
        printf("Nope.\n");
        return 1;
    }

    std::cout << "URL: " << st.url() << std::endl;

    init(st);

    st.start();

    lo::Address a("localhost", "9000");

    printf("address host %s, port %s\n", a.hostname().c_str(), a.port().c_str());
    printf("iface: %s\n", a.iface().c_str());
    a.set_iface(std::string(), std::string("127.0.0.1"));
    a.set_iface(0, "127.0.0.1");
    printf("iface: %s\n", a.iface().c_str());

    a.send_from(st, "test1", "i", 20);
    a.send("test2", "i", 40);
    a.send("test3", "i", 60);
    a.send("test4", "i", 80);
    a.send("test5", "i", 100);
    a.send("test6", "i", 120);
    a.send("test7", "i", 140);
    a.send("test8", "i", 160);
    a.send("test9", "i", 180);
    a.send("test10", "i", 200);

    lo::Message<true> m;
    m.add("i", 220);
    m.add_string(std::string("blah"));
    a.send("test11", m);

    m.add(lo::Blob(4,"asdf"));
    m.add(lo::Blob(std::vector<char>(5, 'a')));
    m.add(lo::Blob(std::array<char,5>{"asdf"}));
    a.send("blobtest", m);

    a.send(lo::Bundle<true>({
                {"test11", lo::Message<false>("is",20,"first in bundle")},
                {"test11", lo::Message<false>("is",30,"second in bundle")}
            }));

    printf("%s: %d\n", a.errstr().c_str(), a.get_errno());

    sleep(1);
}<commit_msg>Add a test for deserialise.<commit_after>
#include <cstdio>
#include <string>
#include <iostream>

#include <array>
#include <vector>

#include <unistd.h>

#include <lo/lo.h>

int test1(const char *path, const char *types,
          lo_arg **argv, int argc, lo_message m,
          void *data)
{
    printf("path: %s\n", path);
    printf("types: %s\n", types);
    printf("i: %d\n", argv[0]->i);
    return 0;
}

int test2(lo_arg **argv, int argc)
{
    printf("in test2: %d\n", argv[0]->i);
    return 0;
}

int test3(lo_arg **argv, int argc, lo_message msg)
{
    printf("in test3\n");
    return 0;
}

void init(lo::Server &s)
{
    int j = 234;

    std::cout << "URL: " << s.url() << std::endl;

    class test3
    {
    public:
        test3(int j, std::string s) : _s(s), _j(j) {};
        int operator () (lo_arg **argv, int argc, lo_message msg)
        {
            std::cout << _s << ": " << _j << ", " << argv[0]->i << std::endl;
            return 0;
        }
    private:
        std::string _s;
        int _j;
    };

    s.add_method("test0", "i", test3(j,"test0"));
    s.del_method("test0", "i");

    s.add_method("test1", "i", test1, 0);
    s.add_method("test2", "i", test2);
    s.add_method("test3", "i", test3(j, "test3"));

    s.add_method("test4", "i",
                  [j](lo_arg **argv, int argc)
                  {
                      printf("test4: %d, %d\n", j, argv[0]->i);
                      return 0;
                  });

    j *= 2;
    s.add_method("test5", "i",
                  [j](lo_arg **argv, int argc, lo_message msg)
                  {
                      printf("test5: %d, %d -- ", j, argv[0]->i);
                      lo_message_pp(msg);
                      return 0;
                  });

    j *= 2;
    s.add_method("test6", "i",
                  [j](lo_message msg)
                  {
                      printf("test6: %d -- ", j);
                      lo_message_pp(msg);
                      return 0;
                  });

    j *= 2;
    s.add_method("test7", "i", [j](){printf("test7: %d\n", j); return 0;});
    j *= 2;
    s.add_method("test8", "i", [j](){printf("test8a: %d\n", j);});
    j *= 2;
    s.add_method("test8", "i", [j](){printf("test8b: %d\n", j);});

    j*=2;
    s.add_method("test9", "i", [j](const char *path, const char *types, lo_arg **argv, int argc)
                  {printf("test9: %d, %s, %s, %d\n", j, path, types, argv[0]->i); return 0;});
    j*=2;
    s.add_method("test10", "i", [j](const char *types, lo_arg **argv, int argc)
                  {printf("test10: %d, %s, %d\n", j, types, argv[0]->i); return 0;});
    j*=2;
    s.add_method("test11", "i", [j](const char *types, lo_arg **argv, int argc, lo_message msg)
                  {printf("test11: %d, %s, %d -- ", j, types, argv[0]->i); lo_message_pp(msg); return 0;});

    j*=2;
    s.add_method("test9", "i", [j](const char *path, const char *types, lo_arg **argv, int argc)
                  {printf("test9: %d, %s, %s, %d\n", j, path, types, argv[0]->i);});
    j*=2;
    s.add_method("test10", "i", [j](const char *types, lo_arg **argv, int argc)
                  {printf("test10: %d, %s, %d\n", j, types, argv[0]->i);});
    j*=2;
    s.add_method("test11", "is", [j](const char *types, lo_arg **argv, int argc, lo_message msg)
                 {printf("test11: %d, %s, %d, %s -- ", j, types, argv[0]->i, &argv[1]->s); lo_message_pp(msg);});

    s.add_method(0, 0, [](const char *path, lo_message m){printf("%s ", path); lo_message_pp(m);});

    j*=2;
    s.add_bundle_handlers(
        [j](lo_timetag time){ printf("Bundle start handler! (j=%d)\n", j); },
        [j](){ printf("Bundle end handler! (j=%d)\n", j); } );
}

int main()
{
    int context = 999;
    lo::ServerThread st(9000,
                        [=](int num, const char *msg, const char *where)
                        {printf("error handler: %d\n", context);});
    if (!st.is_valid()) {
        printf("Nope.\n");
        return 1;
    }

    std::cout << "URL: " << st.url() << std::endl;

    init(st);

    st.start();

    lo::Address a("localhost", "9000");

    printf("address host %s, port %s\n", a.hostname().c_str(), a.port().c_str());
    printf("iface: %s\n", a.iface().c_str());
    a.set_iface(std::string(), std::string("127.0.0.1"));
    a.set_iface(0, "127.0.0.1");
    printf("iface: %s\n", a.iface().c_str());

    a.send_from(st, "test1", "i", 20);
    a.send("test2", "i", 40);
    a.send("test3", "i", 60);
    a.send("test4", "i", 80);
    a.send("test5", "i", 100);
    a.send("test6", "i", 120);
    a.send("test7", "i", 140);
    a.send("test8", "i", 160);
    a.send("test9", "i", 180);
    a.send("test10", "i", 200);

    lo::Message<true> m;
    m.add("i", 220);
    m.add_string(std::string("blah"));
    a.send("test11", m);

    m.add(lo::Blob(4,"asdf"));
    m.add(lo::Blob(std::vector<char>(5, 'a')));
    m.add(lo::Blob(std::array<char,5>{"asdf"}));
    a.send("blobtest", m);

    a.send(lo::Bundle<true>({
                {"test11", lo::Message<false>("is",20,"first in bundle")},
                {"test11", lo::Message<false>("is",30,"second in bundle")}
            }));

    char oscmsg[] = "/ok\x00,\x00\x00";
    int result = 0;
    std::unique_ptr<lo::Message<true>> m2(
        lo::Message<true>::deserialise(oscmsg, sizeof(oscmsg), &result));
    if (m2 != nullptr) {
        printf("deserialise: ");
        m2->print();
    }
    else
        printf("Unexpected failure in deserialise(): %d\n", result);

    printf("%s: %d\n", a.errstr().c_str(), a.get_errno());

    sleep(1);
}
{'fraction_non_alphanumeric': 0.23286784426153703, 'fraction_numerical': 0.03236844538980856, 'mean_word_length': 2.2377245508982035, 'pattern_counts': {'":': 2, '<': 80, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1951500', 'n_tokens_mistral': 4360, 'n_tokens_neox': 4108, 'n_words': 911}