Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created September 15, 2017 23:39
Show Gist options
  • Save theburningmonk/ccf0e88adef88a6e3352c91ded9be2da to your computer and use it in GitHub Desktop.
Save theburningmonk/ccf0e88adef88a6e3352c91ded9be2da to your computer and use it in GitHub Desktop.
'use strict';
const co = require('co');
const Promise = require('bluebird');
const protobuf = Promise.promisifyAll(require("protobufjs"));
const lib = require('./lib');
const fs = require('fs');
module.exports.handler = co.wrap(function* (event, context, callback) {
console.log(JSON.stringify(event));
let players = lib.genPlayers();
let root = yield protobuf.loadAsync("functions/player.proto");
let Players = root.lookupType("protodemo.Players");
let message = Players.create(players);
let buffer = Players.encode(message).finish();
const response = {
statusCode: 200,
headers: { 'Content-Type': 'application/x-protobuf' },
body: buffer.toString('base64'),
isBase64Encoded: true
};
callback(null, response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment