diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..6b89e4c3 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,99 @@ +# Aethernet Agent Rules + +## Coding Style + +- Follow **Google C++ Style Guide**. +- **Exception to IWYU:** + - If `foo.cpp` implements `foo.h`, and `foo.h` already includes a header, do NOT re-include it in `foo.cpp`. + - If `base.h` includes a header, `derived.h` should NOT re-include it. +- Always wrap `if` and `for` bodies in `{}` even if it's short one-line statement. +- Initialize variables and objects using `{}` to distinguish from function call. + - *Exception vector initialization*: In case vector must be created with size use `()` initialization to distinguish from initializer_list constructor. +- Always there is possible use `auto` for variables with respect for references `auto&` and pointers `auto*`. +- Check if pointer is null by comparing it to `nullptr` instead of using implicit conversion to `bool`. +- If function arguments is not used, there are two options. If it's never used, just ommit the argument name. If it's used on some configurations use `[[maybe_unused]]` attribute. +- Immediate lambda call pattern should be implemented by using `std::invoke`. + +## Architecture & Object System + +- **Core Objects (`Obj`):** Main entities (`Aether`, `Client`, `Server`, `Channel`) must inherit from `ae::Obj` and use the `AE_OBJECT` macro. +- **Smart Pointers:** Use `ae::ObjPtr` for `Obj`-based classes. Use `ae::PtrView` or raw pointers for weak references from runtime logic to `Obj` instances. +- **Persistence:** Use `Load`/`Save` methods and `AE_OBJECT_REFLECT` for persistent state in `Obj` classes. +- **Business Logic:** Async logic, streams, and drivers must NOT be `Obj`-based. They are "runtime" classes. + +## Events and Callbacks + +- Use events and callbacks to notify external code about state changes. +- If possible use callbacks set up by the constructor. If not, use event-based notifications. +- Try to pass callbacks as template parameters for better optimization. +- If not possible use SmallFunction. +- If not possible use std::function. Notice std::function makes heap allocation we trying to avoid. +- Events uses SmallFunction as a callback storage. +- Prefer setup SmallFunction by MethodPtr<&Class::method>{this} instead of lambda. +- Event subscriptions should be stored in Subscription or MultiSubscriptions class members to control subscription lifetime. +- If the class makes subscription controls lifetime of the object with event, subscription objects maybe ommited. + +## Asynchrony & Tasks + +### Task System + +- Use task system to run tasks asynchronously. +- There is a `ManualTaskScheduler` with methods to define a single `Task` and `DelayedTask` with duration after which the task will be executed. +- To access this scheduler use `ae_context.scheduler()` method. +- Tasks should be lightweight as possible because it stored in fixed-size object pool. +- To control task lifetime use `TaskSubscription` a RAII object which automatically resets task if subscribers die. +- In rare cases class can guarantee its lifetime, subscription may be omitted. + +### Stdexec + +- `stdexec` library is used for chaining low-level async operations. +- whole library connected through one header `aether/executors/executors.h` and defines ex namespace alias. +- all senders should be scheduled on our Task System though ex::SchedulerOnTasks if required. +- there is three types of objects in stdexec: constructors, adapters and consumers. +- constructors are `ex::just()`, `ex::create()` or some custom senders created for specific logic. +- adapters are `ex::then()`, `ex::let_value()`, `ex::let_error()`, `ex::upon_error()` and others that transform or combine senders. +- consumers are `ex::sync_wait`, but preferred to use `ex::AnyWaiter` or `ex:AsyncWaiter`. +- se `ex::create` to create a sender from a functor to integrate c-style callbacks or other non sender logic into the executor. +- use `ex::create` if logic must test the value and set either error or value during runtime +- use `ex::variant_sender` to conditionally return either on or another sender based on some value. +- use `ex::then` `ex::upon_error` to transform from one value to another or from error to value. +- use `ex::let_value` to run new sender in chain in case of set_value. +- use `ex::let_error` to run new sender in chain in case of set_error. +- `ex::for_range` to iterate over a range of values. Internal sender must return a value, an error or stopped to end loop. To cont +- `ex::with_timeout` to add timeout to a sender chain. +- senders and adapters chained together by `|` operator. + +### Actions + +- Use actions to encapsulate high-level async operations. +- The `Action` maybe inherited from `Action` class which adds `is_finished()` and `finished_event()` methods. +- Each action should provide events to notify about operation progress and completion. Usually just `result_event()`. +- Actions may use senders inside to define their logic or just subscribe to another action's events. +- Actions should be managed by the class that creates them and returned by reference or pointers in case of possible null. +- If action `is_finished()` or after `finished_event()` is emitted non should have access to the action except the owner. +- Actions may be created as class members with optional or `ActionPool` or `std::unique_ptr`. But prefer to avoid allocations. + + +## Specific modules implementation + +### AT Commands + +- `at::MakeRequest(at_support, cmd, waits)` returns a pipeable adaptor — use mid-chain. +- `at::MakeRequest(ex::just(), at_support, cmd, waits)` returns a sender — use as first element or inside `ex::let_value`. +- `at::Wait("")` — build waits for the string. +- `at::Wait("", [](auto& buffer, auto pos) { Handlers for response, must return bool })` — build waits for the string and custom handler. +- Timeouts should be implemented using `ex::with_timeout`. + +## Build & Testing + + Project uses cmake, tests run with `ctest`. + Project build configured in `build-clang` (``) with ninja. + To build the project go into `/` and run `cmake --build . --parallel` or `ninja`. + + To run tests, go into `` and run `ctest . --progress -j -E "((sodium)|(hydro)|(bcrypt)).*" --output-on-failure`. + Or run specific test by name from `/tests/run/`. + + To run smoke test, run `/aether-client-cpp-cloud`. + +## Operational Rules +- Do not analyze logs until everything is working fine. diff --git a/CMakeLists.txt b/CMakeLists.txt index df9cdeb7..a12bef95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,12 +105,6 @@ CPMAddPackage( GIT_TAG "master" EXCLUDE_FROM_ALL FALSE ) -# TODO: remove date -CPMAddPackage( - URI "https://github.com/HowardHinnant/date.git#master" - OPTIONS "ENABLE_DATE_INSTALL ${AE_INSTALL}" - EXCLUDE_FROM_ALL FALSE -) CPMAddPackage( NAME numeric GIT_REPOSITORY "https://github.com/aethernetio/aethernet-numeric.git" @@ -118,6 +112,13 @@ CPMAddPackage( OPTIONS "AE_NUMERIC_INSTALL ${AE_INSTALL}" EXCLUDE_FROM_ALL FALSE ) +CPMAddPackage( + NAME aether-miscpp + GIT_REPOSITORY "https://github.com/aethernetio/aether-miscpp.git" + GIT_TAG "main" + OPTIONS "AE_INSTALL ${AE_INSTALL}" "AE_BUILD_TESTS ${AE_BUILD_TESTS}" + EXCLUDE_FROM_ALL FALSE +) CPMAddPackage( NAME etl GIT_REPOSITORY "https://github.com/ETLCPP/etl.git" @@ -152,7 +153,7 @@ target_link_libraries(${TARGET_NAME} PUBLIC etl stdexec numeric - date) + aether::miscpp) message(STATUS "Aether build for CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") if(CMAKE_SYSTEM_NAME STREQUAL "Linux" diff --git a/aether/actions/actions_queue.h b/aether/actions/actions_queue.h index b75a1b4b..74e712b0 100644 --- a/aether/actions/actions_queue.h +++ b/aether/actions/actions_queue.h @@ -22,7 +22,7 @@ #include #include -#include "aether/types/small_function.h" +#include "aether-miscpp/types/small_function.h" #include "aether/events/event_subscription.h" namespace ae { diff --git a/aether/actions/repeatable_task.h b/aether/actions/repeatable_task.h index 484f684e..210b5351 100644 --- a/aether/actions/repeatable_task.h +++ b/aether/actions/repeatable_task.h @@ -21,8 +21,8 @@ #include #include "aether/actions/action.h" -#include "aether/meta/time_traits.h" -#include "aether/types/small_function.h" +#include "aether-miscpp/meta/time_traits.h" +#include "aether-miscpp/types/small_function.h" #include "aether/actions/action_context.h" namespace ae { diff --git a/aether/ae_actions/check_access_for_send_message.h b/aether/ae_actions/check_access_for_send_message.h index 0c46b69c..04ff648a 100644 --- a/aether/ae_actions/check_access_for_send_message.h +++ b/aether/ae_actions/check_access_for_send_message.h @@ -19,7 +19,7 @@ #include "aether/common.h" #include "aether/types/uid.h" -#include "aether/types/result.h" +#include "aether-miscpp/types/result.h" #include "aether/events/events.h" #include "aether/actions/action.h" #include "aether/cloud_connections/cloud_request.h" diff --git a/aether/ae_actions/get_servers.h b/aether/ae_actions/get_servers.h index 925360f6..b78aef5a 100644 --- a/aether/ae_actions/get_servers.h +++ b/aether/ae_actions/get_servers.h @@ -20,7 +20,7 @@ #include #include "aether/ae_context.h" -#include "aether/types/result.h" +#include "aether-miscpp/types/result.h" #include "aether/events/events.h" #include "aether/types/server_id.h" #include "aether/actions/action.h" diff --git a/aether/ae_actions/select_client.h b/aether/ae_actions/select_client.h index 53803463..9633df68 100644 --- a/aether/ae_actions/select_client.h +++ b/aether/ae_actions/select_client.h @@ -20,7 +20,7 @@ #include "aether/config.h" #include "aether/ae_context.h" #include "aether/obj/obj_ptr.h" -#include "aether/types/result.h" +#include "aether-miscpp/types/result.h" #include "aether/events/events.h" #include "aether/actions/action.h" #include "aether/events/event_subscription.h" diff --git a/aether/ae_actions/telemetry.cpp b/aether/ae_actions/telemetry.cpp index 04b179a5..0937d956 100644 --- a/aether/ae_actions/telemetry.cpp +++ b/aether/ae_actions/telemetry.cpp @@ -19,7 +19,7 @@ #if defined TELEMETRY_ENABLED # include "aether/aether.h" -# include "aether/format/format.h" +# include "aether-miscpp/format/format.h" # include "aether/tele/tele.h" # include "aether/tele/traps/tele_statistics.h" diff --git a/aether/ae_actions/time_sync.cpp b/aether/ae_actions/time_sync.cpp index 14020aaa..2f9827c7 100644 --- a/aether/ae_actions/time_sync.cpp +++ b/aether/ae_actions/time_sync.cpp @@ -23,7 +23,7 @@ # include "aether/client.h" # include "aether/aether.h" # include "aether/uap/uap.h" -# include "aether/misc/override.h" +# include "aether-miscpp/misc/override.h" # include "aether/types/iterator.h" # include "aether/executors/executors.h" # include "aether/cloud_connections/cloud_visit.h" diff --git a/aether/aether_app.h b/aether/aether_app.h index 1511b6fa..e2acece3 100644 --- a/aether/aether_app.h +++ b/aether/aether_app.h @@ -27,7 +27,7 @@ #include "aether/ptr/ptr.h" #include "aether/ptr/rc_ptr.h" #include "aether/obj/domain.h" -#include "aether/types/small_function.h" +#include "aether-miscpp/types/small_function.h" #include "aether/events/events.h" // IWYU pragma: keep #include "aether/actions/action.h" // IWYU pragma: keep diff --git a/aether/all.h b/aether/all.h index 7e271de7..264735f5 100644 --- a/aether/all.h +++ b/aether/all.h @@ -32,8 +32,8 @@ #include "aether/events/event_subscription.h" #include "aether/events/multi_subscription.h" -#include "aether/format/format.h" -#include "aether/reflect/reflect.h" +#include "aether-miscpp/format/format.h" +#include "aether-miscpp/reflect/reflect.h" #include "aether/ptr/ptr.h" #include "aether/ptr/rc_ptr.h" #include "aether/ptr/ptr_view.h" diff --git a/aether/api_protocol/api_class_impl.h b/aether/api_protocol/api_class_impl.h index 01a6de4f..d41e6f0f 100644 --- a/aether/api_protocol/api_class_impl.h +++ b/aether/api_protocol/api_class_impl.h @@ -17,7 +17,7 @@ #ifndef AETHER_API_PROTOCOL_API_CLASS_IMPL_H_ #define AETHER_API_PROTOCOL_API_CLASS_IMPL_H_ -#include "aether/reflect/reflect.h" +#include "aether-miscpp/reflect/reflect.h" #include "aether/api_protocol/api_class.h" #include "aether/api_protocol/api_pack_parser.h" diff --git a/aether/api_protocol/api_promise.h b/aether/api_protocol/api_promise.h index bf672302..aa037b81 100644 --- a/aether/api_protocol/api_promise.h +++ b/aether/api_protocol/api_promise.h @@ -19,7 +19,7 @@ #include -#include "aether/types/result.h" +#include "aether-miscpp/types/result.h" #include "aether/events/events.h" #include "aether/api_protocol/request_id.h" diff --git a/aether/api_protocol/protocol_context.h b/aether/api_protocol/protocol_context.h index 18315d9c..051935bf 100644 --- a/aether/api_protocol/protocol_context.h +++ b/aether/api_protocol/protocol_context.h @@ -21,7 +21,7 @@ #include #include -#include "aether/types/small_function.h" +#include "aether-miscpp/types/small_function.h" #include "aether/api_protocol/request_id.h" namespace ae { diff --git a/aether/api_protocol/request_id.h b/aether/api_protocol/request_id.h index 45f34c92..bf5aa504 100644 --- a/aether/api_protocol/request_id.h +++ b/aether/api_protocol/request_id.h @@ -19,7 +19,7 @@ #include -#include "aether/reflect/reflect.h" +#include "aether-miscpp/reflect/reflect.h" namespace ae { struct RequestId { diff --git a/aether/api_protocol/sub_api.h b/aether/api_protocol/sub_api.h index 70ff75e6..58922b78 100644 --- a/aether/api_protocol/sub_api.h +++ b/aether/api_protocol/sub_api.h @@ -19,10 +19,10 @@ #include -#include "aether/meta/type_list.h" -#include "aether/reflect/reflect.h" -#include "aether/types/small_function.h" -#include "aether/meta/function_signature.h" +#include "aether-miscpp/meta/type_list.h" +#include "aether-miscpp/reflect/reflect.h" +#include "aether-miscpp/types/small_function.h" +#include "aether-miscpp/meta/function_signature.h" #include "aether/api_protocol/api_context.h" #include "aether/api_protocol/api_pack_parser.h" diff --git a/aether/channels/channels_types.h b/aether/channels/channels_types.h index 3ec204fc..fed6411a 100644 --- a/aether/channels/channels_types.h +++ b/aether/channels/channels_types.h @@ -20,7 +20,7 @@ #include #include -#include "aether/reflect/reflect.h" +#include "aether-miscpp/reflect/reflect.h" namespace ae { enum class ConnectionType : std::uint8_t { diff --git a/aether/cloud_connections/cloud_callbacks.h b/aether/cloud_connections/cloud_callbacks.h index e0e8135d..962734fc 100644 --- a/aether/cloud_connections/cloud_callbacks.h +++ b/aether/cloud_connections/cloud_callbacks.h @@ -17,7 +17,7 @@ #ifndef AETHER_CLOUD_CONNECTIONS_CLOUD_CALLBACKS_H_ #define AETHER_CLOUD_CONNECTIONS_CLOUD_CALLBACKS_H_ -#include "aether/types/small_function.h" +#include "aether-miscpp/types/small_function.h" #include "aether/events/event_deleter.h" #include "aether/api_protocol/api_protocol.h" diff --git a/aether/cloud_connections/cloud_request.cpp b/aether/cloud_connections/cloud_request.cpp index e0fe029e..7e94a3c8 100644 --- a/aether/cloud_connections/cloud_request.cpp +++ b/aether/cloud_connections/cloud_request.cpp @@ -21,7 +21,7 @@ #include "aether/server.h" #include "aether/aether.h" -#include "aether/reflect/reflect.h" +#include "aether-miscpp/reflect/reflect.h" #include "aether/write_action/write_action.h" #include "aether/cloud_connections/cloud_visit.h" diff --git a/aether/connection_manager/client_cloud_manager.h b/aether/connection_manager/client_cloud_manager.h index 2e18c273..ca3f3169 100644 --- a/aether/connection_manager/client_cloud_manager.h +++ b/aether/connection_manager/client_cloud_manager.h @@ -28,7 +28,7 @@ #include "aether/cloud.h" #include "aether/types/uid.h" -#include "aether/types/result.h" +#include "aether-miscpp/types/result.h" #include "aether/events/events.h" #include "aether/ae_actions/get_servers.h" diff --git a/aether/crc.h b/aether/crc.h deleted file mode 100644 index e020a2f4..00000000 --- a/aether/crc.h +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AETHER_CRC_H_ -#define AETHER_CRC_H_ - -#include -#include -#include - -namespace crc32 { -struct result_t { - std::uint32_t value; - constexpr result_t(); - constexpr result_t(std::uint32_t); - explicit operator std::uint32_t() const; - auto operator==(const result_t&) const -> bool; -}; - -static const auto default_v = result_t(); - -// compile-time versions - -template -constexpr auto from_literal(const char (&_str)[LEN]) -> result_t; -constexpr auto from_string_view(std::string_view _str) -> result_t; -template -constexpr auto checksum_from_literal(const char (&_str)[LEN]) -> std::uint32_t; - -// run-time versions - -auto from_string(char const* _str, result_t _curr = result_t()) -> result_t; -auto from_buffer(const std::uint8_t* _buffer, size_t _cnt, - result_t _curr = result_t()) -> result_t; - -// ============== -// Implementation -// ============== - -// helpers - -namespace details { - -static const auto INITIAL_VALUE = std::uint32_t{0xFFffFFff}; -static const auto XOR_VALUE = std::uint32_t{0xFFffFFff}; - -template -struct aux; - -constexpr std::uint32_t table[256] = { - // polynomial = 0x04C11DB7 - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, -}; - -template <> -struct aux<1, 0> { - static constexpr auto exec(const char (&)[1], result_t, result_t) - -> result_t { - return result_t(XOR_VALUE); - } -}; // Empty string case - -template -struct aux { - static constexpr auto exec(const char (&_str)[LEN], result_t _curr, result_t) - -> result_t { - return aux::exec( - // 1. String itself - _str, - - // 2. Add '_str[INDEX]' to the current crc value - result_t{table[static_cast(_curr.value) ^ - static_cast(_str[INDEX])] ^ - (_curr.value >> 8)}, - - // 3. Pass through the unmodified current crc32 (special case of "end of - // string") - _curr); - } -}; // General case - -template -struct aux { - static constexpr auto exec(const char (&)[LEN], result_t, result_t _prev) - -> result_t { - return _prev; // we don't want to include '\0' at the end of literal - // strings - } -}; // End of string case - -} // namespace details - -// actual implementation - -template -constexpr auto from_literal(const char (&_str)[LEN]) -> result_t { - return details::aux::exec(_str, result_t(), result_t()); -} - -constexpr auto from_string_view(std::string_view _str) -> result_t { - auto _curr = result_t{}; - for (auto const& _char : _str) { - _curr.value = (_curr.value >> 8) ^ - details::table[static_cast(_curr.value) ^ - static_cast(_char)]; - } - return _curr; -} - -template -constexpr auto checksum_from_literal(const char (&_str)[LEN]) -> std::uint32_t { - return from_literal(_str).value ^ details::XOR_VALUE; -} - -inline auto from_string(char const* _str, result_t _curr) -> result_t { - if (_str) { - while (*_str != 0) { - _curr.value = - (_curr.value >> 8) ^ - details::table[uint8_t(_curr.value) ^ std::uint8_t(*_str++)]; - } - } - - return _curr; -} - -inline auto from_buffer(const std::uint8_t* _buff, size_t _cnt, result_t _curr) - -> result_t { - if (_buff) { - for (auto i = 0u; i < _cnt; ++i) { - _curr.value = - (_curr.value >> 8) ^ - details::table[uint8_t(_curr.value) ^ std::uint8_t(*(_buff + i))]; - } - } - - return _curr; -} - -inline constexpr result_t::result_t() : value(details::INITIAL_VALUE) {} -inline constexpr result_t::result_t(uint32_t _val) : value(_val) {} -inline result_t::operator std::uint32_t() const { - return value ^ details::XOR_VALUE; -} -inline auto result_t::operator==(const result_t& _rhs) const -> bool { - return value == _rhs.value; -} - -// ============ -// Unit testing -// ============ -static_assert(checksum_from_literal("") == 0, - "crc32 unit test (empty string) failed!"); -static_assert(checksum_from_literal("A") == 0xD3D99E8B, - "crc32 unit test ('A') failed!"); -static_assert(checksum_from_literal("Hello world") == 0x8BD69E52, - "crc32 unit test ('Hello world') failed!"); - -} // namespace crc32 - -#endif // AETHER_CRC_H_ */ diff --git a/aether/crypto/crypto_nonce.h b/aether/crypto/crypto_nonce.h index 45a3fc15..39975f59 100644 --- a/aether/crypto/crypto_nonce.h +++ b/aether/crypto/crypto_nonce.h @@ -21,7 +21,7 @@ #include #include "aether/config.h" -#include "aether/reflect/reflect.h" +#include "aether-miscpp/reflect/reflect.h" #if AE_CRYPTO_SYNC == AE_CHACHA20_POLY1305 diff --git a/aether/crypto/key.h b/aether/crypto/key.h index e5e5e2ca..a0892f8d 100644 --- a/aether/crypto/key.h +++ b/aether/crypto/key.h @@ -46,7 +46,7 @@ # include # endif -# include "aether/reflect/reflect.h" +# include "aether-miscpp/reflect/reflect.h" # include "aether/types/variant_type.h" namespace ae { diff --git a/aether/crypto/sign.h b/aether/crypto/sign.h index 03ac77db..d071ad11 100644 --- a/aether/crypto/sign.h +++ b/aether/crypto/sign.h @@ -33,7 +33,7 @@ # include # endif -# include "aether/reflect/reflect.h" +# include "aether-miscpp/reflect/reflect.h" # include "aether/types/variant_type.h" namespace ae { diff --git a/aether/crypto/signed_key.h b/aether/crypto/signed_key.h index 223dcd2f..b01c9ab4 100644 --- a/aether/crypto/signed_key.h +++ b/aether/crypto/signed_key.h @@ -22,7 +22,7 @@ #include "aether/crypto/key.h" #include "aether/crypto/sign.h" -#include "aether/reflect/reflect.h" +#include "aether-miscpp/reflect/reflect.h" namespace ae { #if AE_SIGNATURE != AE_NONE diff --git a/aether/dns/dns_c_ares.cpp b/aether/dns/dns_c_ares.cpp index 8693f5f4..41820cbd 100644 --- a/aether/dns/dns_c_ares.cpp +++ b/aether/dns/dns_c_ares.cpp @@ -24,10 +24,12 @@ # include "ares.h" +# include "aether-miscpp/misc/defer.h" +# include "aether-miscpp/types/result.h" + # include "aether/warning_disable.h" # include "aether/aether.h" -# include "aether/types/result.h" # include "aether/socket_initializer.h" # include "aether/events/multi_subscription.h" @@ -212,7 +214,8 @@ ResolveSender DnsResolverCares::Resolve(NamedAddr const& name_address, } return ares_impl_->Query(name_address, port_hint, protocol_hint) | - ex::continues_on(ex::SchedulerOnTasks{AeContext{*aether_.Load().as()}}); + ex::continues_on( + ex::SchedulerOnTasks{AeContext{*aether_.Load().as()}}); } } // namespace ae diff --git a/aether/domain_storage/registrar_domain_storage.cpp b/aether/domain_storage/registrar_domain_storage.cpp index c73b9043..8b19c9ef 100644 --- a/aether/domain_storage/registrar_domain_storage.cpp +++ b/aether/domain_storage/registrar_domain_storage.cpp @@ -22,7 +22,7 @@ # include # include -# include "aether/format/format.h" +# include "aether-miscpp/format/format.h" # include "aether/tele/tele.h" diff --git a/aether/domain_storage/spifs_domain_storage.cpp b/aether/domain_storage/spifs_domain_storage.cpp index e65d6f00..9eee07b5 100644 --- a/aether/domain_storage/spifs_domain_storage.cpp +++ b/aether/domain_storage/spifs_domain_storage.cpp @@ -24,7 +24,7 @@ # include "esp_spiffs.h" # include "spiffs_config.h" -# include "aether/crc.h" +# include "aether-miscpp/crc.h" # include "aether/mstream.h" # include "aether/mstream_buffers.h" diff --git a/aether/events/event_handler.h b/aether/events/event_handler.h index c2945088..5c0c52cc 100644 --- a/aether/events/event_handler.h +++ b/aether/events/event_handler.h @@ -21,7 +21,7 @@ #include "aether/config.h" #include "aether/common.h" -#include "aether/types/small_function.h" +#include "aether-miscpp/types/small_function.h" namespace ae { diff --git a/aether/events/event_list.h b/aether/events/event_list.h index 883d3569..f8899972 100644 --- a/aether/events/event_list.h +++ b/aether/events/event_list.h @@ -24,7 +24,7 @@ #include #include "aether/events/event_handler.h" -#include "aether/types/aligned_storage.h" +#include "aether-miscpp/types/aligned_storage.h" namespace ae { class EventHandlersList { diff --git a/aether/events/events.h b/aether/events/events.h index 72224f63..4922c232 100644 --- a/aether/events/events.h +++ b/aether/events/events.h @@ -26,7 +26,7 @@ #include "aether/events/event_list.h" #include "aether/events/event_handler.h" #include "aether/events/event_deleter.h" -#include "aether/types/small_function.h" +#include "aether-miscpp/types/small_function.h" #include "aether/events/event_subscription.h" namespace ae { diff --git a/aether/executors/any_waiter.h b/aether/executors/any_waiter.h index 91b1a32e..912efdbc 100644 --- a/aether/executors/any_waiter.h +++ b/aether/executors/any_waiter.h @@ -25,8 +25,8 @@ #include -#include "aether/types/result.h" -#include "aether/meta/ignore_t.h" +#include "aether-miscpp/types/result.h" +#include "aether-miscpp/meta/ignore_t.h" #include "aether/executors/waiter_traits.h" #include "aether/executors/async_context.h" #include "aether/executors/scheduler_on_tasks.h" diff --git a/aether/executors/async_waiter.h b/aether/executors/async_waiter.h index d9aa19f7..82f3a0dd 100644 --- a/aether/executors/async_waiter.h +++ b/aether/executors/async_waiter.h @@ -29,8 +29,8 @@ IGNORE_IMPLICIT_CONVERSION() #include DISABLE_WARNING_POP() -#include "aether/types/result.h" -#include "aether/types/small_function.h" +#include "aether-miscpp/types/result.h" +#include "aether-miscpp/types/small_function.h" #include "aether/executors/waiter_traits.h" #include "aether/executors/async_context.h" diff --git a/aether/executors/for_range.h b/aether/executors/for_range.h index ae522989..a8e50250 100644 --- a/aether/executors/for_range.h +++ b/aether/executors/for_range.h @@ -24,7 +24,7 @@ #include #include "aether/types/iterator.h" -#include "aether/meta/type_list.h" +#include "aether-miscpp/meta/type_list.h" namespace ae::ex { namespace for_range_internal { diff --git a/aether/executors/sync_waiter.h b/aether/executors/sync_waiter.h index ed407971..c0758293 100644 --- a/aether/executors/sync_waiter.h +++ b/aether/executors/sync_waiter.h @@ -27,7 +27,7 @@ IGNORE_IMPLICIT_CONVERSION() #include DISABLE_WARNING_POP() -#include "aether/types/result.h" +#include "aether-miscpp/types/result.h" #include "aether/executors/waiter_traits.h" namespace ae::ex { diff --git a/aether/executors/waiter_traits.h b/aether/executors/waiter_traits.h index d31a2262..852f2833 100644 --- a/aether/executors/waiter_traits.h +++ b/aether/executors/waiter_traits.h @@ -29,8 +29,8 @@ IGNORE_IMPLICIT_CONVERSION() #include DISABLE_WARNING_POP() -#include "aether/meta/ignore_t.h" -#include "aether/meta/type_list.h" +#include "aether-miscpp/meta/ignore_t.h" +#include "aether-miscpp/meta/type_list.h" namespace ae::ex { template