-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d64d131
commit 06543a6
Showing
39 changed files
with
1,129 additions
and
314 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
native-schema-registry/c/include/glue_schema_registry_error.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef NATIVE_SCHEMA_REGISTRY_GLUE_SCHEMA_REGISTRY_ERROR_H | ||
#define NATIVE_SCHEMA_REGISTRY_GLUE_SCHEMA_REGISTRY_ERROR_H | ||
|
||
#include <stdio.h> | ||
|
||
//Error codes are arbitrarily listed from 5000. No specific reason. | ||
#define ERR_CODE_INVALID_STATE 5000 | ||
#define ERR_CODE_NULL_PARAMETERS 5001 | ||
#define ERR_CODE_GRAALVM_INIT_EXCEPTION 5002 | ||
#define ERR_CODE_GRAALVM_TEARDOWN_EXCEPTION 5003 | ||
#define ERR_CODE_INVALID_PARAMETERS 5004 | ||
#define ERR_CODE_RUNTIME_ERROR 5005 | ||
|
||
//TODO: Improve error reporting to respect logging levels. | ||
#define log_warn(msg, code) fprintf(stderr, "WARN: %s, Code: %d\n", msg, code) | ||
|
||
/** Defines the glue_schema_registry_error structure for holding error messages and codes | ||
* resulting from function executions. | ||
*/ | ||
typedef struct glue_schema_registry_error { | ||
char * msg; | ||
int code; | ||
} glue_schema_registry_error; | ||
|
||
glue_schema_registry_error * new_glue_schema_registry_error(const char * err_msg, int err_code); | ||
|
||
void delete_glue_schema_registry_error(glue_schema_registry_error *error); | ||
|
||
/** | ||
* Creates an instance of glue_schema_registry_error and writes it to the given | ||
* glue_schema_registry_error pointer holder (*p_err). It is expected that *p_err | ||
* is initialized by caller. | ||
* @param p_err Initialized glue_schema_registry_error pointer holder. | ||
* @param msg Error message to write. | ||
* @param code Non-zero error code. | ||
*/ | ||
void throw_error(glue_schema_registry_error **p_err, const char *msg, int code); | ||
|
||
#endif //NATIVE_SCHEMA_REGISTRY_GLUE_SCHEMA_REGISTRY_ERROR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 23 additions & 18 deletions
41
native-schema-registry/c/src/glue_schema_registry_deserializer.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,85 @@ | ||
#include "../include/glue_schema_registry_deserializer.h" | ||
#include "../include/error_handling.h" | ||
#include "../../target/libnativeschemaregistry.h" | ||
#include <stdlib.h> | ||
|
||
glue_schema_registry_deserializer * new_glue_schema_registry_deserializer() { | ||
glue_schema_registry_deserializer * new_glue_schema_registry_deserializer(glue_schema_registry_error **p_err) { | ||
glue_schema_registry_deserializer *deserializer = NULL; | ||
deserializer = | ||
(glue_schema_registry_deserializer *) malloc(sizeof(glue_schema_registry_deserializer)); | ||
|
||
int ret = graal_create_isolate(NULL, NULL, (graal_isolatethread_t **) &deserializer->instance_context); | ||
if (ret != 0) { | ||
log_error("Failed to initialize GraalVM isolate.", ERR_CODE_GRAALVM_INIT_EXCEPTION); | ||
delete_glue_schema_registry_deserializer(deserializer); | ||
throw_error(p_err, "Failed to initialize GraalVM isolate.", ERR_CODE_GRAALVM_INIT_EXCEPTION); | ||
return NULL; | ||
} | ||
//TODO: Handle errors here. | ||
//TODO: Handle errors here when configuration is added. | ||
initialize_deserializer(deserializer->instance_context); | ||
return deserializer; | ||
} | ||
|
||
void delete_glue_schema_registry_deserializer(glue_schema_registry_deserializer * deserializer) { | ||
if (deserializer == NULL) { | ||
log_error("Deserializer is NULL", ERR_CODE_NULL_PARAMETERS); | ||
log_warn("Deserializer is NULL", ERR_CODE_NULL_PARAMETERS); | ||
return; | ||
} | ||
if (deserializer->instance_context != NULL) { | ||
int ret = graal_tear_down_isolate(deserializer->instance_context); | ||
if (ret != 0) { | ||
log_error("Error tearing down the graal isolate instance.", ERR_CODE_GRAALVM_TEARDOWN_EXCEPTION); | ||
log_warn("Error tearing down the graal isolate instance.", ERR_CODE_GRAALVM_TEARDOWN_EXCEPTION); | ||
} | ||
deserializer->instance_context = NULL; | ||
} | ||
|
||
free(deserializer); | ||
} | ||
|
||
mutable_byte_array *glue_schema_registry_deserializer_decode(glue_schema_registry_deserializer * deserializer, read_only_byte_array *array) { | ||
mutable_byte_array *glue_schema_registry_deserializer_decode(glue_schema_registry_deserializer * deserializer, | ||
read_only_byte_array *array, | ||
glue_schema_registry_error **p_err) { | ||
if (deserializer == NULL || deserializer->instance_context == NULL) { | ||
log_error("Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); | ||
throw_error(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); | ||
return NULL; | ||
} | ||
|
||
if (array == NULL || array->len == 0) { | ||
log_error("Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); | ||
throw_error(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); | ||
return NULL; | ||
} | ||
|
||
return decode(deserializer->instance_context, array); | ||
return decode(deserializer->instance_context, array, p_err); | ||
} | ||
|
||
glue_schema_registry_schema *glue_schema_registry_deserializer_decode_schema(glue_schema_registry_deserializer * deserializer, read_only_byte_array *array) { | ||
glue_schema_registry_schema *glue_schema_registry_deserializer_decode_schema(glue_schema_registry_deserializer * deserializer, | ||
read_only_byte_array *array, | ||
glue_schema_registry_error **p_err) { | ||
if (deserializer == NULL || deserializer->instance_context == NULL) { | ||
log_error("Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); | ||
throw_error(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); | ||
return NULL; | ||
} | ||
|
||
if (array == NULL || array->len == 0) { | ||
log_error("Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); | ||
throw_error(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); | ||
return NULL; | ||
} | ||
|
||
glue_schema_registry_schema * schema = decode_schema(deserializer->instance_context, array); | ||
glue_schema_registry_schema * schema = decode_schema(deserializer->instance_context, array, p_err); | ||
return schema; | ||
} | ||
|
||
bool glue_schema_registry_deserializer_can_decode(glue_schema_registry_deserializer * deserializer, read_only_byte_array *array) { | ||
bool glue_schema_registry_deserializer_can_decode(glue_schema_registry_deserializer * deserializer, | ||
read_only_byte_array *array, | ||
glue_schema_registry_error **p_err) { | ||
if (deserializer == NULL || deserializer->instance_context == NULL) { | ||
log_error("Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); | ||
throw_error(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); | ||
return NULL; | ||
} | ||
|
||
if (array == NULL || array->len == 0) { | ||
log_error("Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); | ||
throw_error(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); | ||
return NULL; | ||
} | ||
|
||
return can_decode(deserializer->instance_context, array); | ||
return can_decode(deserializer->instance_context, array, p_err); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "../include/glue_schema_registry_error.h" | ||
|
||
static int validate(const char *err_msg) { | ||
if (err_msg == NULL) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
glue_schema_registry_error *new_glue_schema_registry_error( | ||
const char *err_msg, | ||
int err_code) { | ||
if (validate(err_msg) != 0) { | ||
log_warn("Error message cannot be null", ERR_CODE_NULL_PARAMETERS); | ||
return NULL; | ||
} | ||
glue_schema_registry_error *error = NULL; | ||
error = (glue_schema_registry_error *) malloc(sizeof(glue_schema_registry_error)); | ||
error->msg = strdup(err_msg); | ||
error->code = err_code; | ||
|
||
return error; | ||
} | ||
|
||
void delete_glue_schema_registry_error(glue_schema_registry_error *error) { | ||
if (error == NULL) { | ||
log_warn("Error pointer passed is NULL", ERR_CODE_NULL_PARAMETERS); | ||
return; | ||
} | ||
|
||
if (error->msg != NULL) { | ||
free(error->msg); | ||
error->msg = NULL; | ||
} | ||
error->code = 0; | ||
|
||
free(error); | ||
} | ||
|
||
//Create and set the error to the glue_schema_registry_error pointer holder. | ||
void throw_error(glue_schema_registry_error **p_err, const char *msg, int code) { | ||
if (p_err == NULL) { | ||
return; | ||
} | ||
|
||
glue_schema_registry_error *err = new_glue_schema_registry_error(msg, code); | ||
*p_err = err; | ||
} |
Oops, something went wrong.