mirror of
https://github.com/fluencelabs/c-template
synced 2025-04-25 06:32:14 +00:00
update readme
This commit is contained in:
parent
7e8e556bf0
commit
26b38c5a59
@ -1,3 +1,7 @@
|
|||||||
|
# C template
|
||||||
|
|
||||||
|
Template backend project for Rust
|
||||||
|
|
||||||
# How to build
|
# How to build
|
||||||
|
|
||||||
This app could be built either with docker
|
This app could be built either with docker
|
||||||
|
19
main.c
19
main.c
@ -1,25 +1,6 @@
|
|||||||
#include "sdk/allocator.h"
|
#include "sdk/allocator.h"
|
||||||
#include "sdk/logger.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) {
|
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;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user