From 4ac67cf3435b3e15f95fadc20c98e37abf706ea4 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 13 Jun 2018 19:38:22 +0200 Subject: Demo protobufs in deno2. Adds deno_set_response() to allow stack allocated responses. --- deno2/main.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'deno2/main.cc') diff --git a/deno2/main.cc b/deno2/main.cc index 2c0b1b298..506469dfa 100644 --- a/deno2/main.cc +++ b/deno2/main.cc @@ -3,13 +3,33 @@ #include #include #include +#include +#include +#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)); -- cgit v1.2.3