From 080f4355a03f123058b09277368c25350e05010c Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Wed, 10 Jun 2009 04:18:50 +0000 Subject: =?UTF-8?q?Blob=20padding=20does=20not=20add=20zero=20if=20already?= =?UTF-8?q?=20modulo=204=20length.=20Blob=20length=20one=20also=20works.?= =?UTF-8?q?=20Thanks=20Wolfgang=20J=C3=A4ger=20for=20debugs...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svn path=/trunk/externals/mrpeach/; revision=11735 --- osc/packOSC.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/osc/packOSC.c b/osc/packOSC.c index f06004c..73c095b 100644 --- a/osc/packOSC.c +++ b/osc/packOSC.c @@ -166,7 +166,9 @@ typedef struct static int OSC_strlen(char *s); static int OSC_padString(char *dest, char *str); static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str); -static int OSC_WritePadding(char *dest, int i); +static int OSC_WriteStringPadding(char *dest, int i); +static int OSC_WriteBlobPadding(char *dest, int i); + static int CheckTypeTag(OSCbuf *buf, char expectedType); /* Initialize the given OSCbuf. The user of this module must pass in the @@ -425,14 +427,14 @@ static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv) #endif if ((c = typeStr[m+1]) == 0) break; if (!(c == 'T' || c == 'F' || c == 'N' || c == 'I')) - ++nTagsWithData; /* these tags have data */ -/*OSC-blob + { + ++nTagsWithData; /* anything other than these tags have at least one data byte */ +/* + OSC-blob An int32 size count, followed by that many 8-bit bytes of arbitrary binary data, followed by 0-3 additional zero bytes to make the total number of bits a multiple of 32. -*/ if (c == 'b') - { - ++nTagsWithData ; /* at least one byte of data, */ - blobCount++; /* but probably more, so set a flag */ +*/ + if (c == 'b') blobCount++; /* b probably has more than one byte, so set a flag */ } } if (((blobCount == 0)&&(nTagsWithData != nArgs)) || ((blobCount != 0)&&(nTagsWithData > nArgs))) @@ -1267,7 +1269,7 @@ static int OSC_writeBlobArg(OSCbuf *buf, typedArg *arg, size_t nArgs) #endif buf->bufptr[i] = b; } - i = OSC_WritePadding(buf->bufptr, i); + i = OSC_WriteBlobPadding(buf->bufptr, i); buf->bufptr += i; buf->gettingFirstUntypedArg = 0; return 0; @@ -1340,7 +1342,7 @@ static int OSC_padString(char *dest, char *str) for (i = 0; str[i] != '\0'; i++) dest[i] = str[i]; - return OSC_WritePadding(dest, i); + return OSC_WriteStringPadding(dest, i); } static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str) @@ -1350,11 +1352,12 @@ static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str) dest[0] = ','; for (i = 0; str[i] != '\0'; i++) dest[i+1] = str[i]; - return OSC_WritePadding(dest, i+1); + return OSC_WriteStringPadding(dest, i+1); } -static int OSC_WritePadding(char *dest, int i) -{ +static int OSC_WriteStringPadding(char *dest, int i) +{ + /* pad with at least one zero to fit 4-byte */ dest[i] = '\0'; i++; @@ -1363,6 +1366,13 @@ static int OSC_WritePadding(char *dest, int i) return i; } +static int OSC_WriteBlobPadding(char *dest, int i) +{ + /* pad if necessary to fit 4-byte */ + for (; (i % STRING_ALIGN_PAD) != 0; i++) dest[i] = '\0'; + return i; +} + /* The next bit is modified from OSC-timetag.c. */ /* -- cgit v1.2.1