From 9d25d28217818e8c5c994d5abac60aad95071cfb Mon Sep 17 00:00:00 2001 From: neon Date: Mon, 2 Jan 2017 20:35:28 +0100 Subject: [PATCH] added deep-copy functions tosc_copy_message and tosc_copy_bundle --- tinyosc.c | 23 +++++++++++++++++++++++ tinyosc.h | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tinyosc.c b/tinyosc.c index 13fa09ee69..84003f9652 100644 --- a/tinyosc.c +++ b/tinyosc.c @@ -313,3 +313,26 @@ void tosc_printMessage(tosc_message *osc) { } printf("\n"); } + +int tosc_copy_message(tosc_message *dst, tosc_message *src) +{ + if (dst->len < src->len) { + return 0; + } // checking space is enough + memcpy(dst->buffer, src->buffer, src->len); + dst->len = src->len; + dst->marker = dst->buffer + (src->marker - src->buffer); + dst->format = dst->buffer + (src->format - src->buffer); + return 1; +} + +int tosc_copy_bundle(tosc_bundle *dst, tosc_bundle *src) +{ + if (dst->bufLen < src->bundleLen) { + return 0; + } // checking space is enough + memcpy(dst->buffer, src->buffer, src->bundleLen); + dst->bundleLen = src->bundleLen; + dst->marker = dst->buffer + (src->marker - src->buffer); + return 1; +} \ No newline at end of file diff --git a/tinyosc.h b/tinyosc.h index e39c926ff2..355316c154 100644 --- a/tinyosc.h +++ b/tinyosc.h @@ -165,6 +165,18 @@ void tosc_printOscBuffer(char *buffer, const int len); */ void tosc_printMessage(tosc_message *o); +/** + * A convenience function to deep-copy an OSC message + * The destination message's buffer must have been allocated by the caller. + */ +int tosc_copy_message(tosc_message *dst, tosc_message *src); + +/** + * A convenience function to deep-copy an OSC message + * The destination bundle's buffer must have been allocated by the caller. + */ +int tosc_copy_bundle(tosc_bundle *dst, tosc_bundle *src); + #ifdef __cplusplus } #endif