cosc 0.1.0
OSC library for C99 or C++11.
Loading...
Searching...
No Matches
message.c
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "cosc.h"
int main(int argc, char *argv[])
{
char buffer[1024] = {0};
// An array of values that actually have a payload.
union cosc_value values[11] = {
{.i = 0x12345678},
{.f = 12.34f},
{.s = {.s="Hello World!", .length = 1024}},
{.b = {.b="Hello World!", .size = 12}},
{.h = 0x1234567812345678ULL},
{.t = 0x8765432187654321ULL},
{.d = 1234.5678},
{.s = {.s="Hello World!", .length = 1024}},
{.c = 'A'},
{.r = 0x87654321},
{.m = {0x01, 0x02, 0x03, 0x04}}
};
// Put the message together.
struct cosc_message message;
message.address = "/hello_world";
message.address_n = 1024;
message.typetag = ",ifsbhtdScrmTFNI";
message.typetag_n = 1024;
message.values.write = values;
message.values_n = 11;
// Write it.
cosc_int32 value_count = 0;
buffer, sizeof(buffer), &message,
-1, &value_count
);
if (ret < 0)
{
printf("Uh oh, error writing message: %d!\n", ret);
return 1;
}
printf("%d bytes written for %d values.\n", ret, value_count);
// Read it.
cosc_int32 packet_size;
buffer, sizeof(buffer), &message,
&packet_size, &value_count, true
);
if (ret < 0)
{
printf("Uh oh, error reading message: %d!\n", ret);
return 2;
}
printf("%d bytes read for %d values, packet size is %d.\n", ret, value_count, packet_size);
// Dump the message to a string.
char tmps[1024];
cosc_message_dump(tmps, sizeof(tmps), &message);
printf("%s\n", tmps);
return 0;
}
OSC library for C99 or C++11.
COSC_TYPE_INT32 cosc_int32
Signed 32-bit integer.
Definition cosc.h:253
COSC_API cosc_int32 cosc_write_message(void *buffer, cosc_int32 size, const struct cosc_message *message, cosc_int32 psize, cosc_int32 *value_count)
Write an OSC message.
Definition cosc.c:1923
COSC_API cosc_int32 cosc_message_dump(char *s, cosc_int32 n, const struct cosc_message *message)
Dump an OSC message to string.
Definition cosc.c:2105
COSC_API cosc_int32 cosc_read_message(const void *buffer, cosc_int32 size, struct cosc_message *message, cosc_int32 *psize, cosc_int32 *value_count, cosc_int32 exit_early)
Read an OSC message.
Definition cosc.c:1975
A message.
Definition cosc.h:536
cosc_int32 values_n
Write/read at most this many values.
Definition cosc.h:581
cosc_int32 address_n
When writing read at most this many bytes from the address, when reading the length excluding the zer...
Definition cosc.h:547
union cosc_message::@050073337162334015163030171201070055033256045255 values
Const safety.
const char * typetag
The typetag.
Definition cosc.h:552
const char * address
The address.
Definition cosc.h:541
const union cosc_value * write
Write values.
Definition cosc.h:569
cosc_int32 typetag_n
When writing read at most this many bytes from the typetag, when reading the length excluding the zer...
Definition cosc.h:558
A value.
Definition cosc.h:447