Support to receive non UTF8 OSC String


The Open Sound Control specification specify OSC-string as following:

“sequence of non-null ASCII characters followed by a null, followed by 0-3 additional null characters to make the total number of bits a multiple of 32”

Sadly the charset codepage encoding of Extended ASCII Codes are not specified and was let free to implementator.

Current OSCInputStream::readString() use InputStream::readString() assuming UTF8 encoding.
Sadly some OSC software sent OSC-string containing accentuated character in local codepage, like Western Latin.

To support this, I propose the following patch for juce_OSCReceiver.cpp

static String readStringWithCodePageDetection(InputStream& inputStream)
  MemoryOutputStream buffer;

  for (;;)
    auto c = inputStream.readByte();

    if (c == 0) // do not call toUTF8() like InputStream::readString() does, but relly on String::createStringFromData
      return buffer.toString(); //  who creates a string from data in an unknown format.

String readString()
    checkBytesAvailable (4, "OSC input stream exhausted while reading string");

    auto posBegin = (size_t) getPosition();
    auto s = readStringWithCodePageDetection(input); // PATCH HERE
    auto posEnd = (size_t) getPosition();

    if (static_cast<const char*> (getData()) [posEnd - 1] != '\0')
        throw OSCFormatError ("OSC input stream exhausted before finding null terminator of string");

    size_t bytesRead = posEnd - posBegin;
    readPaddingZeros (bytesRead);

    return s;

Of Course a more proper and invasive patch should be to modify MemoryOutputStream::toString(), juce::InputStream::toString() and overrides, allowing to let caller choose underlying stream buffer interpretation betwen UTF8, UTF16, Windows1252Codepage or autodetect.

Here a python sender code to test Juce receiver before and after the patch:

#pip install oscpy
from oscpy.client import OSCClient
address = ""
port = 1234
osc = OSCClient(address, port, encoding='windows-1252')
osc.send_message(b'/address', ["aàaeée"])

Hopping this can helps.
Best regards

Hi !

Nobody for a quick fix for Juce developer branch with reproducible scenario ?

Thanks for your concern about this.
Best regards