Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
A common use of WebSockets is the transmission of JSON messages as text messages. Text transmitted on WebSockets is UTF-8 (usually). QWebSocket only exposes signals/methods to get/send text frames/messages as a QString. This requires transcoding from/to UTF-16.
In the case of JSON, this is (almost) always unnecessary, because most JSON parsers require the JSON to be in UTF-8 and JSON writers will usually write UTF-8 (QJsonValue for example). Thus, for parsing JSON, we'd do UTF-8 → UTF-16 → UTF-8 → parsed (backwards for writing).
It would be great to have the ability to get the "raw" text payloads as a QByteArray (since there's no QUtf8String yet) and similarly to be able to send UTF-8 as a QByteArray or QUtf8String. This could be a switch on the WebSocket like ws->setTextAsUtf8(true) for the socket to emit text as UTF-8.