update readme

This commit is contained in:
vms 2019-04-21 22:25:40 +03:00
parent 7e8e556bf0
commit 26b38c5a59
2 changed files with 4 additions and 19 deletions

View File

@ -1,3 +1,7 @@
# C template
Template backend project for Rust
# How to build
This app could be built either with docker

19
main.c
View File

@ -1,25 +1,6 @@
#include "sdk/allocator.h"
#include "sdk/logger.h"
#include <string.h>
const char *const greeting = "Hello world! From ";
const int RESPONSE_SIZE_BYTES = 4;
char *invoke(const char *str, int length) {
const size_t greeting_length = strlen(greeting);
// TODO: add check for overflow
const size_t response_length = length + RESPONSE_SIZE_BYTES + greeting_length;
char *response = (char *)allocate(response_length);
wasm_log(str, length);
for(int i = 0; i < RESPONSE_SIZE_BYTES; ++i) {
response[i] = (response_length >> 8*i) & 0xFF;
}
memcpy(response + RESPONSE_SIZE_BYTES, greeting, greeting_length);
memcpy(response + RESPONSE_SIZE_BYTES + greeting_length, str, length);
return response;
}