Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added deep-copy functions tosc_copy_message and tosc_copy_bundle #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tinyosc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 12 additions & 0 deletions tinyosc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down