-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnm_cpp.cpp
30 lines (27 loc) · 826 Bytes
/
nm_cpp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// C++ Native Messaging host
// https://browserext.github.io/native-messaging/
// https://developer.chrome.com/docs/apps/nativeMessaging/
// https://www.reddit.com/user/Eternal_Weeb/
// guest271314, 2022
#include <iostream>
#include <vector>
using namespace std;
vector<uint8_t> getMessage() {
uint32_t length = 0;
size_t size = fread(&length, sizeof(length), 1, stdin);
vector<uint8_t> message(length);
size = fread(message.data(), sizeof(*message.data()), message.size(), stdin);
return message;
}
void sendMessage(const vector<uint8_t> &message) {
const uint32_t length = message.size();
fwrite(&length, sizeof(length), 1, stdout);
fwrite(message.data(), message.size(), sizeof(*message.data()), stdout);
fflush(stdout);
}
int main() {
while (true) {
sendMessage(getMessage());
}
return 0;
}