Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@
"-style=file:clang-format.yml",
"-i",
"benchmarks/cpp/src/main.cc",
"references/cpp/src/output.h",
"references/cpp/src/output.cc",
"references/cpp/src/utils.h",
"references/cpp/src/utils.cc",
"references/cpp/src/reference.cc",
"references/cpp/src/readme.cc",
"references/cpp/src/main.cc",
]

[tasks."format:js"]
Expand Down
24 changes: 3 additions & 21 deletions references/cpp/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
dependencies = ["test"]

[tasks.build]
dependencies = ["prepare", "milo", "release", "debug", "readme"]
dependencies = ["prepare", "milo", "release", "debug"]

[tasks.test]
env = { VARIANT = "cpp" }
Expand All @@ -30,9 +30,7 @@
"../../dist/cpp/release",
"-o",
"../../tmp/references/cpp/release",
"src/output.cc",
"src/utils.cc",
"src/reference.cc",
"src/main.cc",
"../../dist/cpp/release/libmilo.a",
]

Expand All @@ -44,26 +42,10 @@
"../../dist/cpp/debug",
"-o",
"../../tmp/references/cpp/debug",
"src/output.cc",
"src/utils.cc",
"src/reference.cc",
"src/main.cc",
"../../dist/cpp/debug/libmilo.a",
]

[tasks.readme]
command = "clang++"
args = [
"-std=c++11",
"-I",
"../../dist/cpp/release",
"-o",
"../../tmp/references/cpp/readme",
"src/output.cc",
"src/utils.cc",
"src/readme.cc",
"../../dist/cpp/release/libmilo.a",
]

[tasks."milo:headers"]
cwd = "../../parser"
command = "makers"
Expand Down
87 changes: 85 additions & 2 deletions references/cpp/src/reference.cc → references/cpp/src/main.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,92 @@
#include "milo.h"
#include "stdio.h"
#include "string.h"
#include <cinttypes>
#include <cstdint>
#include <cstdlib>

#define MAX_FORMAT 1000

typedef uintptr_t usize_t;
typedef unsigned char uchar_t;

struct context_t {
uchar_t* input;
uchar_t* method;
uchar_t* url;
uchar_t* protocol;
uchar_t* version;
};

void clear_context(context_t* context) {
if (context->input != NULL) {
free(context->input);
context->input = NULL;
}

if (context->method != NULL) {
free(context->method);
context->method = NULL;
}

if (context->url != NULL) {
free(context->url);
context->url = NULL;
}

if (context->protocol != NULL) {
free(context->protocol);
context->protocol = NULL;
}

#include "output.h"
#include "utils.h"
if (context->version != NULL) {
free(context->version);
context->version = NULL;
}
}

uchar_t* create_string() {
return reinterpret_cast<uchar_t*>(calloc(MAX_FORMAT, sizeof(uchar_t)));
}

void append_output(const milo_parser::Parser* parser, uchar_t* message, const uchar_t* data, usize_t from,
usize_t size) {
if (data == NULL) {
printf("{ %s, \"data\": null }\n", message);
} else {
uchar_t* string_data = create_string();
strncpy(reinterpret_cast<char*>(string_data), reinterpret_cast<const char*>(data), size);
printf("{ %s, \"data\": \"%s\" }\n", message, string_data);
}

free(message);
}

void event(const milo_parser::Parser* parser, const char* name, const uchar_t* data, usize_t from, usize_t size) {
auto message = create_string();
snprintf((char*) message, MAX_FORMAT, "\"pos\": %lu, \"event\": \"%s\"", from, name);
append_output(parser, message, data, from, size);
}

void show_span(const milo_parser::Parser* parser, const char* name, const uchar_t* data, usize_t from, usize_t size) {
auto context = reinterpret_cast<context_t*>(parser->context);
uchar_t* string_data = create_string();
strncpy(reinterpret_cast<char*>(string_data), reinterpret_cast<const char*>(data), size);

if (strcmp(name, "method") == 0) {
context->method = string_data;
} else if (strcmp(name, "url") == 0) {
context->url = string_data;
} else if (strcmp(name, "protocol") == 0) {
context->protocol = string_data;
} else if (strcmp(name, "version") == 0) {
context->version = string_data;
} else {
free(string_data);
}

event(parser, name, data, from, size);
}

#define EXTRACT_PAYLOAD(name, parser, from, size) \
auto name = size > 0 ? reinterpret_cast<context_t*>(parser->context)->input + from : NULL;
Expand Down
41 changes: 0 additions & 41 deletions references/cpp/src/output.cc

This file was deleted.

14 changes: 0 additions & 14 deletions references/cpp/src/output.h

This file was deleted.

42 changes: 0 additions & 42 deletions references/cpp/src/readme.cc

This file was deleted.

32 changes: 0 additions & 32 deletions references/cpp/src/utils.cc

This file was deleted.

22 changes: 0 additions & 22 deletions references/cpp/src/utils.h

This file was deleted.