mirror of
https://github.com/fluencelabs/fluid
synced 2025-04-24 14:22:18 +00:00
move prepare_response to utils
This commit is contained in:
parent
732ae5a4ed
commit
202626c2ee
@ -6,7 +6,7 @@ CFLAGS = -nostartfiles -fvisibility=hidden
|
||||
LDFLAGS = -Wl,--no-entry,--demangle,--allow-undefined
|
||||
EXPORT_FUNCS = --export=allocate,--export=deallocate,--export=invoke
|
||||
SDK = sdk/allocator.c sdk/logger.c
|
||||
SRC = src/main.c src/model.c
|
||||
SRC = src/main.c src/model.c src/utils.c
|
||||
LIBS = libs/tiny-json/tiny-json.c
|
||||
|
||||
.PHONY: default all clean
|
||||
|
19300
backend-c/fluid.wat
Normal file
19300
backend-c/fluid.wat
Normal file
File diff suppressed because one or more lines are too long
@ -43,6 +43,7 @@ JSON
|
||||
echo -e "Sending post: $JSON"
|
||||
# Send json as a request, and receive result
|
||||
RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/0\n'"$JSON" --compressed)
|
||||
echo "asd"
|
||||
RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE")
|
||||
# Parse json or print response as is
|
||||
echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "model.h"
|
||||
#include "../sdk/allocator.h"
|
||||
#include "utils.h"
|
||||
#include "../sdk/logger.h"
|
||||
#include "../sdk/syscalls_stubs.c"
|
||||
#include "../libs/tiny-json/tiny-json.h"
|
||||
@ -7,19 +7,6 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *prepare_response(const char *response, int response_length) {
|
||||
const int RESPONSE_SIZE_BYTES = 4;
|
||||
char *result = (char *)allocate(response_length + RESPONSE_SIZE_BYTES);
|
||||
|
||||
for(int i = 0; i < RESPONSE_SIZE_BYTES; ++i) {
|
||||
result[i] = (response_length >> 8*i) & 0xFF;
|
||||
}
|
||||
|
||||
memcpy(result + RESPONSE_SIZE_BYTES, response, response_length);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const char *add_post_request(const json_t *json);
|
||||
const char *fetch_posts_request(const json_t *json);
|
||||
|
||||
|
18
backend-c/src/utils.c
Normal file
18
backend-c/src/utils.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include "utils.h"
|
||||
#include "../sdk/allocator.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *prepare_response(const char *response, int response_length) {
|
||||
const int RESPONSE_SIZE_BYTES = 4;
|
||||
char *result = (char *)allocate(response_length + RESPONSE_SIZE_BYTES);
|
||||
|
||||
for(int i = 0; i < RESPONSE_SIZE_BYTES; ++i) {
|
||||
result[i] = (response_length >> 8*i) & 0xFF;
|
||||
}
|
||||
|
||||
memcpy(result + RESPONSE_SIZE_BYTES, response, response_length);
|
||||
|
||||
return result;
|
||||
}
|
6
backend-c/src/utils.h
Normal file
6
backend-c/src/utils.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef FLUID_UTILS_H
|
||||
#define FLUID_UTILS_H
|
||||
|
||||
char *prepare_response(const char *response, int response_length);
|
||||
|
||||
#endif //FLUID_UTILS_H
|
Loading…
x
Reference in New Issue
Block a user