diff --git a/CMakeLists.txt b/CMakeLists.txt index b05623a..616d6b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.6) -project(CerealPack CXX) +project(CruncyBytes CXX) if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) @@ -9,55 +9,55 @@ endif() find_package(Python3 COMPONENTS Interpreter REQUIRED) if(NOT ${Python3_FOUND}) - message(FATAL_ERROR "Python3 is required to generate the cereal_pack classes") + message(FATAL_ERROR "Python3 is required to generate the crunchy_bytes classes") endif() -if (NOT DEFINED CEREAL_PACK_SCHEMA_DIR AND NOT DEFINED CEREAL_PACK_SCHEMA_FILES) +if (NOT DEFINED CRUNCHY_BYTES_SCHEMA_DIR AND NOT DEFINED CRUNCHY_BYTES_SCHEMA_FILES) message(FATAL_ERROR - "A schema directory or schema files should be defined using the CMake variables CEREAL_PACK_SCHEMA_DIR or CEREAL_PACK_SCHEMA_FILES") -elseif(DEFINED CEREAL_PACK_SCHEMA_DIR) - set(CEREAL_PACK_SCHEMA_FILES "") - file(GLOB_RECURSE CEREAL_PACK_SCHEMA_FILES "${CEREAL_PACK_SCHEMA_DIR}/*.toml") + "A schema directory or schema files should be defined using the CMake variables CRUNCHY_BYTES_SCHEMA_DIR or CRUNCHY_BYTES_SCHEMA_FILES") +elseif(DEFINED CRUNCHY_BYTES_SCHEMA_DIR) + set(CRUNCHY_BYTES_SCHEMA_FILES "") + file(GLOB_RECURSE CRUNCHY_BYTES_SCHEMA_FILES "${CRUNCHY_BYTES_SCHEMA_DIR}/*.toml") endif() -if (NOT DEFINED CEREAL_PACK_OUTPUT_DIR) +if (NOT DEFINED CRUNCHY_BYTES_OUTPUT_DIR) message(FATAL_ERROR - "An output directory for generated cereal_pack classes must be set using the CMake variable CEREAL_PACK_OUTPUT_DIR") + "An output directory for generated crunchy_bytes classes must be set using the CMake variable CRUNCHY_BYTES_OUTPUT_DIR") endif() -if (DEFINED CEREAL_PACK_GLOBALS) - set(CEREAL_PACK_GLOBALS_OPT "-g" "${CEREAL_PACK_GLOBALS}") +if (DEFINED CRUNCHY_BYTES_GLOBALS) + set(CRUNCHY_BYTES_GLOBALS_OPT "-g" "${CRUNCHY_BYTES_GLOBALS}") endif() -set(CEREAL_PACK_GENERATE_COMMAND +set(CRUNCHY_BYTES_GENERATE_COMMAND "${Python3_EXECUTABLE}" - "${CMAKE_CURRENT_SOURCE_DIR}/cereal_pack.py" - "-o" "${CEREAL_PACK_OUTPUT_DIR}" - "-s" "${CEREAL_PACK_SCHEMA_FILES}" - "${CEREAL_PACK_GLOBALS_OPT}" + "${CMAKE_CURRENT_SOURCE_DIR}/crunchy_bytes.py" + "-o" "${CRUNCHY_BYTES_OUTPUT_DIR}" + "-s" "${CRUNCHY_BYTES_SCHEMA_FILES}" + "${CRUNCHY_BYTES_GLOBALS_OPT}" ) execute_process( - COMMAND ${CEREAL_PACK_GENERATE_COMMAND} --cmake + COMMAND ${CRUNCHY_BYTES_GENERATE_COMMAND} --cmake OUTPUT_VARIABLE GENERATED_FILES RESULT_VARIABLE RETURN_VALUE ) if (NOT RETURN_VALUE EQUAL 0) - message(FATAL_ERROR "Failed to generate source list from cereal_pack schemas. See above") + message(FATAL_ERROR "Failed to generate source list from crunchy_bytes schemas. See above") endif() -set(CEREAL_PACK_GENERATOR_CODE "") -file(GLOB_RECURSE CEREAL_PACK_GENERATOR_CODE - "${CMAKE_CURRENT_SOURCE_DIR}/cereal_pack.py" +set(CRUNCHY_BYTES_GENERATOR_CODE "") +file(GLOB_RECURSE CRUNCHY_BYTES_GENERATOR_CODE + "${CMAKE_CURRENT_SOURCE_DIR}/crunchy_bytes.py" "${CMAKE_CURRENT_SOURCE_DIR}/generator/*.py") add_custom_command( - COMMAND ${CEREAL_PACK_GENERATE_COMMAND} - DEPENDS ${CEREAL_PACK_GENERATOR_CODE} ${CEREAL_PACK_SCHEMA_FILES} ${CEREAL_PACK_GLOBALS} + COMMAND ${CRUNCHY_BYTES_GENERATE_COMMAND} + DEPENDS ${CRUNCHY_BYTES_GENERATOR_CODE} ${CRUNCHY_BYTES_SCHEMA_FILES} ${CRUNCHY_BYTES_GLOBALS} OUTPUT ${GENERATED_FILES} - COMMENT "Generating cereal_pack classes" + COMMENT "Generating crunchy_bytes classes" ) -add_library(cereal_pack_interface INTERFACE ${GENERATED_FILES}) -target_include_directories(cereal_pack_interface INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/includes" "${CEREAL_PACK_OUTPUT_DIR}") +add_library(crunchy_bytes_interface INTERFACE ${GENERATED_FILES}) +target_include_directories(crunchy_bytes_interface INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/includes" "${CRUNCHY_BYTES_OUTPUT_DIR}") diff --git a/README.md b/README.md index 095da6f..fce7a86 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ -# Cereal Pack 🥣 +# Crunchy Bytes 🥣 #### C++ Schema Serialization Library -![cereal-gif](./cereal_pack.gif) +![crunchy-gif](./crunchy_bytes.gif) -## What is Cereal Pack? +## What is Crunchy Bytes? -`cereal_pack` is a C++ 17 library that serializes structured data. +`crunchy_bytes` is a C++ 17 library that serializes structured data. -You bring the data definitions, and `cereal_pack` will generate C++ classes that can +You bring the data definitions, and `crunchy_bytes` will generate C++ classes that can `serialize` and `deserialize` themselves into a compact binary representation that can be easily be transferred between processes. -`cereal_pack` is ideal for IPC, or long term data storage +`crunchy_bytes` is ideal for IPC, or long term data storage ## Getting Started ### Requirements @@ -25,7 +25,7 @@ pip install toml Schemas are defined by creating [TOML](https://toml.io/en/) documents. Each provided `.toml` file will be converted into a C++ class that inherits from -`cereal_pack::Schema`. +`crunchy_bytes::Schema`. The only required top level properties of a TOML schema are it's `name` and its `props`. @@ -48,51 +48,51 @@ Once you have your schemas the process to generate your C++ classes is pretty simple #### Using CMake: -Add `cereal_pack` to your `CMakeLists.txt` as a `subdirectory` +Add `crunchy_bytes` to your `CMakeLists.txt` as a `subdirectory` and tell it where to find your `.toml` schemas, and where to place the generated classes ```cmake -# Either set `CEREAL_PACK_SCHEMA_FILES` explicitly -set(CEREAL_PACK_SCHEMA_FILES +# Either set `CRUNCHY_BYTES_SCHEMA_FILES` explicitly +set(CRUNCHY_BYTES_SCHEMA_FILES "./my_schemas/schema_one.toml" "./my_schemas/schema_two.toml" ) -# OR set `CEREAL_PACK_SCHEMA_DIR` which will recursively search the directory for .toml files -set(CEREAL_PACK_SCHEMA_DIR "./my-schemas") +# OR set `CRUNCHY_BYTES_SCHEMA_DIR` which will recursively search the directory for .toml files +set(CRUNCHY_BYTES_SCHEMA_DIR "./my-schemas") # This will place the generated files in our build directory -set(CEREAL_PACK_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/my-schemas") +set(CRUNCHY_BYTES_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/my-schemas") -# add the `cereal_pack` subdirectory -add_subdirectory(${PATH_TO_CEREAL_PACK} cereal_pack_interface) +# add the `crunchy_bytes` subdirectory +add_subdirectory(${PATH_TO_CRUNCHY_BYTES} crunchy_bytes_interface) ``` -Then simply link `cereal_pack_interface` into your program +Then simply link `crunchy_bytes_interface` into your program ```cmake -target_link_libraries(my_program cereal_pack_interface) +target_link_libraries(my_program crunchy_bytes_interface) ``` -The advantage of using cereal_pack's `CMakeLists.txt` is that any change to `cereal_pack` +The advantage of using crunchy_bytes's `CMakeLists.txt` is that any change to `crunchy_bytes` or to your schemas will cause the generated C++ classes to be regenerated [Check out the test suite CMakeLists.txt for another example](./test/CMakeLists.txt) #### Manually: -First you need to use `cereal_pack.py` to generate the C++ classes +First you need to use `crunchy_bytes.py` to generate the C++ classes ```sh -python cereal_pack.py -s ./my-schemas/* -o generated-classes/ +python crunchy_bytes.py -s ./my-schemas/* -o generated-classes/ ``` -Then simply include `cereal_pack` and the `generated-classes` in your build +Then simply include `crunchy_bytes` and the `generated-classes` in your build ```sh -g++ main.cpp -I./cereal_pack -I./generated-classes -o my_program +g++ main.cpp -I./crunchy_bytes -I./generated-classes -o my_program ``` ## Usage ### Generated C++ Schemas The generated C++ schemas are more or less containers for lists of properties. Each property on the class translates into a getter method which will return a -subclass of `cereal_pack::Property`. +subclass of `crunchy_bytes::Property`. For example, the schema generated by this TOML file ```toml @@ -105,9 +105,9 @@ name = "Cereal" type = "string" max_length = 32 ``` -Will have an `is_cereal` method that returns a `cereal_pack::Primitive` +Will have an `is_cereal` method that returns a `crunchy_bytes::Primitive` -All `cereal_pack::Property` classes are simple wrappers that allow you to `get` +All `crunchy_bytes::Property` classes are simple wrappers that allow you to `get` or `set` the property. Putting it all together: @@ -137,7 +137,7 @@ assert(s.set_of_things()[0] == a_thing); ``` #### Nested schemas -The only property getter that won't return a `cereal_pack::Property` is the `reference` +The only property getter that won't return a `crunchy_bytes::Property` is the `reference` type. When using the `reference` property type to nest schemas, the generated getter @@ -176,12 +176,12 @@ box.brand().set("Kollogs Quran Flakes"); // And if you want to set all the dimensions at once you can use the `=` operator CerealBox same_size_box; same_size_box.box_dimensions() = box.box_dimensions(); -same_size_box.brand().set("Commander Crunch"); +same_size_box.brand().set("Crunchy Bytes"); ``` #### Serialization You probably don't need it explained to you that you can `serialize` and `deserialize` -`cereal_pack` schemas. +`crunchy_bytes` schemas. ```C++ CerealBox box; // TODO: set some of the properties @@ -193,7 +193,7 @@ uint32_t length_read = another_box.deserialize(buffer); #### Constants -All `cereal_pack` schema classes contain a `constants` "namespace" [^1] +All `crunchy_bytes` schema classes contain a `constants` "namespace" [^1] [^1]: Actually C++ doesn't support namespaces inside a class, but a `struct` with the constructor deleted does the trick @@ -260,10 +260,10 @@ for (auto& barcode: stock.barcodes().get()) { } ``` ### Globals -The generated code will _always_ include a file called `cereal_pack_globals.hpp`. +The generated code will _always_ include a file called `crunchy_bytes_globals.hpp`. -This will include the namespace `cereal_pack::globals`, containing constants & -definitions. By default the only thing in here will be `max_cereal_pack_serial_length`, +This will include the namespace `crunchy_bytes::globals`, containing constants & +definitions. By default the only thing in here will be `max_crunchy_bytes_serial_length`, but you can add to this by supplying a global definitions file. Globals can also be used to avoid repeating constant & enum definitions in multiple @@ -272,10 +272,10 @@ schema files. [More detail on globals can be found here](./docs/GLOBALS.md) ### Router -`cereal_pack` provides a router class that can be used to work with messages -created with `cereal_pack`. It is small and simple to use +`crunchy_bytes` provides a router class that can be used to work with messages +created with `crunchy_bytes`. It is small and simple to use ```C++ -using namespace cereal_pack::router; +using namespace crunchy_bytes::router; BasicRouter r([] (const MyCustomHeader& h) { return h.body_name().get(); }); r.attatch_route([](const ImportantEvent& event) { @@ -287,12 +287,12 @@ r.attatch_route([](const UrgentEvent& event) { }); while (true) { - std::vector cereal_data = read_ipc(); - r.handle_message(cereal_data.data()); + std::vector crunchy_data = read_ipc(); + r.handle_message(crunchy_data.data()); } ``` It's up to you to define how you want your message headers to look, -you just need to tell `cereal_pack` how to read your header. +you just need to tell `crunchy_bytes` how to read your header. [More detail on routers can be found here](./docs/ROUTER.md) @@ -301,13 +301,13 @@ you just need to tell `cereal_pack` how to read your header. They probably wouldn't! :) Seriously, [ProtoBuf](https://developers.google.com/protocol-buffers) is a very mature, and well tested library with many more features, and it's developed by freaking _Google_. -`cereal_pack` is a hobby project made by one dude. There is no way it can compete +`crunchy_bytes` is a hobby project made by one dude. There is no way it can compete in terms of features, or stability. -However, if you need something _small & simple_, for C++ _only_, then maybe `cereal_pack` -can work for you. Due to a slightly simpler design `cereal_pack` has a handful of advantages +However, if you need something _small & simple_, for C++ _only_, then maybe `crunchy_bytes` +can work for you. Due to a slightly simpler design `crunchy_bytes` has a handful of advantages -#### It's tiny & embedded friendly +#### It's tiny * The core library that supports the generated C++ classes is _very_ small * It's header only, including the generated classes @@ -317,13 +317,13 @@ can work for you. Due to a slightly simpler design `cereal_pack` has a handful o * There is no "compiler", just some python scripts that generate the C++ classes #### Max sizes -Every `cereal_pack` schema has a _maximum_ size when serialized. Having a determinate +Every `crunchy_bytes` schema has a _maximum_ size when serialized. Having a determinate amount of memory required makes code safer & simpler. And the generated code can always tell you how much space you need to buffer any of your schemas ```C++ -std::array msgBuffer; +std::array msgBuffer; ``` This can make message handling logic very simple, as you can ensure each packet diff --git a/cereal_pack.gif b/cereal_pack.gif deleted file mode 100644 index 7dfeb0d..0000000 Binary files a/cereal_pack.gif and /dev/null differ diff --git a/crunchy_bytes.gif b/crunchy_bytes.gif new file mode 100644 index 0000000..40fffe7 Binary files /dev/null and b/crunchy_bytes.gif differ diff --git a/cereal_pack.py b/crunchy_bytes.py similarity index 92% rename from cereal_pack.py rename to crunchy_bytes.py index 7033a45..87f2098 100644 --- a/cereal_pack.py +++ b/crunchy_bytes.py @@ -7,7 +7,7 @@ def path_of_class(root, schema): return pathlib.Path(root, *schema.name_with_namespace.split('::')[:-1], schema.name + '.hpp') if __name__ == '__main__': - arg_parser = argparse.ArgumentParser(description='Generate cereal pack c++ classes from a list of schemas.') + arg_parser = argparse.ArgumentParser(description='Generate crunchy bytes c++ classes from a list of schemas.') arg_parser.add_argument('--schemas', '-s', metavar='schema', nargs='+', required=True, help='schema files to genearte classes from') @@ -32,7 +32,7 @@ def path_of_class(root, schema): pathlib.Path(args.out_dir).mkdir(exist_ok=True) - with open(pathlib.Path(args.out_dir, 'cereal_pack_globals.hpp'), 'w') as file: + with open(pathlib.Path(args.out_dir, 'crunchy_bytes_globals.hpp'), 'w') as file: file.write(generate.globals_header(globals, schemas)) for s in schemas.values(): diff --git a/docs/GLOBALS.md b/docs/GLOBALS.md index f18162b..b2e2bec 100644 --- a/docs/GLOBALS.md +++ b/docs/GLOBALS.md @@ -1,8 +1,8 @@ ### Globals -The generated code will _always_ include a file called `cereal_pack_globals.hpp`. +The generated code will _always_ include a file called `crunchy_byte_globals.hpp`. -This will include the namespace `cereal_pack::globals`, containing constants & -definitions. By default the only thing in here will be `max_cereal_pack_serial_length`, +This will include the namespace `crunchy_bytes::globals`, containing constants & +definitions. By default the only thing in here will be `max_crunchy_bytes_serial_length`, but you can add to this by supplying a global definitions file. Globals can also be used to avoid repeating constant & enum definitions in multiple @@ -16,25 +16,25 @@ order to facilitate this you can supply a file with global definitions that can be referenced in your schemas. ##### Using CMake -You can define a globals file to use by setting the cmake variable `CEREAL_PACK_GLOBALS` +You can define a globals file to use by setting the cmake variable `CRUNCHY_BYTE_GLOBALS` ```cmake -set(CEREAL_PACK_GLOBALS "${CMAKE_CURRENT_SOURCE_DIR}/cereal_pack_globals.toml") +set(CRUNCHY_BYTE_GLOBALS "${CMAKE_CURRENT_SOURCE_DIR}/crunchy_byte_globals.toml") ``` ##### Manually -The globals file can be passed to `cereal_pack.py` with the `--globals` or `-g` option +The globals file can be passed to `crunchy_bytes.py` with the `--globals` or `-g` option ```sh -python cereal_pack.py -g ./my_globals.toml -s ./my-schemas/* -o generated-classes/ +python crunchy_bytes.py -g ./my_globals.toml -s ./my-schemas/* -o generated-classes/ ``` The file can contain the keys: -* `max_cereal_pack_serial_length` +* `max_crunchy_bytes_serial_length` - This is a `uint32_t` that will be directly added to the `cereal_pack::globals` + This is a `uint32_t` that will be directly added to the `crunchy_bytes::globals` namespace, and will will enforce that _no_ schema ever exceeds this length when serialized (an error will be thrown during code generation). - If you do not supply this feild, it will still appear in the `cereal_pack::gloabls` + If you do not supply this feild, it will still appear in the `crunchy_bytes::gloabls` namespace, with the maximum length that any of your schemas can be when serialized. * `lengths` @@ -49,7 +49,7 @@ The file can contain the keys: E.g. ```toml -max_cereal_pack_serial_length = 8192 +max_crunchy_bytes_serial_length = 8192 [lengths] max_number_of_marshmallows = 100 diff --git a/docs/ROUTER.md b/docs/ROUTER.md index 4951ebf..074dcf0 100644 --- a/docs/ROUTER.md +++ b/docs/ROUTER.md @@ -1,8 +1,8 @@ ### Router -`cereal_pack` provides a router class that can be used to work with messages -created with `cereal_pack`. It is small and simple to use +`crunchy_bytes` provides a router class that can be used to work with messages +created with `crunchy_bytes`. It is small and simple to use ```C++ -using namespace cereal_pack::router; +using namespace crunchy_bytes::router; BasicRouter r([] (const MyCustomHeader& h) { return h.body_name().get(); }); r.attatch_route([](const ImportantEvent& event) { @@ -14,12 +14,12 @@ r.attatch_route([](const UrgentEvent& event) { }); while (true) { - std::vector cereal_data = read_ipc(); - r.handle_message(cereal_data.data()); + std::vector crunchy_data = read_ipc(); + r.handle_message(crunchy_data.data()); } ``` It's up to you to define how you want your message headers to look, -you just need to tell `cereal_pack` how to read your header. +you just need to tell `crunchy_bytes` how to read your header. First, create a new schema that will serve as your header: ```toml @@ -42,9 +42,9 @@ name = "MyCustomHeader" ``` -Now in your C++ code, create a `cereal_pack::router::BasicRouter` +Now in your C++ code, create a `crunchy_bytes::router::BasicRouter` ```C++ -using namespace cereal_pack::router; +using namespace crunchy_bytes::router; BasicRouter router([] (const MyCustomHeader& header) { // this callback defines how the router should get the body_name property // from our custom header diff --git a/docs/SCHEMAS.md b/docs/SCHEMAS.md index 5356188..bf18e27 100644 --- a/docs/SCHEMAS.md +++ b/docs/SCHEMAS.md @@ -2,7 +2,7 @@ Schemas are defined by creating [TOML](https://toml.io/en/) documents. Each provided `.toml` file will be converted into a C++ class that inherits from -`cereal_pack::Schema`. +`crunchy_bytes::Schema`. The only required top level properties of a TOML schema are it's `name` and its `props`. @@ -21,7 +21,7 @@ name = "OneBool" [Check out more examples here](./test/test-schemas) ### Property Types: -Each "prop" should be a valid `cereal_pack` property definition, including at a minimum a `type` +Each "prop" should be a valid `crunchy_bytes` property definition, including at a minimum a `type` #### Primitives There are quite a few `Primitive` types that will be very familiar to any C++ developer @@ -33,7 +33,7 @@ int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t float, double ``` These types don't need any more definition outside the type, and will be represented as -`cereal_pack::Primitive` in the generated C++ schema. +`crunchy_bytes::Primitive` in the generated C++ schema. E.g. ```toml @@ -54,7 +54,7 @@ There are 2 types for byte arrays (think `std::vector`), data that is a fixed size, like a digest. It is not really encoded in any special way and gets [de]serialized "as is". -It is represented by a `cereal_pack::ConstLengthBuffer` in the generated schema +It is represented by a `crunchy_bytes::ConstLengthBuffer` in the generated schema E.g. ```toml @@ -69,7 +69,7 @@ ___ maximum length. It is serialized by writing it's length as a `uint32_t`, followed by its contents. -It is represented by a `cereal_pack::DynamicLengthBuffer` in the generated schema +It is represented by a `crunchy_bytes::DynamicLengthBuffer` in the generated schema E.g. ```toml @@ -82,7 +82,7 @@ ___ In addition to binary data there is a `string` type ##### string This should be pretty self explanatory. -It only supports UTF8, is represented by `cereal_pack::String`, +It only supports UTF8, is represented by `crunchy_bytes::String`, and is encoded as a c-style null terminated string. ```toml @@ -95,11 +95,11 @@ ___ #### Enum An `enum` type shouuld be fairly self explanatory. It is a field that can hold one of a discreet set of values, encoded as a `uint32_t`. The enum can either be -defined within the schema, or defined globally ([see cereal_pack globals](./GLOBALS.md)). The +defined within the schema, or defined globally ([see crunchy_bytes globals](./GLOBALS.md)). The enum should be defined separately to the property, and then set as the properties "enum" -It is represented by a `cereal_pack::Primitive` in the generated schema, +It is represented by a `crunchy_bytes::Primitive` in the generated schema, where T is the enum type. E.g. @@ -129,7 +129,7 @@ enum = "grain_t" ___ #### Reference A `reference` type can _refer_ to any other schema. This is represented by a -`cereal_pack::Reference`, where `T` is the schema being referenced. +`crunchy_bytes::Reference`, where `T` is the schema being referenced. The `reference` key provided must include the schema's namespace (if applicable). E.g. @@ -174,14 +174,14 @@ item = { type = "const_length_buffer", length = 24 } To put a schema inside a namespace of your choosing, just set the the `namespace` top level key for the schema. It may include nested namespaces. ```toml -namespace = "cereal_pack_testing::test" +namespace = "crunchy_bytes_testing::test" ``` Using a namespace will create a subdirectory with the same name, in the output directory where the C++ classes are generated. This is done to avoid path conflicts ```C++ -#include "my_schemas/cereal_pack_testing/test/Example.hpp" -cereal_pack_testing::test::Example e; +#include "my_schemas/crunchy_bytes_testing/test/Example.hpp" +crunchy_bytes_testing::test::Example e; ``` ### Order diff --git a/generator/errors.py b/generator/errors.py index 2507cf5..e6bcffe 100644 --- a/generator/errors.py +++ b/generator/errors.py @@ -1,4 +1,4 @@ -class CerealPackException(Exception): +class CrunchyBytesException(Exception): def __init__(self, file_path, *errors): super().__init__('Error in schema file "{}": {}'.format(file_path, ' '.join(errors))) diff --git a/generator/generate.py b/generator/generate.py index f5524ee..7b21f49 100644 --- a/generator/generate.py +++ b/generator/generate.py @@ -10,7 +10,7 @@ def _length_to_const(length): if type(length) == int: return str(length) elif type(length) == tuple: - return "cereal_pack::globals::" + length[0] + return "crunchy_bytes::globals::" + length[0] else: raise Exception("Invalid length: {}".format(length)) @@ -18,11 +18,11 @@ def globals_header(globals, schemas): template = globals_template global_defs = [] - if globals.max_cereal_pack_serial_length: - max_cereal_pack_serial_length = globals.max_cereal_pack_serial_length + if globals.max_crunchy_bytes_serial_length: + max_crunchy_bytes_serial_length = globals.max_crunchy_bytes_serial_length else: - max_cereal_pack_serial_length = max(map(lambda s: s.max_length(), schemas.values())) - global_defs.append('constexpr uint32_t max_cereal_pack_serial_length = {};'.format(max_cereal_pack_serial_length)) + max_crunchy_bytes_serial_length = max(map(lambda s: s.max_length(), schemas.values())) + global_defs.append('constexpr uint32_t max_crunchy_bytes_serial_length = {};'.format(max_crunchy_bytes_serial_length)) for name, val in globals.lengths.items(): global_defs.append('constexpr uint32_t {} = {};'.format(name, val)) @@ -122,7 +122,7 @@ def class_for_prop(prop): # includes to_include = ['#include "{}.hpp"'.format(i.replace("::", "/")) for i in schema.references] if schema.uses_globals(): - to_include.append('#include "cereal_pack_globals.hpp"') + to_include.append('#include "crunchy_bytes_globals.hpp"') template = replace_placeholder(template, 'INCLUDES', to_include) # enums diff --git a/generator/globals.py b/generator/globals.py index b0492ab..b693337 100644 --- a/generator/globals.py +++ b/generator/globals.py @@ -1,11 +1,11 @@ class Globals: enums = {} lengths = {} - max_cereal_pack_serial_length = None + max_crunchy_bytes_serial_length = None def __init__(self, globals_dict): if not globals_dict: return self.lengths = globals_dict['lengths'] self.enums = globals_dict['enums'] - self.max_cereal_pack_serial_length = globals_dict['max_cereal_pack_serial_length'] + self.max_crunchy_bytes_serial_length = globals_dict['max_crunchy_bytes_serial_length'] diff --git a/generator/parser.py b/generator/parser.py index 2975f17..4ef7821 100644 --- a/generator/parser.py +++ b/generator/parser.py @@ -1,7 +1,7 @@ import toml from . import schema import re -from .errors import CerealPackException +from .errors import CrunchyBytesException from .property_types import length_length from .validation import * from .globals import Globals @@ -10,22 +10,22 @@ def load_toml(file_path): try: return toml.load(file_path) except toml.decoder.TomlDecodeError as e: - raise CerealPackException(file_path, 'TOML decode error: {}'.format(str(e))) + raise CrunchyBytesException(file_path, 'TOML decode error: {}'.format(str(e))) def parse_globals(file_path): raw = load_toml(file_path) if 'lengths' in raw: if not isinstance(raw['lengths'], dict): - raise CerealPackException(file_path, 'expected "lengths" to be a dictionary') + raise CrunchyBytesException(file_path, 'expected "lengths" to be a dictionary') for name, val in raw['lengths'].items(): validate_uint32(file_path, val, 'length ' + name) if 'enums' in raw: validate_enums(file_path, raw['enums']) - if 'max_cereal_pack_serial_length' in raw: - validate_uint32(file_path, raw['max_cereal_pack_serial_length'], '"max_cereal_pack_serial_length"') + if 'max_crunchy_bytes_serial_length' in raw: + validate_uint32(file_path, raw['max_crunchy_bytes_serial_length'], '"max_crunchy_bytes_serial_length"') return Globals(raw) @@ -33,22 +33,22 @@ def parse_schema(file_path, globals=None): raw = load_toml(file_path) if 'name' not in raw: - raise CerealPackException(file_path, 'top level field "name" not found') + raise CrunchyBytesException(file_path, 'top level field "name" not found') if not isinstance(raw['name'], str): - raise CerealPackException(file_path, 'top level field "name" is not a string') + raise CrunchyBytesException(file_path, 'top level field "name" is not a string') if 'props' not in raw: - raise CerealPackException(file_path, 'top level field "props" not found') + raise CrunchyBytesException(file_path, 'top level field "props" not found') if not isinstance(raw['props'], dict): - raise CerealPackException(file_path, 'top level field "props" is not a dictionary') + raise CrunchyBytesException(file_path, 'top level field "props" is not a dictionary') if 'namespace' in raw and not isinstance(raw['namespace'], str): - raise CerealPackException(file_path, 'top level field "namespace" is not a string') + raise CrunchyBytesException(file_path, 'top level field "namespace" is not a string') if 'order' in raw and not isinstance(raw['order'], list): - raise CerealPackException(file_path, 'top level field "order" is not an array') + raise CrunchyBytesException(file_path, 'top level field "order" is not an array') name = raw['name'] props = raw['props'] @@ -62,7 +62,7 @@ def parse_schema(file_path, globals=None): order = raw['order'] for o in order: if not isinstance(o, str): - raise CerealPackException(file_path, 'top level property "order" should be an array of property names') + raise CrunchyBytesException(file_path, 'top level property "order" should be an array of property names') # validate enums @@ -80,14 +80,14 @@ def load_schemas(files, globals_file=None): for file in files: s = parse_schema(file, globals) if s.name_with_namespace in schemas: - raise CerealPackException(s.file_path, 'Schema has same name as "{}"'.format(schemas[s.name_with_namespace].file_path)) + raise CrunchyBytesException(s.file_path, 'Schema has same name as "{}"'.format(schemas[s.name_with_namespace].file_path)) schemas[s.name_with_namespace] = s # resolve references for schema in schemas.values(): for ref_name in schema.references: if ref_name not in schemas: - raise CerealPackException(schema.file_path, 'unable to resolve reference to "{}"'.format(ref_name)) + raise CrunchyBytesException(schema.file_path, 'unable to resolve reference to "{}"'.format(ref_name)) reference = schemas[ref_name] @@ -117,13 +117,13 @@ def resolve_max_length(schema): try: resolve_max_length(schema) except RecursionError: - raise CerealPackException(schema.file_path, 'unable to resolve references due to circular reference') + raise CrunchyBytesException(schema.file_path, 'unable to resolve references due to circular reference') - if globals.max_cereal_pack_serial_length: - if schema.max_length() > globals.max_cereal_pack_serial_length: - raise CerealPackException( + if globals.max_crunchy_bytes_serial_length: + if schema.max_length() > globals.max_crunchy_bytes_serial_length: + raise CrunchyBytesException( schema.file_path, - 'schema exceeds max length defined in "{}": {} > {}'.format(globals_file, schema.max_length(), globals.max_cereal_pack_serial_length) + 'schema exceeds max length defined in "{}": {} > {}'.format(globals_file, schema.max_length(), globals.max_crunchy_bytes_serial_length) ) return schemas, globals diff --git a/generator/property_types.py b/generator/property_types.py index ebae915..e155c5c 100644 --- a/generator/property_types.py +++ b/generator/property_types.py @@ -3,77 +3,77 @@ 'const_length': True, 'predefined_length': 1, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'int8_t': { 'const_length': True, 'predefined_length': 1, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'uint8_t': { 'const_length': True, 'predefined_length': 1, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'int16_t': { 'const_length': True, 'predefined_length': 2, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'uint16_t': { 'const_length': True, 'predefined_length': 2, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'int32_t': { 'const_length': True, 'predefined_length': 4, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'uint32_t': { 'const_length': True, 'predefined_length': 4, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'int64_t': { 'const_length': True, 'predefined_length': 8, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'uint64_t': { 'const_length': True, 'predefined_length': 8, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'float': { 'const_length': True, 'predefined_length': 4, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, 'double': { 'const_length': True, 'predefined_length': 8, 'variable_length': False, - 'class': 'cereal_pack::Primitive' + 'class': 'crunchy_bytes::Primitive' }, @@ -81,7 +81,7 @@ 'const_length': True, 'predefined_length': False, 'variable_length': False, - 'class': 'cereal_pack::ConstLengthBuffer<$LENGTH$>' + 'class': 'crunchy_bytes::ConstLengthBuffer<$LENGTH$>' }, 'dynamic_length_buffer': { @@ -89,7 +89,7 @@ 'predefined_length': False, 'variable_length': True, 'encoding_length': 4, - 'class': 'cereal_pack::DynamicLengthBuffer<$LENGTH$>' + 'class': 'crunchy_bytes::DynamicLengthBuffer<$LENGTH$>' }, 'string': { @@ -97,28 +97,28 @@ 'predefined_length': False, 'variable_length': True, 'encoding_length': 1, - 'class': 'cereal_pack::String<$LENGTH$>' + 'class': 'crunchy_bytes::String<$LENGTH$>' }, 'reference': { 'const_length': False, 'predefined_length': False, 'variable_length': False, - 'class': 'cereal_pack::Reference<$REFERENCE$>' + 'class': 'crunchy_bytes::Reference<$REFERENCE$>' }, 'set': { 'const_length': False, 'predefined_length': False, 'variable_length': False, - 'class': 'cereal_pack::Set<$CLASS$, $LENGTH$>' + 'class': 'crunchy_bytes::Set<$CLASS$, $LENGTH$>' }, 'enum': { 'const_length': True, 'predefined_length': 4, 'variable_length': False, - 'class': 'cereal_pack::Primitive<$CLASS$>' + 'class': 'crunchy_bytes::Primitive<$CLASS$>' }, } diff --git a/generator/schema.py b/generator/schema.py index b0fe27c..3673e01 100644 --- a/generator/schema.py +++ b/generator/schema.py @@ -1,5 +1,5 @@ import re -from .errors import CerealPackException +from .errors import CrunchyBytesException from .property_types import property_types, length_length from .validation import is_int @@ -43,7 +43,7 @@ def __init__(self, file_path, name, dict, enums, validate=True, globals=None): if validate: if re.match('^\w+$', name) is None: - raise CerealPackException(file_path, err_in, '"name" of property must only use alphanumeric characters and underscore, "{}" given'.format(name)) + raise CrunchyBytesException(file_path, err_in, '"name" of property must only use alphanumeric characters and underscore, "{}" given'.format(name)) self.validate_prop(err_in, dict, enums) @@ -66,7 +66,7 @@ def __init__(self, file_path, name, dict, enums, validate=True, globals=None): if dict['enum'] in enums: self.enum = dict['enum'] elif dict['enum'] in self.globals.enums: - self.enum = 'cereal_pack::globals::' + dict['enum'] + self.enum = 'crunchy_bytes::globals::' + dict['enum'] if self.type == 'set': self.max_items = self._to_length_constant(dict['max_items']) @@ -86,48 +86,48 @@ def __init__(self, file_path, name, dict, enums, validate=True, globals=None): # ensure max length was set unless the property contains a reference if self.max_length is None and self.reference is None: - raise CerealPackException(file_path, err_in, 'unable to determine max length of property') + raise CrunchyBytesException(file_path, err_in, 'unable to determine max length of property') def validate_prop(self, err_pre, prop_dict, enums): # type if 'type' not in prop_dict: - raise CerealPackException(self.file_path, err_pre, '"type" not defined') + raise CrunchyBytesException(self.file_path, err_pre, '"type" not defined') if prop_dict['type'] not in property_types: - raise CerealPackException(self.file_path, err_pre, 'unknown property type "{}"'.format(prop_dict['type'])) + raise CrunchyBytesException(self.file_path, err_pre, 'unknown property type "{}"'.format(prop_dict['type'])) type_to_validate = prop_dict['type'] property_type = property_types[type_to_validate] if type_to_validate == 'enum': if 'enum' not in prop_dict: - raise CerealPackException(self.file_path, err_pre, '"enum" key must contain an "enum"') + raise CrunchyBytesException(self.file_path, err_pre, '"enum" key must contain an "enum"') if type(prop_dict['enum']) != str: - raise CerealPackException(self.file_path, err_pre, '"enum" key must be the name of an enum') + raise CrunchyBytesException(self.file_path, err_pre, '"enum" key must be the name of an enum') if prop_dict['enum'] not in enums and prop_dict['enum'] not in self.globals.enums: - raise CerealPackException(self.file_path, err_pre, '"enum" key not found') + raise CrunchyBytesException(self.file_path, err_pre, '"enum" key not found') # reference if type_to_validate == 'reference' and 'reference' not in prop_dict: - raise CerealPackException(self.file_path, err_pre, 'reference property must contain a "reference"') + raise CrunchyBytesException(self.file_path, err_pre, 'reference property must contain a "reference"') # set if type_to_validate == 'set': # item if 'item' not in prop_dict: - raise CerealPackException(self.file_path, err_pre, 'set property must contain an "item"') + raise CrunchyBytesException(self.file_path, err_pre, 'set property must contain an "item"') # max_items if 'max_items' not in prop_dict: - raise CerealPackException(self.file_path, err_pre, 'set property must contain a "max_items"') + raise CrunchyBytesException(self.file_path, err_pre, 'set property must contain a "max_items"') if type(prop_dict['max_items']) is str: if not self._is_global_length(prop_dict['max_items']): - raise CerealPackException(self.file_path, err_pre, 'set property "max_items" is an unknown name. Expected a global length name') + raise CrunchyBytesException(self.file_path, err_pre, 'set property "max_items" is an unknown name. Expected a global length name') elif not is_int(prop_dict['max_items']): - raise CerealPackException(self.file_path, err_pre, 'set property must contain an integer "max_items" or a string name of a global length') + raise CrunchyBytesException(self.file_path, err_pre, 'set property must contain an integer "max_items" or a string name of a global length') # don't allow a set to contain a set if 'type' in prop_dict['item'] and prop_dict['item']['type'] == 'set': - raise CerealPackException(self.file_path, err_pre, 'item of set property cannot be of type "set"') + raise CrunchyBytesException(self.file_path, err_pre, 'item of set property cannot be of type "set"') # validate item self.validate_prop(err_pre + ' in "item" definition:', prop_dict['item'], enums) @@ -135,20 +135,20 @@ def validate_prop(self, err_pre, prop_dict, enums): # length if type(property_type['predefined_length']) != int and property_type['const_length']: if 'length' not in prop_dict: - raise CerealPackException(self.file_path, err_pre, '{} property must contain a "length"'.format(type_to_validate)) + raise CrunchyBytesException(self.file_path, err_pre, '{} property must contain a "length"'.format(type_to_validate)) if type(prop_dict['length']) is str: if not self._is_global_length(prop_dict['length']): - raise CerealPackException(self.file_path, err_pre, '{} property "length" is an unknown name. Expected a global length name'.format(type_to_validate)) + raise CrunchyBytesException(self.file_path, err_pre, '{} property "length" is an unknown name. Expected a global length name'.format(type_to_validate)) elif not is_int(prop_dict['length']): - raise CerealPackException(self.file_path, err_pre, '{} property must contain an integer "length" or a string name of a global length'.format(type_to_validate)) + raise CrunchyBytesException(self.file_path, err_pre, '{} property must contain an integer "length" or a string name of a global length'.format(type_to_validate)) # max_length if property_type['variable_length']: if 'max_length' not in prop_dict: - raise CerealPackException(self.file_path, err_pre, '{} property must contain a "max_length"'.format(type_to_validate)) + raise CrunchyBytesException(self.file_path, err_pre, '{} property must contain a "max_length"'.format(type_to_validate)) if not is_int(prop_dict['max_length']): if not self._is_global_length(prop_dict['max_length']): - raise CerealPackException(self.file_path, err_pre, '{} property must contain an integer "max_length"'.format(type_to_validate)) + raise CrunchyBytesException(self.file_path, err_pre, '{} property must contain an integer "max_length"'.format(type_to_validate)) def __str__(self): return str(self.dict) @@ -165,12 +165,12 @@ def __init__(self, file_path, name, enums, props, namespace=None, order=[], glob self.enums = enums if re.match('^\w+$', name) is None: - raise CerealPackException(file_path, + raise CrunchyBytesException(file_path, '"name" must only contain alphanumeric and underscore charchters') if namespace: if re.match('^\w+(::\w+)*$', namespace) is None: - raise CerealPackException(file_path, + raise CrunchyBytesException(file_path, '"namespace" must only contain alphanumeric and underscore charchters, and "::"') self.name_with_namespace = namespace + "::" + name @@ -182,11 +182,11 @@ def __init__(self, file_path, name, enums, props, namespace=None, order=[], glob for o in self.order: if o not in props: - raise CerealPackException(file_path, + raise CrunchyBytesException(file_path, 'order array contains "{}" which is not a property in this schema'.format(o)) if len(self.order) != len(set(self.order)): - raise CerealPackException(file_path, 'order array contains duplicates'.format(o)) + raise CrunchyBytesException(file_path, 'order array contains duplicates'.format(o)) def max_length(self): if None in [p.max_length for _, p in self.props.items()]: diff --git a/generator/templates.py b/generator/templates.py index 7bc83a5..9a90480 100644 --- a/generator/templates.py +++ b/generator/templates.py @@ -3,12 +3,12 @@ #define __$HEADERGUARD$__ #include -#include "cereal_pack/cereal_pack.hpp" +#include "crunchy_bytes/crunchy_bytes.hpp" $INCLUDES$ $NAMESPACE_START$ -class $NAME$ : public cereal_pack::Schema { +class $NAME$ : public crunchy_bytes::Schema { public: struct constants { static constexpr const char * schema_name = "$NAME_WITH_NAMESPACE$"; @@ -53,10 +53,10 @@ class $NAME$ : public cereal_pack::Schema { $GETTERS$ private: - const std::vector m_properties = { + const std::vector m_properties = { $PROPERTY_PTRS$ }; - virtual const std::vector& properties() const override { + virtual const std::vector& properties() const override { return m_properties; } }; @@ -96,12 +96,12 @@ class $NAME$ : public cereal_pack::Schema { """ globals_template = """ -#ifndef __CEREAL_PACK_GLOBALS_H__ -#define __CEREAL_PACK_GLOBALS_H__ -namespace cereal_pack { +#ifndef __CRUNCHY_BYTES_GLOBALS_H__ +#define __CRUNCHY_BYTES_GLOBALS_H__ +namespace crunchy_bytes { namespace globals { $GLOBALS$ }; }; -#endif // __CEREAL_PACK_GLOBALS_H__ +#endif // __CRUNCHY_BYTES_GLOBALS_H__ """ diff --git a/generator/validation.py b/generator/validation.py index deecc2d..2e3cc49 100644 --- a/generator/validation.py +++ b/generator/validation.py @@ -1,31 +1,31 @@ -from .errors import CerealPackException +from .errors import CrunchyBytesException def is_int(val): return type(val) == int or (type(val) == str and val.isnumeric()) def validate_uint32(file_path, val, err_desc): if type(val) != int: - raise CerealPackException(file_path, '{} is not an integer'.format(err_desc)) + raise CrunchyBytesException(file_path, '{} is not an integer'.format(err_desc)) if val < 0: - raise CerealPackException(file_path, '{} cannot be negative'.format(err_desc)) + raise CrunchyBytesException(file_path, '{} cannot be negative'.format(err_desc)) if val > 0xFFFFFFFF: - raise CerealPackException(file_path, '{} exceeds UINT32_MAX '.format(err_desc)) + raise CrunchyBytesException(file_path, '{} exceeds UINT32_MAX '.format(err_desc)) def validate_enums(file_path, enums): if not isinstance(enums, dict): - raise CerealPackException(file_path, '"enums" should be a dictionary of enums where the key is the name of each enum') + raise CrunchyBytesException(file_path, '"enums" should be a dictionary of enums where the key is the name of each enum') for name, enum in enums.items(): if not isinstance(enum, dict): - raise CerealPackException(file_path, 'enum "{}" should be a dictionary'.format(name)) + raise CrunchyBytesException(file_path, 'enum "{}" should be a dictionary'.format(name)) for val_name, val in enum.items(): err_pre = 'enum "{}.{}"'.format(name, val_name) if not is_int(val): - raise CerealPackException(file_path, err_pre, 'value must be an integer') + raise CrunchyBytesException(file_path, err_pre, 'value must be an integer') if int(val) < 0: - raise CerealPackException(file_path, err_pre, 'value must be positive') + raise CrunchyBytesException(file_path, err_pre, 'value must be positive') if len(set(enum.values())) != len(enum.values()): - raise CerealPackException(file_path, 'enum "{}" values are not unique'.format(name)) + raise CrunchyBytesException(file_path, 'enum "{}" values are not unique'.format(name)) if 0 not in map(lambda v: int(v), enum.values()): - raise CerealPackException(file_path, 'enum "{}" must contain a `0` value, this is the default'.format(name)) + raise CrunchyBytesException(file_path, 'enum "{}" must contain a `0` value, this is the default'.format(name)) diff --git a/includes/cereal_pack/serialization/CerealPackException.hpp b/includes/cereal_pack/serialization/CerealPackException.hpp deleted file mode 100644 index b359be2..0000000 --- a/includes/cereal_pack/serialization/CerealPackException.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _CEREAL_PACK_CEREALPACKEXCEPTION_HPP_ -#define _CEREAL_PACK_CEREALPACKEXCEPTION_HPP_ -#include -#include - -namespace cereal_pack { - class CerealPackException : public std::exception { - const std::string message; - public: - CerealPackException(char const* const message) throw() : - message{"Cereal pack error: " + std::string(message)} {} - - virtual const char* what() const throw() override { - return message.c_str(); - } - }; -}; -#endif //_CEREAL_PACK_CEREALPACKEXCEPTION_HPP_ diff --git a/includes/cereal_pack/cereal_pack.hpp b/includes/crunchy_bytes/crunchy_bytes.hpp similarity index 75% rename from includes/cereal_pack/cereal_pack.hpp rename to includes/crunchy_bytes/crunchy_bytes.hpp index b989823..3e18127 100644 --- a/includes/cereal_pack/cereal_pack.hpp +++ b/includes/crunchy_bytes/crunchy_bytes.hpp @@ -1,8 +1,8 @@ -#ifndef _CEREAL_PACK_HPP_ -#define _CEREAL_PACK_HPP_ +#ifndef _CRUNCHY_BYTES_HPP_ +#define _CRUNCHY_BYTES_HPP_ #include -#include "serialization/CerealPackException.hpp" +#include "serialization/CrunchyBytesException.hpp" #include "serialization/Schema.hpp" #include "serialization/properties/Property.hpp" #include "serialization/properties/Primitive.hpp" @@ -12,4 +12,4 @@ #include "serialization/properties/Reference.hpp" #include "serialization/properties/String.hpp" -#endif //_CEREAL_PACK_HPP_ +#endif //_CRUNCHY_BYTES_HPP_ diff --git a/includes/cereal_pack/router/Router.hpp b/includes/crunchy_bytes/router/Router.hpp similarity index 94% rename from includes/cereal_pack/router/Router.hpp rename to includes/crunchy_bytes/router/Router.hpp index 5d8a3a4..e661f1a 100644 --- a/includes/cereal_pack/router/Router.hpp +++ b/includes/crunchy_bytes/router/Router.hpp @@ -1,11 +1,11 @@ -#ifndef _CEREAL_PACK_ROUTER_HPP_ -#define _CEREAL_PACK_ROUTER_HPP_ +#ifndef _CRUNCHY_BYTES_ROUTER_HPP_ +#define _CRUNCHY_BYTES_ROUTER_HPP_ #include #include #include #include -namespace cereal_pack { +namespace crunchy_bytes { namespace router { template class Router { @@ -64,4 +64,4 @@ namespace cereal_pack { }; }; }; -#endif //_CEREAL_PACK_ROUTER_HPP_ +#endif //_CRUNCHY_BYTES_ROUTER_HPP_ diff --git a/includes/crunchy_bytes/serialization/CrunchyBytesException.hpp b/includes/crunchy_bytes/serialization/CrunchyBytesException.hpp new file mode 100644 index 0000000..12795e5 --- /dev/null +++ b/includes/crunchy_bytes/serialization/CrunchyBytesException.hpp @@ -0,0 +1,18 @@ +#ifndef _CRUNCHY_BYTES_CRUNCHYBYTESEXCEPTION_HPP_ +#define _CRUNCHY_BYTES_CRUNCHYBYTESEXCEPTION_HPP_ +#include +#include + +namespace crunchy_bytes { + class CrunchyBytesException : public std::exception { + const std::string message; + public: + CrunchyBytesException(char const* const message) throw() : + message{"crunchy_bytes error: " + std::string(message)} {} + + virtual const char* what() const throw() override { + return message.c_str(); + } + }; +}; +#endif //_CRUNCHY_BYTES_CRUNCHYBYTESEXCEPTION_HPP_ diff --git a/includes/cereal_pack/serialization/Schema.hpp b/includes/crunchy_bytes/serialization/Schema.hpp similarity index 92% rename from includes/cereal_pack/serialization/Schema.hpp rename to includes/crunchy_bytes/serialization/Schema.hpp index bcecefa..21556b4 100644 --- a/includes/cereal_pack/serialization/Schema.hpp +++ b/includes/crunchy_bytes/serialization/Schema.hpp @@ -1,12 +1,12 @@ -#ifndef _CEREAL_PACK_SCHEMA_HPP_ -#define _CEREAL_PACK_SCHEMA_HPP_ +#ifndef CRUNCHY_BYTES_SCHEMA_HPP_ +#define CRUNCHY_BYTES_SCHEMA_HPP_ #include #include "properties/Property.hpp" #include #include -namespace cereal_pack { +namespace crunchy_bytes { class Schema { public: void reset() { @@ -57,4 +57,4 @@ namespace cereal_pack { virtual const std::vector& properties() const = 0; }; }; -#endif //_CEREAL_PACK_SCHEMA_HPP_ +#endif //CRUNCHY_BYTES_SCHEMA_HPP_ diff --git a/includes/cereal_pack/serialization/properties/ConstLengthBuffer.hpp b/includes/crunchy_bytes/serialization/properties/ConstLengthBuffer.hpp similarity index 94% rename from includes/cereal_pack/serialization/properties/ConstLengthBuffer.hpp rename to includes/crunchy_bytes/serialization/properties/ConstLengthBuffer.hpp index 81e714c..9bbdbc3 100644 --- a/includes/cereal_pack/serialization/properties/ConstLengthBuffer.hpp +++ b/includes/crunchy_bytes/serialization/properties/ConstLengthBuffer.hpp @@ -1,14 +1,14 @@ #ifndef _CERAL_PACK_CONSTLENGTHBUFFER_HPP_ #define _CERAL_PACK_CONSTLENGTHBUFFER_HPP_ #include "Property.hpp" -#include "../CerealPackException.hpp" +#include "../CrunchyBytesException.hpp" #include #include #include #include #include -namespace cereal_pack { +namespace crunchy_bytes { template class ConstLengthBuffer: public Property { public: @@ -20,7 +20,7 @@ namespace cereal_pack { template < template < class ... > class Container, class ... Args > ConstLengthBuffer(const Container& data) { if (data.size() > length) { - throw CerealPackException("Unable to construct `ConstLengthBuffer`, container exceeds max length"); + throw CrunchyBytesException("Unable to construct `ConstLengthBuffer`, container exceeds max length"); } m_value.resize(length); std::fill(m_value.begin(), m_value.end(), 0); diff --git a/includes/cereal_pack/serialization/properties/DynamicLengthBuffer.hpp b/includes/crunchy_bytes/serialization/properties/DynamicLengthBuffer.hpp similarity index 85% rename from includes/cereal_pack/serialization/properties/DynamicLengthBuffer.hpp rename to includes/crunchy_bytes/serialization/properties/DynamicLengthBuffer.hpp index 510bc71..d9e7902 100644 --- a/includes/cereal_pack/serialization/properties/DynamicLengthBuffer.hpp +++ b/includes/crunchy_bytes/serialization/properties/DynamicLengthBuffer.hpp @@ -1,14 +1,14 @@ -#ifndef _CEREAL_PACK_DYNAMICLENGTHBUFFER_HPP_ -#define _CEREAL_PACK_DYNAMICLENGTHBUFFER_HPP_ +#ifndef _CRUNCHY_BYTES_DYNAMICLENGTHBUFFER_HPP_ +#define _CRUNCHY_BYTES_DYNAMICLENGTHBUFFER_HPP_ #include "Property.hpp" -#include "../CerealPackException.hpp" +#include "../CrunchyBytesException.hpp" #include #include #include #include -namespace cereal_pack { +namespace crunchy_bytes { template class DynamicLengthBuffer: public Property { public: @@ -17,7 +17,7 @@ namespace cereal_pack { template < template < class ... > class Container, class ... Args > DynamicLengthBuffer(const Container& data) { if (!length_is_valid(data.size())) { - throw CerealPackException("Unable to construct `DynamicLengthBuffer`, container exceeds max length"); + throw CrunchyBytesException("Unable to construct `DynamicLengthBuffer`, container exceeds max length"); } m_value.resize(max_buffer_length); std::fill(m_value.begin(), m_value.end(), 0); @@ -63,7 +63,7 @@ namespace cereal_pack { virtual uint32_t deserialize(const void* buffer) override { uint32_t l = *(uint32_t*)buffer; if (!length_is_valid(l)) { - throw CerealPackException("Unable to deserialize `DynamicLengthBuffer`, length exceeds max length"); + throw CrunchyBytesException("Unable to deserialize `DynamicLengthBuffer`, length exceeds max length"); } resize(l); memcpy(m_value.data(), (uint8_t*)buffer + sizeof(uint32_t), l); @@ -80,7 +80,7 @@ namespace cereal_pack { void set(uint8_t* data, unsigned int length) { if (!length_is_valid(length)) { - throw CerealPackException("Unable to set `DynamicLengthBuffer`, length exceeds max length"); + throw CrunchyBytesException("Unable to set `DynamicLengthBuffer`, length exceeds max length"); } resize(length); memcpy(data, m_value.data(), length); @@ -92,7 +92,7 @@ namespace cereal_pack { void set(std::vector&& data) { if (!length_is_valid(data.size())) { - throw CerealPackException("Unable to set `DynamicLengthBuffer`, container size exceeds max length"); + throw CrunchyBytesException("Unable to set `DynamicLengthBuffer`, container size exceeds max length"); } m_value = data; } @@ -121,4 +121,4 @@ namespace cereal_pack { }; }; -#endif //_CEREAL_PACK_DYNAMICLENGTHBUFFER_HPP_ +#endif //_CRUNCHY_BYTES_DYNAMICLENGTHBUFFER_HPP_ diff --git a/includes/cereal_pack/serialization/properties/Primitive.hpp b/includes/crunchy_bytes/serialization/properties/Primitive.hpp similarity index 92% rename from includes/cereal_pack/serialization/properties/Primitive.hpp rename to includes/crunchy_bytes/serialization/properties/Primitive.hpp index 711068a..afebcfd 100644 --- a/includes/cereal_pack/serialization/properties/Primitive.hpp +++ b/includes/crunchy_bytes/serialization/properties/Primitive.hpp @@ -1,10 +1,10 @@ -#ifndef _CEREAL_PACK_PRIMITIVE_HPP_ -#define _CEREAL_PACK_PRIMITIVE_HPP_ +#ifndef _CRUNCHY_BYTES_PRIMITIVE_HPP_ +#define _CRUNCHY_BYTES_PRIMITIVE_HPP_ #include "Property.hpp" #include #include -namespace cereal_pack { +namespace crunchy_bytes { template class Primitive : public Property { static_assert(std::is_fundamental::value || std::is_enum::value, @@ -60,4 +60,4 @@ namespace cereal_pack { }; }; -#endif //_CEREAL_PACK_PRIMITIVE_HPP_ +#endif //_CRUNCHY_BYTES_PRIMITIVE_HPP_ diff --git a/includes/cereal_pack/serialization/properties/Property.hpp b/includes/crunchy_bytes/serialization/properties/Property.hpp similarity index 72% rename from includes/cereal_pack/serialization/properties/Property.hpp rename to includes/crunchy_bytes/serialization/properties/Property.hpp index e6be485..a773180 100644 --- a/includes/cereal_pack/serialization/properties/Property.hpp +++ b/includes/crunchy_bytes/serialization/properties/Property.hpp @@ -1,9 +1,9 @@ -#ifndef _CEREAL_PACK_PROPERTY_HPP_ -#define _CEREAL_PACK_PROPERTY_HPP_ +#ifndef _CRUNCHY_BYTES_PROPERTY_HPP_ +#define _CRUNCHY_BYTES_PROPERTY_HPP_ #include #include -namespace cereal_pack { +namespace crunchy_bytes { class Property { public: virtual void reset() = 0; @@ -13,4 +13,4 @@ namespace cereal_pack { virtual uint32_t serial_length() const = 0; }; }; -#endif //_CEREAL_PACK_PROPERTY_HPP_ +#endif //_CRUNCHY_BYTES_PROPERTY_HPP_ diff --git a/includes/cereal_pack/serialization/properties/Reference.hpp b/includes/crunchy_bytes/serialization/properties/Reference.hpp similarity index 93% rename from includes/cereal_pack/serialization/properties/Reference.hpp rename to includes/crunchy_bytes/serialization/properties/Reference.hpp index 1050724..d6fde7b 100644 --- a/includes/cereal_pack/serialization/properties/Reference.hpp +++ b/includes/crunchy_bytes/serialization/properties/Reference.hpp @@ -1,12 +1,12 @@ -#ifndef _CEREAL_PACK_REFERENCE_HPP_ -#define _CEREAL_PACK_REFERENCE_HPP_ +#ifndef _CRUNCHY_BYTES_REFERENCE_HPP_ +#define _CRUNCHY_BYTES_REFERENCE_HPP_ #include "Property.hpp" #include class Schema; -namespace cereal_pack { +namespace crunchy_bytes { template class Reference : public Property { static_assert(std::is_base_of::value, "Reference must refer to a schema"); @@ -66,4 +66,4 @@ namespace cereal_pack { }; }; -#endif //_CEREAL_PACK_REFERENCE_HPP_ +#endif //_CRUNCHY_BYTES_REFERENCE_HPP_ diff --git a/includes/cereal_pack/serialization/properties/Set.hpp b/includes/crunchy_bytes/serialization/properties/Set.hpp similarity index 85% rename from includes/cereal_pack/serialization/properties/Set.hpp rename to includes/crunchy_bytes/serialization/properties/Set.hpp index 8be73c8..e504d26 100644 --- a/includes/cereal_pack/serialization/properties/Set.hpp +++ b/includes/crunchy_bytes/serialization/properties/Set.hpp @@ -1,15 +1,15 @@ -#ifndef _CEREAL_PACK_SET_HPP_ -#define _CEREAL_PACK_SET_HPP_ +#ifndef _CRUNCHY_BYTES_SET_HPP_ +#define _CRUNCHY_BYTES_SET_HPP_ #include "Property.hpp" -#include "../CerealPackException.hpp" +#include "../CrunchyBytesException.hpp" #include #include #include #include #include -namespace cereal_pack { +namespace crunchy_bytes { template class Reference; template @@ -53,7 +53,7 @@ namespace cereal_pack { virtual uint32_t deserialize(const void* buffer) override { uint32_t items = *(uint32_t*)buffer; if (!number_of_items_is_valid(items)) { - throw CerealPackException("Unable to deserialize `Set`, number of items exceeds max length"); + throw CrunchyBytesException("Unable to deserialize `Set`, number of items exceeds max length"); } resize(items); const uint8_t* pos = (uint8_t*)buffer + sizeof(uint32_t); @@ -79,7 +79,7 @@ namespace cereal_pack { void set(const std::vector& data) { if (!number_of_items_is_valid(data.size())) { - throw CerealPackException("Unable to set `Set`, number of items exceeds max length"); + throw CrunchyBytesException("Unable to set `Set`, number of items exceeds max length"); } m_value = data; } @@ -89,7 +89,7 @@ namespace cereal_pack { static_assert(std::is_convertible::value, "Expected `Container` to contain elements convertible to `T`"); if (!number_of_items_is_valid(data.size())) { - throw CerealPackException("Unable to set `Set`, number of items exceeds max length"); + throw CrunchyBytesException("Unable to set `Set`, number of items exceeds max length"); } m_value = {data.begin(), data.end()}; } @@ -100,7 +100,7 @@ namespace cereal_pack { "Expected `Container` to contain elements convertible to `T`"); if (!number_of_items_is_valid(data.size())) { - throw CerealPackException("Unable to set `Set`, number of items exceeds max length"); + throw CrunchyBytesException("Unable to set `Set`, number of items exceeds max length"); } m_value = {data.begin(), data.end()}; } @@ -108,7 +108,7 @@ namespace cereal_pack { template auto push_back(Args&&... args) { if (!number_of_items_is_valid(1 + m_value.size())) { - throw CerealPackException("Unable to `push_back` item to `Set`, number of items exceeds max length"); + throw CrunchyBytesException("Unable to `push_back` item to `Set`, number of items exceeds max length"); } return m_value.push_back(std::forward(args)...); } @@ -116,7 +116,7 @@ namespace cereal_pack { template auto emplace_back(Args&&... args) { if (!number_of_items_is_valid(1 + m_value.size())) { - throw CerealPackException("Unable to `emplace_back` item to `Set`, number of items exceeds max length"); + throw CrunchyBytesException("Unable to `emplace_back` item to `Set`, number of items exceeds max length"); } return m_value.emplace_back(std::forward(args)...); } @@ -143,7 +143,7 @@ namespace cereal_pack { void resize(uint32_t length) { if (!number_of_items_is_valid(length)) { - throw CerealPackException("Unable to resize `Set`, number of items exceeds max length"); + throw CrunchyBytesException("Unable to resize `Set`, number of items exceeds max length"); } m_value.resize(length); } @@ -169,4 +169,4 @@ namespace cereal_pack { std::vector m_value; }; } -#endif //_CEREAL_PACK_SET_HPP_ +#endif //_CRUNCHY_BYTES_SET_HPP_ diff --git a/includes/cereal_pack/serialization/properties/String.hpp b/includes/crunchy_bytes/serialization/properties/String.hpp similarity index 87% rename from includes/cereal_pack/serialization/properties/String.hpp rename to includes/crunchy_bytes/serialization/properties/String.hpp index c1e5b73..e2b0f3f 100644 --- a/includes/cereal_pack/serialization/properties/String.hpp +++ b/includes/crunchy_bytes/serialization/properties/String.hpp @@ -1,13 +1,13 @@ -#ifndef _CEREAL_PACK_STRING_HPP_ -#define _CEREAL_PACK_STRING_HPP_ +#ifndef _CRUNCHY_BYTES_STRING_HPP_ +#define _CRUNCHY_BYTES_STRING_HPP_ #include "Property.hpp" -#include "../CerealPackException.hpp" +#include "../CrunchyBytesException.hpp" #include #include #include -namespace cereal_pack { +namespace crunchy_bytes { template class String: public Property { public: @@ -53,7 +53,7 @@ namespace cereal_pack { while (*(c++)) { unsigned int len = c - (const char*)buffer; if (!length_is_valid(len)) { - throw CerealPackException("Unable to deserialize `String`, it exceeds max length"); + throw CrunchyBytesException("Unable to deserialize `String`, it exceeds max length"); } } @@ -71,7 +71,7 @@ namespace cereal_pack { void set(const std::string& str) { if (!length_is_valid(str.size())) { - throw CerealPackException("Unable to set `String`, it exceeds max length"); + throw CrunchyBytesException("Unable to set `String`, it exceeds max length"); } m_value = str; } @@ -94,4 +94,4 @@ namespace cereal_pack { }; }; -#endif //_CEREAL_PACK_STRING_HPP_ +#endif //_CRUNCHY_BYTES_STRING_HPP_ diff --git a/test/router/BasicRouterTest.cpp b/test/router/BasicRouterTest.cpp index 23217c7..9c30f86 100644 --- a/test/router/BasicRouterTest.cpp +++ b/test/router/BasicRouterTest.cpp @@ -1,13 +1,13 @@ #include -#include -#include +#include +#include #include #include #include #include -using namespace cereal_pack; -using namespace cereal_pack::router; +using namespace crunchy_bytes; +using namespace crunchy_bytes::router; std::array fake_data; diff --git a/test/router/CMakeLists.txt b/test/router/CMakeLists.txt index c91750d..6dcddf2 100644 --- a/test/router/CMakeLists.txt +++ b/test/router/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.6) -project(CerealPackTests CXX) +project(CrunchyBytesTests CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -10,7 +10,7 @@ if (CMAKE_COMPILER_IS_GNUCC) set(WFLAGS "-Wall -Wextra -Werror") endif() -set(CEREAL_PACK_SCHEMA_FILES +set(CRUNCHY_BYTES_SCHEMA_FILES "${CMAKE_CURRENT_SOURCE_DIR}/test-schemas/enum_header.toml" "${CMAKE_CURRENT_SOURCE_DIR}/test-schemas/name_header.toml" "${CMAKE_CURRENT_SOURCE_DIR}/test-schemas/type_one.toml" @@ -18,10 +18,10 @@ set(CEREAL_PACK_SCHEMA_FILES "${CMAKE_CURRENT_SOURCE_DIR}/test-schemas/type_three.toml" ) -set(CEREAL_PACK_GLOBALS "${CMAKE_CURRENT_SOURCE_DIR}/../test_globals.toml") -set(CEREAL_PACK_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test-schemas") +set(CRUNCHY_BYTES_GLOBALS "${CMAKE_CURRENT_SOURCE_DIR}/../test_globals.toml") +set(CRUNCHY_BYTES_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test-schemas") -add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../" cereal_pack_interface) +add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../" crunchy_bytes_interface) # GTEST include(FetchContent) @@ -37,4 +37,4 @@ set(test_sources "") file(GLOB_RECURSE test_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") add_executable(runTests ${test_sources}) -target_link_libraries(runTests pthread cereal_pack_interface gtest_main) +target_link_libraries(runTests pthread crunchy_bytes_interface gtest_main) diff --git a/test/router/EnumRouterTest.cpp b/test/router/EnumRouterTest.cpp index f2aa0d3..9713a90 100644 --- a/test/router/EnumRouterTest.cpp +++ b/test/router/EnumRouterTest.cpp @@ -1,13 +1,13 @@ #include -#include -#include +#include +#include #include #include #include #include -using namespace cereal_pack; -using namespace cereal_pack::router; +using namespace crunchy_bytes; +using namespace crunchy_bytes::router; class EnumRouterTest : public ::testing::Test { protected: diff --git a/test/serialization/CMakeLists.txt b/test/serialization/CMakeLists.txt index aa0d55c..15cb2a1 100644 --- a/test/serialization/CMakeLists.txt +++ b/test/serialization/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.6) -project(CerealPackTests CXX) +project(CrunchyBytesTests CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -10,7 +10,7 @@ if (CMAKE_COMPILER_IS_GNUCC) set(WFLAGS "-Wall -Wextra -Werror") endif() -set(CEREAL_PACK_SCHEMA_FILES +set(CRUNCHY_BYTES_SCHEMA_FILES "${CMAKE_CURRENT_SOURCE_DIR}/test-schemas/nesting.toml" "${CMAKE_CURRENT_SOURCE_DIR}/test-schemas/one_bool.toml" "${CMAKE_CURRENT_SOURCE_DIR}/test-schemas/simple.toml" @@ -18,11 +18,11 @@ set(CEREAL_PACK_SCHEMA_FILES "${CMAKE_CURRENT_SOURCE_DIR}/test-schemas/enums.toml" ) -set(CEREAL_PACK_GLOBALS "${CMAKE_CURRENT_SOURCE_DIR}/../test_globals.toml") -set(CEREAL_PACK_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test-schemas") -set(BUILD_CEREAL_PACK_ROUTER 1) +set(CRUNCHY_BYTES_GLOBALS "${CMAKE_CURRENT_SOURCE_DIR}/../test_globals.toml") +set(CRUNCHY_BYTES_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test-schemas") +set(BUILD_CRUNCHY_BYTES_ROUTER 1) -add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../" cereal_pack_interface) +add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../" crunchy_bytes_interface) # GTEST include(FetchContent) @@ -38,4 +38,4 @@ set(test_sources "") file(GLOB_RECURSE test_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") add_executable(runTests ${test_sources}) -target_link_libraries(runTests pthread cereal_pack_interface gtest_main) +target_link_libraries(runTests pthread crunchy_bytes_interface gtest_main) diff --git a/test/serialization/ConstantsTest.cpp b/test/serialization/ConstantsTest.cpp index f1c3898..a0bb102 100644 --- a/test/serialization/ConstantsTest.cpp +++ b/test/serialization/ConstantsTest.cpp @@ -1,13 +1,13 @@ #include -#include -#include -#include +#include +#include +#include #include #include -using namespace cereal_pack_test::test; -using namespace cereal_pack_test::test::nesting; -using namespace cereal_pack; +using namespace crunchy_bytes_test::test; +using namespace crunchy_bytes_test::test::nesting; +using namespace crunchy_bytes; class ConstantsTest : public ::testing::Test { protected: @@ -36,31 +36,31 @@ TEST_F(ConstantsTest, Constants) { }; TEST_F(ConstantsTest, GlobalConstants) { - EXPECT_EQ(8192, cereal_pack::globals::max_cereal_pack_serial_length); + EXPECT_EQ(8192, crunchy_bytes::globals::max_crunchy_bytes_serial_length); - EXPECT_EQ(10, cereal_pack::globals::max_elements); - EXPECT_EQ(100, cereal_pack::globals::max_item_length); - EXPECT_EQ(255, cereal_pack::globals::max_name_length); + EXPECT_EQ(10, crunchy_bytes::globals::max_elements); + EXPECT_EQ(100, crunchy_bytes::globals::max_item_length); + EXPECT_EQ(255, crunchy_bytes::globals::max_name_length); - EXPECT_EQ(cereal_pack::globals::max_item_length, UsingGlobals::constants::data_one_max_length); - EXPECT_EQ(cereal_pack::globals::max_item_length, UsingGlobals::constants::data_two_max_length); - EXPECT_EQ(cereal_pack::globals::max_name_length, UsingGlobals::constants::name_max_length); - EXPECT_EQ(cereal_pack::globals::max_name_length, UsingGlobals::constants::some_list_of_names_item_max_length); - EXPECT_EQ(cereal_pack::globals::max_item_length, UsingGlobals::constants::some_list_of_buffers_item_max_length); + EXPECT_EQ(crunchy_bytes::globals::max_item_length, UsingGlobals::constants::data_one_max_length); + EXPECT_EQ(crunchy_bytes::globals::max_item_length, UsingGlobals::constants::data_two_max_length); + EXPECT_EQ(crunchy_bytes::globals::max_name_length, UsingGlobals::constants::name_max_length); + EXPECT_EQ(crunchy_bytes::globals::max_name_length, UsingGlobals::constants::some_list_of_names_item_max_length); + EXPECT_EQ(crunchy_bytes::globals::max_item_length, UsingGlobals::constants::some_list_of_buffers_item_max_length); - EXPECT_EQ(cereal_pack::globals::max_elements, UsingGlobals::constants::some_list_of_numbers_max_items); - EXPECT_EQ(cereal_pack::globals::max_elements, UsingGlobals::constants::some_list_of_names_max_items); - EXPECT_EQ(cereal_pack::globals::max_elements, UsingGlobals::constants::some_list_of_buffers_max_items); + EXPECT_EQ(crunchy_bytes::globals::max_elements, UsingGlobals::constants::some_list_of_numbers_max_items); + EXPECT_EQ(crunchy_bytes::globals::max_elements, UsingGlobals::constants::some_list_of_names_max_items); + EXPECT_EQ(crunchy_bytes::globals::max_elements, UsingGlobals::constants::some_list_of_buffers_max_items); } TEST_F(ConstantsTest, SchemaNames) { - EXPECT_EQ(0, strcmp("cereal_pack_test::test::SimpleTest", SimpleTest::constants::schema_name)); + EXPECT_EQ(0, strcmp("crunchy_bytes_test::test::SimpleTest", SimpleTest::constants::schema_name)); SimpleTest s; - EXPECT_EQ(0, strcmp("cereal_pack_test::test::SimpleTest", s.schema_name())); + EXPECT_EQ(0, strcmp("crunchy_bytes_test::test::SimpleTest", s.schema_name())); - EXPECT_EQ(0, strcmp("cereal_pack_test::test::nesting::Nesting", Nesting::constants::schema_name)); + EXPECT_EQ(0, strcmp("crunchy_bytes_test::test::nesting::Nesting", Nesting::constants::schema_name)); Nesting n; - EXPECT_EQ(0, strcmp("cereal_pack_test::test::nesting::Nesting", n.schema_name())); + EXPECT_EQ(0, strcmp("crunchy_bytes_test::test::nesting::Nesting", n.schema_name())); EXPECT_EQ(0, strcmp("OneBool", OneBool::constants::schema_name)); OneBool ob; diff --git a/test/serialization/EqualityTest.cpp b/test/serialization/EqualityTest.cpp index 9beacad..a55c3d9 100644 --- a/test/serialization/EqualityTest.cpp +++ b/test/serialization/EqualityTest.cpp @@ -1,11 +1,11 @@ #include -#include -#include -#include +#include +#include +#include #include -using namespace cereal_pack_test::test; -using namespace cereal_pack_test::test::nesting; +using namespace crunchy_bytes_test::test; +using namespace crunchy_bytes_test::test::nesting; class EqualityTest : public ::testing::Test { protected: void SetUp() override { diff --git a/test/serialization/ExceptionTest.cpp b/test/serialization/ExceptionTest.cpp index 460912d..d0b723c 100644 --- a/test/serialization/ExceptionTest.cpp +++ b/test/serialization/ExceptionTest.cpp @@ -1,7 +1,7 @@ #include -#include +#include -using namespace cereal_pack; +using namespace crunchy_bytes; class ExceptionTest : public ::testing::Test { void SetUp() override { @@ -12,12 +12,12 @@ class ExceptionTest : public ::testing::Test { TEST_F(ExceptionTest, ConstructingConstLengthBuffer) { std::vector vec {1, 2, 3}; - EXPECT_THROW(ConstLengthBuffer<2> cb {vec} , CerealPackException); + EXPECT_THROW(ConstLengthBuffer<2> cb {vec} , CrunchyBytesException); } TEST_F(ExceptionTest, ConstructingDynamicLengthBuffer) { std::vector vec {1, 2, 3}; - EXPECT_THROW(DynamicLengthBuffer<2> db {vec} , CerealPackException); + EXPECT_THROW(DynamicLengthBuffer<2> db {vec} , CrunchyBytesException); } TEST_F(ExceptionTest, DeserializingDynamicLengthBuffer) { @@ -28,21 +28,21 @@ TEST_F(ExceptionTest, DeserializingDynamicLengthBuffer) { db1.serialize(buff.data()); DynamicLengthBuffer<2> db2; - EXPECT_THROW(db2.deserialize(buff.data()), CerealPackException); + EXPECT_THROW(db2.deserialize(buff.data()), CrunchyBytesException); } TEST_F(ExceptionTest, SetDynamicLengthBufferFromPointer) { std::vector vec; vec.resize(100); DynamicLengthBuffer<2> db; - EXPECT_THROW(db.set(vec.data(), vec.size()), CerealPackException); + EXPECT_THROW(db.set(vec.data(), vec.size()), CrunchyBytesException); } TEST_F(ExceptionTest, SetDynamicLengthBufferFromContainer) { std::vector vec; vec.resize(100); DynamicLengthBuffer<2> db; - EXPECT_THROW(db.set(vec), CerealPackException); + EXPECT_THROW(db.set(vec), CrunchyBytesException); } TEST_F(ExceptionTest, DeserializingSet) { @@ -54,44 +54,44 @@ TEST_F(ExceptionTest, DeserializingSet) { s1.serialize(buff.data()); Set, 1> s2; - EXPECT_THROW(s2.deserialize(buff.data()), CerealPackException); + EXPECT_THROW(s2.deserialize(buff.data()), CrunchyBytesException); } TEST_F(ExceptionTest, SetSet) { Set, 2> s; std::vector vec1 {1, 2, 3, 4}; - EXPECT_THROW(s.set(vec1), CerealPackException); + EXPECT_THROW(s.set(vec1), CrunchyBytesException); std::vector> vec2 {1, 2, 3, 4}; - EXPECT_THROW(s.set(vec2), CerealPackException); + EXPECT_THROW(s.set(vec2), CrunchyBytesException); } TEST_F(ExceptionTest, PushBackSet) { Set, 2> s; s.push_back(1); s.push_back(2); - EXPECT_THROW(s.push_back(3), CerealPackException); + EXPECT_THROW(s.push_back(3), CrunchyBytesException); } TEST_F(ExceptionTest, EmplaceBackSet) { Set, 2> s; s.emplace_back(1); s.emplace_back(2); - EXPECT_THROW(s.emplace_back(3), CerealPackException); + EXPECT_THROW(s.emplace_back(3), CrunchyBytesException); } TEST_F(ExceptionTest, ResizeSet) { Set, 2> s; - EXPECT_THROW(s.resize(3), CerealPackException); + EXPECT_THROW(s.resize(3), CrunchyBytesException); } TEST_F(ExceptionTest, DeserializeString) { String<2> s; std::string str = "Hello"; - EXPECT_THROW(s.deserialize(str.c_str()), CerealPackException); + EXPECT_THROW(s.deserialize(str.c_str()), CrunchyBytesException); } TEST_F(ExceptionTest, SetString) { String<2> s; std::string str = "Hello"; - EXPECT_THROW(s.set(str), CerealPackException); + EXPECT_THROW(s.set(str), CrunchyBytesException); } diff --git a/test/serialization/SerializationTest.cpp b/test/serialization/SerializationTest.cpp index 903da68..e58669c 100644 --- a/test/serialization/SerializationTest.cpp +++ b/test/serialization/SerializationTest.cpp @@ -1,12 +1,12 @@ #include -#include -#include -#include +#include +#include +#include #include #include -using namespace cereal_pack_test::test; -using namespace cereal_pack_test::test::nesting; +using namespace crunchy_bytes_test::test; +using namespace crunchy_bytes_test::test::nesting; class SerializationTest : public ::testing::Test { protected: diff --git a/test/serialization/SettingAndGettingTest.cpp b/test/serialization/SettingAndGettingTest.cpp index 9c668c1..3192939 100644 --- a/test/serialization/SettingAndGettingTest.cpp +++ b/test/serialization/SettingAndGettingTest.cpp @@ -1,8 +1,8 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -16,13 +16,13 @@ class SettingAndGettingTest : public ::testing::Test { }; TEST_F(SettingAndGettingTest, CanConstructGeneratedClasses) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; OneBool b; - cereal_pack_test::test::nesting::Nesting n; + crunchy_bytes_test::test::nesting::Nesting n; } TEST_F(SettingAndGettingTest, MaxLengthsMatch) { - using namespace cereal_pack_test::test; + using namespace crunchy_bytes_test::test; SimpleTest s; EXPECT_EQ(s.max_serial_length(), SimpleTest::constants::max_serial_length); @@ -32,7 +32,7 @@ TEST_F(SettingAndGettingTest, MaxLengthsMatch) { } TEST_F(SettingAndGettingTest, CanSetBool) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.boolean().set(false); EXPECT_FALSE(s.boolean().get()); s.boolean().set(true); @@ -40,7 +40,7 @@ TEST_F(SettingAndGettingTest, CanSetBool) { } TEST_F(SettingAndGettingTest, CanSetString) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.string().set("Wow it's a string"); EXPECT_EQ(s.string().get(), "Wow it's a string"); s.string().set("Wow it's still a string"); @@ -48,7 +48,7 @@ TEST_F(SettingAndGettingTest, CanSetString) { } TEST_F(SettingAndGettingTest, CanSetUint8) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.uint8().set(32); EXPECT_EQ(s.uint8().get(), 32); s.uint8().set(251); @@ -56,7 +56,7 @@ TEST_F(SettingAndGettingTest, CanSetUint8) { } TEST_F(SettingAndGettingTest, CanSetInt8) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.int8().set(32); EXPECT_EQ(s.int8().get(), 32); s.int8().set(-4); @@ -64,7 +64,7 @@ TEST_F(SettingAndGettingTest, CanSetInt8) { } TEST_F(SettingAndGettingTest, CanSetUint16) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.uint16().set(1450); EXPECT_EQ(s.uint16().get(), 1450); s.uint16().set(251); @@ -72,7 +72,7 @@ TEST_F(SettingAndGettingTest, CanSetUint16) { } TEST_F(SettingAndGettingTest, CanSetInt16) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.int16().set(1450); EXPECT_EQ(s.int16().get(), 1450); s.int16().set(-4); @@ -80,7 +80,7 @@ TEST_F(SettingAndGettingTest, CanSetInt16) { } TEST_F(SettingAndGettingTest, CanSetUint32) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.uint32().set(242424242); EXPECT_EQ(s.uint32().get(), 242424242); s.uint32().set(251); @@ -88,7 +88,7 @@ TEST_F(SettingAndGettingTest, CanSetUint32) { } TEST_F(SettingAndGettingTest, CanSetInt32) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.int32().set(242424242); EXPECT_EQ(s.int32().get(), 242424242); s.int32().set(-4); @@ -97,7 +97,7 @@ TEST_F(SettingAndGettingTest, CanSetInt32) { TEST_F(SettingAndGettingTest, CanSetUint64) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.uint64().set(32); EXPECT_EQ(s.uint64().get(), 32); s.uint64().set(324425555225252252); @@ -105,7 +105,7 @@ TEST_F(SettingAndGettingTest, CanSetUint64) { } TEST_F(SettingAndGettingTest, CanSetInt64) { - cereal_pack_test::test::SimpleTest s; + crunchy_bytes_test::test::SimpleTest s; s.int64().set(324425555225252252); EXPECT_EQ(s.int64().get(), 324425555225252252); s.int64().set(-4); @@ -113,7 +113,7 @@ TEST_F(SettingAndGettingTest, CanSetInt64) { } TEST_F(SettingAndGettingTest, CanSetConstLengthBuffer) { - using namespace cereal_pack_test::test; + using namespace crunchy_bytes_test::test; SimpleTest s; std::vector buff; @@ -138,7 +138,7 @@ TEST_F(SettingAndGettingTest, CanSetConstLengthBuffer) { } TEST_F(SettingAndGettingTest, CanSetDynamicLengthBuffer) { - using namespace cereal_pack_test::test; + using namespace crunchy_bytes_test::test; SimpleTest s; std::vector buff; @@ -174,7 +174,7 @@ TEST_F(SettingAndGettingTest, CanSetDynamicLengthBuffer) { } TEST_F(SettingAndGettingTest, CanSetReference) { - using namespace cereal_pack_test::test; + using namespace crunchy_bytes_test::test; SimpleTest s; OneBool b; b.boolean().set(true); @@ -185,14 +185,14 @@ TEST_F(SettingAndGettingTest, CanSetReference) { s.reference() = std::move(b); EXPECT_FALSE(s.reference().boolean().get()); - cereal_pack::Reference bRef; + crunchy_bytes::Reference bRef; bRef.get().boolean().set(true); s.reference() = bRef; EXPECT_TRUE(s.reference().boolean().get()); } TEST_F(SettingAndGettingTest, CanSetSetOfPrimitives) { - using namespace cereal_pack_test::test; + using namespace crunchy_bytes_test::test; SimpleTest s; s.set_of_bools().set({false, true, true}); EXPECT_EQ(3, s.set_of_bools().get().size()); @@ -210,7 +210,7 @@ TEST_F(SettingAndGettingTest, CanSetSetOfPrimitives) { ASSERT_EQ(0, s.set_of_bools().size()); s.set_of_bools().push_back(true); - cereal_pack::Primitive b; + crunchy_bytes::Primitive b; b.set(false); s.set_of_bools().push_back(b); s.set_of_bools().push_back(false); @@ -224,7 +224,7 @@ TEST_F(SettingAndGettingTest, CanSetSetOfPrimitives) { ASSERT_EQ(0, s.set_of_bools().size()); s.set_of_bools().emplace_back(true); - cereal_pack::Primitive b2; + crunchy_bytes::Primitive b2; b2.set(false); s.set_of_bools().emplace_back(b2); s.set_of_bools().emplace_back(false); @@ -236,7 +236,7 @@ TEST_F(SettingAndGettingTest, CanSetSetOfPrimitives) { } TEST_F(SettingAndGettingTest, CanSetSetOfReferences) { - using namespace cereal_pack_test::test; + using namespace crunchy_bytes_test::test; SimpleTest s; std::vector refs; @@ -251,7 +251,7 @@ TEST_F(SettingAndGettingTest, CanSetSetOfReferences) { EXPECT_FALSE(s.set_of_references()[1].boolean()); EXPECT_TRUE(s.set_of_references()[2].boolean()); - std::vector> refs2; + std::vector> refs2; refs2.resize(3); refs2[0].get().boolean().set(true); refs2[1].get().boolean().set(false); @@ -266,7 +266,7 @@ TEST_F(SettingAndGettingTest, CanSetSetOfReferences) { s.set_of_references().reset(); ASSERT_EQ(0, s.set_of_references().size()); - cereal_pack::Reference b; + crunchy_bytes::Reference b; b.get().boolean().set(false); s.set_of_references().push_back(b); @@ -305,18 +305,18 @@ TEST_F(SettingAndGettingTest, CanSetSetOfReferences) { s.set_of_references()[0] = oneBool; EXPECT_TRUE(s.set_of_references()[0].boolean()); - cereal_pack::Reference oneBool2; + crunchy_bytes::Reference oneBool2; oneBool2.get().boolean().set(false); s.set_of_references()[0] = oneBool2; EXPECT_FALSE(s.set_of_references()[0].boolean()); } TEST_F(SettingAndGettingTest, CanSetSetOfBuffers) { - using namespace cereal_pack_test::test; + using namespace crunchy_bytes_test::test; SimpleTest s; constexpr auto buffLen = SimpleTest::constants::set_of_buffers_item_max_length; - std::vector> buffs; + std::vector> buffs; buffs.resize(3); memset(buffs[0].get(), 0xFF, buffLen); @@ -404,7 +404,7 @@ TEST_F(SettingAndGettingTest, CanSetSetOfBuffers) { } TEST_F(SettingAndGettingTest, SetNestedProperties) { - using namespace cereal_pack_test::test::nesting; + using namespace crunchy_bytes_test::test::nesting; Nesting n; n.simple_ref().string().set("Yeah"); EXPECT_EQ("Yeah", n.simple_ref().string().get()); @@ -435,8 +435,8 @@ TEST_F(SettingAndGettingTest, SetNestedProperties) { TEST_F(SettingAndGettingTest, SetPropetiesUsingGlobals) { UsingGlobals g; - using namespace cereal_pack::globals; - uint8_t buff[max_cereal_pack_serial_length]; + using namespace crunchy_bytes::globals; + uint8_t buff[max_crunchy_bytes_serial_length]; memset(buff, 0x89, sizeof(buff)); g.data_one().set(buff); EXPECT_EQ(0, memcmp(g.data_one().get(), buff, max_item_length)); @@ -475,14 +475,14 @@ TEST_F(SettingAndGettingTest, SetPropetiesUsingGlobals) { EXPECT_EQ(0, memcmp(g.some_list_of_buffers()[i].get(), buffers[i].data(), max_item_length)); } - g.current_location().set(cereal_pack::globals::continent::asia); - EXPECT_EQ(cereal_pack::globals::continent::asia, g.current_location().get()); + g.current_location().set(crunchy_bytes::globals::continent::asia); + EXPECT_EQ(crunchy_bytes::globals::continent::asia, g.current_location().get()); for (unsigned int i = 0; i < UsingGlobals::constants::bucket_list_max_items; i++) { - g.bucket_list().push_back((cereal_pack::globals::continent)i); + g.bucket_list().push_back((crunchy_bytes::globals::continent)i); } for (unsigned int i = 0; i < UsingGlobals::constants::bucket_list_max_items; i++) { - EXPECT_EQ((cereal_pack::globals::continent)i, g.bucket_list().get()[i]); + EXPECT_EQ((crunchy_bytes::globals::continent)i, g.bucket_list().get()[i]); } EXPECT_EQ(g.serial_length(), g.max_serial_length()); diff --git a/test/serialization/test-schemas/nesting.toml b/test/serialization/test-schemas/nesting.toml index 185c884..b22f52a 100644 --- a/test/serialization/test-schemas/nesting.toml +++ b/test/serialization/test-schemas/nesting.toml @@ -1,4 +1,4 @@ -namespace = "cereal_pack_test::test::nesting" +namespace = "crunchy_bytes_test::test::nesting" name = "Nesting" [props] @@ -8,7 +8,7 @@ name = "Nesting" [props.simple_ref] type = "reference" - reference = "cereal_pack_test::test::SimpleTest" + reference = "crunchy_bytes_test::test::SimpleTest" [props.set_of_bool] type = "set" @@ -18,4 +18,4 @@ name = "Nesting" [props.set_of_simple] type = "set" max_items = 5 - item = { type = "reference", reference = "cereal_pack_test::test::SimpleTest" } + item = { type = "reference", reference = "crunchy_bytes_test::test::SimpleTest" } diff --git a/test/serialization/test-schemas/simple.toml b/test/serialization/test-schemas/simple.toml index ce946a8..722961d 100644 --- a/test/serialization/test-schemas/simple.toml +++ b/test/serialization/test-schemas/simple.toml @@ -1,4 +1,4 @@ -namespace = "cereal_pack_test::test" +namespace = "crunchy_bytes_test::test" name = "SimpleTest" order = ['string', 'boolean', 'uint8', 'dynamic_length_buffer'] diff --git a/test/test_globals.toml b/test/test_globals.toml index c2aeb34..573361a 100644 --- a/test/test_globals.toml +++ b/test/test_globals.toml @@ -1,4 +1,4 @@ -max_cereal_pack_serial_length = 8192 +max_crunchy_bytes_serial_length = 8192 [lengths] max_item_length = 100