Skip to content

Commit 9db48e5

Browse files
committed
Updated following
1. Mutable byte arrays use aws_byte_buf 2. clang-tidy and clang-format integration
1 parent 939148f commit 9db48e5

18 files changed

+234
-111
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: Mozilla
4+
AlignAfterOpenBracket: AlwaysBreak
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlines: Right
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: false
11+
AllowShortBlocksOnASingleLine: false
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: Inline
14+
AllowShortIfStatementsOnASingleLine: false
15+
AllowShortLoopsOnASingleLine: false
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: false
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BreakBeforeBinaryOperators: None
21+
BreakBeforeBraces: Attach
22+
BreakBeforeTernaryOperators: true
23+
BreakStringLiterals: true
24+
ColumnLimit: 120
25+
ContinuationIndentWidth: 4
26+
DerivePointerAlignment: false
27+
IncludeBlocks: Preserve
28+
IndentCaseLabels: true
29+
IndentPPDirectives: AfterHash
30+
IndentWidth: 4
31+
IndentWrappedFunctionNames: true
32+
KeepEmptyLinesAtTheStartOfBlocks: true
33+
MacroBlockBegin: ''
34+
MacroBlockEnd: ''
35+
MaxEmptyLinesToKeep: 1
36+
PenaltyBreakAssignment: 2
37+
PenaltyBreakBeforeFirstCallParameter: 19
38+
PenaltyBreakComment: 300
39+
PenaltyBreakFirstLessLess: 120
40+
PenaltyBreakString: 1000
41+
PenaltyExcessCharacter: 1000000
42+
PenaltyReturnTypeOnItsOwnLine: 100000
43+
PointerAlignment: Right
44+
ReflowComments: true
45+
SortIncludes: true
46+
SpaceAfterCStyleCast: false
47+
SpaceBeforeAssignmentOperators: true
48+
SpaceBeforeParens: ControlStatements
49+
SpaceInEmptyParentheses: false
50+
SpacesInContainerLiterals: true
51+
SpacesInCStyleCastParentheses: false
52+
SpacesInParentheses: false
53+
SpacesInSquareBrackets: false
54+
Standard: Cpp11
55+
TabWidth: 4
56+
UseTab: Never
57+
...

native-schema-registry/c/.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
Checks: 'clang-diagnostic-*,clang-analyzer-*,readability-*,modernize-*,bugprone-*,misc-*,google-runtime-int,llvm-header-guard,fuchsia-restrict-system-includes,-clang-analyzer-valist.Uninitialized,-clang-analyzer-security.insecureAPI.rand,-clang-analyzer-alpha.*,-readability-magic-numbers,-readability-non-const-parameter,-readability-avoid-const-params-in-decls,-readability-else-after-return,-readability-isolate-declaration,-readability-uppercase-literal-suffix,-bugprone-sizeof-expression'
33
WarningsAsErrors: '*'
4-
HeaderFilterRegex: '.*\.[h]$'
4+
HeaderFilterRegex: '(./c/src/.*\.c$)|(./c/include/.*\.h$)'
55
FormatStyle: 'file'
66
CheckOptions:
77
- key: readability-braces-around-statements.ShortStatementLines

native-schema-registry/c/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set(NATIVE_SCHEMA_REGISTRY_MODULE_NAME libnativeschemaregistry)
2727
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
2828

2929
include_directories("include")
30+
include(cmake/FetchAwsCommon.cmake)
3031
include_directories(${LIB_NATIVE_SCHEMA_REGISTRY_PATH})
3132

3233
add_subdirectory("src")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include(FetchContent)
2+
3+
set(AWS_C_COMMON aws-c-common)
4+
5+
FetchContent_Declare(
6+
AWS_C_COMMON
7+
GIT_REPOSITORY https://github.com/awslabs/aws-c-common.git
8+
GIT_TAG v0.7.4
9+
GIT_SHALLOW 1
10+
)
11+
12+
FetchContent_MakeAvailable(AWS_C_COMMON)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z $CLANG_FORMAT ]] ; then
4+
CLANG_FORMAT=clang-format
5+
fi
6+
7+
if NOT type $CLANG_FORMAT 2> /dev/null ; then
8+
echo "No appropriate clang-format found."
9+
exit 1
10+
fi
11+
12+
FAIL=0
13+
SOURCE_FILES=`find src include -type f \( -name '*.h' -o -name '*.c' \)`
14+
for i in $SOURCE_FILES
15+
do
16+
$CLANG_FORMAT -output-replacements-xml $i | grep -c "<replacement " > /dev/null
17+
if [ $? -ne 1 ]
18+
then
19+
echo "$i failed clang-format check."
20+
FAIL=1
21+
fi
22+
done
23+
24+
exit $FAIL
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
#ifndef GLUE_SCHEMA_REGISTRY_DESERIALIZER_H
22
#define GLUE_SCHEMA_REGISTRY_DESERIALIZER_H
33

4-
#include "glue_schema_registry_schema.h"
54
#include "glue_schema_registry_error.h"
5+
#include "glue_schema_registry_schema.h"
66
#include "mutable_byte_array.h"
77
#include "read_only_byte_array.h"
88
#include <stdbool.h>
99

1010
typedef struct glue_schema_registry_deserializer {
11-
//This is used for storing the instance context. Currently, being used for managing GraalVM instance.
11+
/* This is used for storing the instance context. Currently, being used for
12+
* managing GraalVM instance. */
1213
void *instance_context;
1314
} glue_schema_registry_deserializer;
1415

1516
glue_schema_registry_deserializer *new_glue_schema_registry_deserializer(glue_schema_registry_error **p_err);
1617

1718
void delete_glue_schema_registry_deserializer(glue_schema_registry_deserializer *deserializer);
1819

19-
mutable_byte_array *glue_schema_registry_deserializer_decode(glue_schema_registry_deserializer *deserializer,
20-
read_only_byte_array *array,
21-
glue_schema_registry_error **p_err);
20+
mutable_byte_array *glue_schema_registry_deserializer_decode(
21+
const glue_schema_registry_deserializer *deserializer,
22+
const read_only_byte_array *array,
23+
glue_schema_registry_error **p_err);
2224

23-
glue_schema_registry_schema *
24-
glue_schema_registry_deserializer_decode_schema(glue_schema_registry_deserializer *deserializer,
25-
read_only_byte_array *array,
26-
glue_schema_registry_error **p_err);
25+
glue_schema_registry_schema *glue_schema_registry_deserializer_decode_schema(
26+
const glue_schema_registry_deserializer *deserializer,
27+
const read_only_byte_array *array,
28+
glue_schema_registry_error **p_err);
2729

28-
bool glue_schema_registry_deserializer_can_decode(glue_schema_registry_deserializer *deserializer,
29-
read_only_byte_array *array,
30-
glue_schema_registry_error **p_err);
30+
bool glue_schema_registry_deserializer_can_decode(
31+
const glue_schema_registry_deserializer *deserializer,
32+
const read_only_byte_array *array,
33+
glue_schema_registry_error **p_err);
3134

32-
#endif //GLUE_SCHEMA_REGISTRY_DESERIALIZER_H
35+
#endif /* GLUE_SCHEMA_REGISTRY_DESERIALIZER_H */
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
#ifndef NATIVE_SCHEMA_REGISTRY_GLUE_SCHEMA_REGISTRY_ERROR_H
2-
#define NATIVE_SCHEMA_REGISTRY_GLUE_SCHEMA_REGISTRY_ERROR_H
1+
#ifndef GLUE_SCHEMA_REGISTRY_ERROR_H
2+
#define GLUE_SCHEMA_REGISTRY_ERROR_H
33

44
#include <stdio.h>
55

6-
//Error codes are arbitrarily listed from 5000. No specific reason.
7-
#define ERR_CODE_INVALID_STATE 5000
8-
#define ERR_CODE_NULL_PARAMETERS 5001
9-
#define ERR_CODE_GRAALVM_INIT_EXCEPTION 5002
10-
#define ERR_CODE_GRAALVM_TEARDOWN_EXCEPTION 5003
11-
#define ERR_CODE_INVALID_PARAMETERS 5004
12-
#define ERR_CODE_RUNTIME_ERROR 5005
13-
14-
//TODO: Improve error reporting to respect logging levels.
6+
/* Error codes are arbitrarily listed from 5000. No specific reason. */
7+
enum aws_gsr_error_code {
8+
AWS_GSR_ERR_CODE_INVALID_STATE = 5000,
9+
AWS_GSR_ERR_CODE_NULL_PARAMETERS = 5001,
10+
AWS_GSR_ERR_CODE_GRAALVM_INIT_EXCEPTION = 5002,
11+
AWS_GSR_ERR_CODE_GRAALVM_TEARDOWN_EXCEPTION = 5003,
12+
AWS_GSR_ERR_CODE_INVALID_PARAMETERS = 5004,
13+
AWS_GSR_ERR_CODE_RUNTIME_ERROR = 5005
14+
};
15+
16+
/* TODO: Improve error reporting to respect logging levels. */
1517
#define log_warn(msg, code) fprintf(stderr, "WARN: %s, Code: %d\n", msg, code)
1618

17-
#define MAX_ERROR_MSG_LEN 10000
19+
#define AWS_GSR_MAX_ERROR_MSG_LEN 10000
1820

19-
/** Defines the glue_schema_registry_error structure for holding error messages and codes
20-
* resulting from function executions.
21+
/** Defines the glue_schema_registry_error structure for holding error messages
22+
* and codes resulting from function executions.
2123
*/
2224
typedef struct glue_schema_registry_error {
23-
char * msg;
25+
char *msg;
2426
int code;
2527
} glue_schema_registry_error;
2628

27-
glue_schema_registry_error * new_glue_schema_registry_error(const char * err_msg, int err_code);
29+
glue_schema_registry_error *new_glue_schema_registry_error(const char *err_msg, int err_code);
2830

2931
void delete_glue_schema_registry_error(glue_schema_registry_error *error);
3032

31-
//Copies the given error's msg into dst array trimming the size as necessary.
32-
void glue_schema_registry_error_get_msg(glue_schema_registry_error *error, char *dst, size_t len);
33+
/* Copies the given error's msg into dst array trimming the size as necessary. */
34+
void glue_schema_registry_error_get_msg(const glue_schema_registry_error *error, char *dst, size_t len);
3335

3436
/**
3537
* Creates an instance of glue_schema_registry_error and writes it to the given
36-
* glue_schema_registry_error pointer holder (*p_err). It is expected that *p_err
37-
* is initialized by caller.
38+
* glue_schema_registry_error pointer holder (*p_err). It is expected that
39+
* *p_err is initialized by caller.
3840
* @param p_err Initialized glue_schema_registry_error pointer holder.
3941
* @param msg Error message to write.
4042
* @param code Non-zero error code.
@@ -51,4 +53,4 @@ glue_schema_registry_error **new_glue_schema_registry_error_holder(void);
5153
*/
5254
void delete_glue_schema_registry_error_holder(glue_schema_registry_error **p_err);
5355

54-
#endif //NATIVE_SCHEMA_REGISTRY_GLUE_SCHEMA_REGISTRY_ERROR_H
56+
#endif /* GLUE_SCHEMA_REGISTRY_ERROR_H */

native-schema-registry/c/include/memory_allocator.h renamed to native-schema-registry/c/include/glue_schema_registry_memory_allocator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef NATIVE_SCHEMA_REGISTRY_MEMORY_ALLOCATOR_H
2-
#define NATIVE_SCHEMA_REGISTRY_MEMORY_ALLOCATOR_H
1+
#ifndef GLUE_SCHEMA_REGISTRY_MEMORY_ALLOCATOR_H
2+
#define GLUE_SCHEMA_REGISTRY_MEMORY_ALLOCATOR_H
33

44
#include <stdlib.h>
55

@@ -13,4 +13,4 @@ void *aws_common_calloc(size_t count, size_t size);
1313

1414
void aws_common_free(void *ptr);
1515

16-
#endif //NATIVE_SCHEMA_REGISTRY_MEMORY_ALLOCATOR_H
16+
#endif /* GLUE_SCHEMA_REGISTRY_MEMORY_ALLOCATOR_H */

native-schema-registry/c/include/glue_schema_registry_schema.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,40 @@
88
* schema object required by Glue Schema Registry Serializers / De-serializers.
99
*/
1010
typedef struct glue_schema_registry_schema {
11-
//String name of the schema
12-
char * schema_name;
11+
/* String name of the schema */
12+
char *schema_name;
1313

14-
//Complete definition of the schema as String
15-
char * schema_def;
14+
/* Complete definition of the schema as String */
15+
char *schema_def;
1616

17-
//Data format name, JSON, AVRO, PROTOBUF as String
18-
char * data_format;
17+
/* Data format name, JSON, AVRO, PROTOBUF as String */
18+
char *data_format;
1919

2020
} glue_schema_registry_schema;
2121

22-
//Creates a new instance of glue_schema_registry_schema
22+
/*
23+
* Creates a new instance of glue_schema_registry_schema
24+
*/
2325
glue_schema_registry_schema *new_glue_schema_registry_schema(
24-
const char * schema_name,
25-
const char * schema_def,
26-
const char * data_format,
27-
glue_schema_registry_error ** p_err
28-
);
26+
const char *schema_name,
27+
const char *schema_def,
28+
const char *data_format,
29+
glue_schema_registry_error **p_err);
2930

30-
//Deletes the glue schema registry schema.
31-
void delete_glue_schema_registry_schema(glue_schema_registry_schema * schema);
31+
/*
32+
* Deletes the glue schema registry schema.
33+
*/
34+
void delete_glue_schema_registry_schema(glue_schema_registry_schema *schema);
3235

33-
//Gets different attributes from glue_schema_registry_schema instance.
34-
//These getter methods are translated into "Getter" methods in target languages.
35-
const char * glue_schema_registry_schema_get_schema_name(glue_schema_registry_schema * schema);
36+
/*
37+
* Gets different attributes from glue_schema_registry_schema instance.
38+
* These getter methods are translated into "Getter" methods in target
39+
* languages.
40+
*/
41+
const char *glue_schema_registry_schema_get_schema_name(const glue_schema_registry_schema *schema);
3642

37-
const char * glue_schema_registry_schema_get_schema_def(glue_schema_registry_schema * schema);
43+
const char *glue_schema_registry_schema_get_schema_def(const glue_schema_registry_schema *schema);
3844

39-
const char * glue_schema_registry_schema_get_data_format(glue_schema_registry_schema * schema);
45+
const char *glue_schema_registry_schema_get_data_format(const glue_schema_registry_schema *schema);
4046

41-
#endif //GLUE_SCHEMA_REGISTRY_SCHEMA_H
47+
#endif /* GLUE_SCHEMA_REGISTRY_SCHEMA_H */
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
#ifndef GLUE_SCHEMA_REGISTRY_SERIALIZER_H
22
#define GLUE_SCHEMA_REGISTRY_SERIALIZER_H
33

4-
#include "glue_schema_registry_schema.h"
54
#include "glue_schema_registry_error.h"
5+
#include "glue_schema_registry_schema.h"
66
#include "mutable_byte_array.h"
77
#include "read_only_byte_array.h"
88

99
typedef struct glue_schema_registry_serializer {
10-
//This is used for storing the instance context. Currently being used for managing GraalVM instance.
10+
/* This is used for storing the instance context. Currently being used for
11+
* managing GraalVM instance. */
1112
void *instance_context;
1213
} glue_schema_registry_serializer;
1314

1415
glue_schema_registry_serializer *new_glue_schema_registry_serializer(glue_schema_registry_error **p_err);
1516

1617
void delete_glue_schema_registry_serializer(glue_schema_registry_serializer *serializer);
1718

18-
//Encodes the GSR Schema with a byte array.
19-
mutable_byte_array *glue_schema_registry_serializer_encode(glue_schema_registry_serializer *serializer,
20-
read_only_byte_array * array,
21-
const char * transport_name,
22-
glue_schema_registry_schema *gsr_schema,
23-
glue_schema_registry_error **p_err);
19+
// Encodes the GSR Schema with a byte array.
20+
mutable_byte_array *glue_schema_registry_serializer_encode(
21+
const glue_schema_registry_serializer *serializer,
22+
const read_only_byte_array *array,
23+
const char *transport_name,
24+
const glue_schema_registry_schema *gsr_schema,
25+
glue_schema_registry_error **p_err);
2426

25-
#endif //GLUE_SCHEMA_REGISTRY_SERIALIZER_H
27+
#endif /* GLUE_SCHEMA_REGISTRY_SERIALIZER_H */

0 commit comments

Comments
 (0)