-
Notifications
You must be signed in to change notification settings - Fork 2
/
twirpl_test.js
36 lines (29 loc) · 912 Bytes
/
twirpl_test.js
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
31
32
33
34
35
36
const M = require('./rpc/publicservices/service_pb'),
https = require('http');
let search = new M.Search(),
giphy = new M.Giphy();
search.setTerm("Wahooo");
const postBytes = search.serializeBinary();
const options = {
hostname: 'localhost',
port: 8080,
path: '/twirp/com.rynop.twirpl.publicservices.Image/CreateGiphy',
method: 'POST',
headers: {
'Content-Type': 'application/protobuf',
}
};
const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
const uInt8Array = d.buffer.slice(d.byteOffset, d.byteOffset + d.byteLength);
const giphyMessage = M.Giphy.deserializeBinary(uInt8Array);
console.log(giphyMessage.toObject());
});
});
req.on('error', (e) => {
console.error(e);
});
req.write(Buffer.from(postBytes));
req.end();