StreamDeck SDK allows to write plugins in C++ and JavaScript. One of the functions I use is setting a key title:
void SetTitle(const std::string &inTitle, const std::string& inContext, ESDSDKTarget inTarget);
inTitle
is the title shown on device key. All functions in this project accept only char*
strings. Internally, SetTitle
generates JSON object and sends it to the StreamDesk program using WebSocket.
I need to set title in different languages. JavaScript plugin allows to do this by simple way, for example:
SetTitle : function(context, keyPressCounter) {
var json = {
"event": "setTitle",
"context": context,
"payload": {
//"title": "" + keyPressCounter,
"title": "ы",
"target": DestinationEnum.HARDWARE_AND_SOFTWARE
}
};
websocket.send(JSON.stringify(json));
}
This function successfully shows Russian letter "ы" (0x044B) on the device. Using WireShark, I found this packet:
{"event":"setTitle","context":"6AB547E3C555617462ABD483D36ED595","payload":{"title":"\321\213","target":0}}
So, the string is actually 0xd1, 0x8b
, or \321\213\
. If I use this string in C++ program:
mConnectionManager->SetTitle("\321\213", context, kESDSDKTarget_HardwareAndSoftware);
everything is OK, the letter "ы" is shown. But this is hard-code string. I need to convert any wchar_t*
string to char*
. What algorithm is used here? How Unicode character 0x044B is converted by third-party program to 0xd1 0x8b
? I need to understand this.