mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 20:59:10 +00:00
Demo protobufs in deno2.
Adds deno_set_response() to allow stack allocated responses.
This commit is contained in:
parent
f97216609d
commit
4ac67cf343
10 changed files with 88 additions and 35 deletions
|
|
@ -3,13 +3,33 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
|
||||
#include "./msg.pb.h"
|
||||
#include "include/deno.h"
|
||||
|
||||
void MessagesFromJS(Deno* d, const char* channel, deno_buf buf) {
|
||||
printf("MessagesFromJS %s\n", channel);
|
||||
|
||||
char cwdbuf[1024];
|
||||
std::string cwd(getcwd(cwdbuf, sizeof(cwdbuf)));
|
||||
|
||||
deno::Msg response;
|
||||
response.set_command(deno::Msg_Command_START);
|
||||
response.set_start_cwd(cwd);
|
||||
|
||||
std::string output;
|
||||
assert(response.SerializeToString(&output) == true);
|
||||
|
||||
auto bufout = deno_buf{output.c_str(), output.length()};
|
||||
deno_set_response(d, bufout);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
deno_init();
|
||||
|
||||
Deno* d = deno_new(NULL, NULL);
|
||||
Deno* d = deno_new(NULL, MessagesFromJS);
|
||||
bool r = deno_execute(d, "deno_main.js", "denoMain();");
|
||||
if (!r) {
|
||||
printf("Error! %s\n", deno_last_exception(d));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue