示例#1
0
文件: bundle.c 项目: foogywoo/drone
void *lo_bundle_serialise(lo_bundle b, void *to, size_t *size)
{
    size_t s, skip;
    int32_t *bes;
    int i;
    char *pos;
    lo_pcast32 be;

    if (!b) {
	return NULL;
    }

    s = lo_bundle_length(b);
    if (size) {
	*size = s;
    }

    if (!to) {
	to = calloc(1, s);
    }

    pos = to;
    strcpy(pos, "#bundle");
    pos += 8;
	
    be.nl = lo_htoo32(b->ts.sec);
    memcpy(pos, &be, 4);
    pos += 4;
    be.nl = lo_htoo32(b->ts.frac);
    memcpy(pos, &be, 4);
    pos += 4;

    for (i = 0; i < b->len; i++) {
	lo_message_serialise(b->msgs[i], b->paths[i], pos + 4, &skip);
	bes = (int32_t *)pos;
	*bes = lo_htoo32(skip);
	pos += skip + 4;

	if (pos > (char *)to + s) {
	    fprintf(stderr, "liblo: data integrity error at message %d\n", i);

	    return NULL;
	}
    }
    if (pos != to + s) {
	fprintf(stderr, "liblo: data integrity error\n");

	return NULL;
    }

    return to;
}
示例#2
0
int lo_send_bundle_from(lo_address a, lo_server from, lo_bundle b)
{
    const size_t data_len = lo_bundle_length(b);
    char *data = lo_bundle_serialise(b, NULL, NULL);

    // Send the bundle
    int ret = send_data( a, from, data, data_len );

    // Free the memory allocated by lo_bundle_serialise
    if (data) free( data );

    return ret;
}