You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2022/10/06 08:20:24 UTC
[ignite-3] branch main updated: IGNITE-17831 Portability and style for ignite-3 C++ code (#1166)
This is an automated email from the ASF dual-hosted git repository.
isapego pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new fac922ae83 IGNITE-17831 Portability and style for ignite-3 C++ code (#1166)
fac922ae83 is described below
commit fac922ae8350414c2fe7abda97cab42ee965d717
Author: Aleksey Demakov <ad...@gmail.com>
AuthorDate: Thu Oct 6 11:20:20 2022 +0300
IGNITE-17831 Portability and style for ignite-3 C++ code (#1166)
---
modules/platforms/cpp/.clang-tidy | 163 +++++++++++++++++
.../cpp/client-test/src/ignite_client_test.cpp | 2 +-
modules/platforms/cpp/client-test/src/main.cpp | 1 +
.../platforms/cpp/client-test/src/tables_test.cpp | 6 +-
.../platforms/cpp/client/src/cluster_connection.h | 7 +-
modules/platforms/cpp/client/src/ignite_client.cpp | 3 +-
.../platforms/cpp/client/src/node_connection.cpp | 34 ++--
modules/platforms/cpp/client/src/node_connection.h | 10 +-
.../platforms/cpp/client/src/response_handler.h | 8 +-
.../platforms/cpp/client/src/table/tables_impl.cpp | 21 +--
.../platforms/cpp/client/src/table/tables_impl.h | 9 +-
modules/platforms/cpp/common/CMakeLists.txt | 1 -
modules/platforms/cpp/common/ignite_result.h | 8 +-
modules/platforms/cpp/common/platform.h | 39 ----
modules/platforms/cpp/common/uuid.h | 8 +-
.../network/src/network/length_prefix_codec.cpp | 7 +-
.../include/ignite/protocol/buffer_adapter.h | 30 ++--
.../include/ignite/protocol/extension_types.h | 2 +-
.../cpp/protocol/include/ignite/protocol/reader.h | 116 ++++++++----
.../cpp/protocol/include/ignite/protocol/utils.h | 199 ++++-----------------
.../cpp/protocol/include/ignite/protocol/writer.h | 67 +++----
.../platforms/cpp/protocol/src/buffer_adapter.cpp | 13 +-
modules/platforms/cpp/protocol/src/reader.cpp | 57 ++----
modules/platforms/cpp/protocol/src/utils.cpp | 63 +++++--
modules/platforms/cpp/protocol/src/writer.cpp | 17 +-
.../platforms/cpp/schema/binary_tuple_builder.h | 12 +-
.../platforms/cpp/schema/binary_tuple_parser.cpp | 112 ++++++------
modules/platforms/cpp/schema/ignite_time.h | 11 +-
28 files changed, 529 insertions(+), 497 deletions(-)
diff --git a/modules/platforms/cpp/.clang-tidy b/modules/platforms/cpp/.clang-tidy
new file mode 100644
index 0000000000..934da921f2
--- /dev/null
+++ b/modules/platforms/cpp/.clang-tidy
@@ -0,0 +1,163 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+---
+Checks: '-*,
+bugprone-argument-comment,
+bugprone-assert-side-effect,
+bugprone-bad-signal-to-kill-thread,
+bugprone-branch-clone,
+bugprone-copy-constructor-init,
+bugprone-dangling-handle,
+bugprone-dynamic-static-initializers,
+bugprone-fold-init-type,
+bugprone-forward-declaration-namespace,
+bugprone-forwarding-reference-overload,
+bugprone-inaccurate-erase,
+bugprone-incorrect-roundings,
+bugprone-integer-division,
+bugprone-lambda-function-name,
+bugprone-macro-parentheses,
+bugprone-macro-repeated-side-effects,
+bugprone-misplaced-operator-in-strlen-in-alloc,
+bugprone-misplaced-pointer-arithmetic-in-alloc,
+bugprone-misplaced-widening-cast,
+bugprone-move-forwarding-reference,
+bugprone-multiple-statement-macro,
+bugprone-no-escape,
+bugprone-not-null-terminated-result,
+bugprone-parent-virtual-call,
+bugprone-posix-return,
+bugprone-reserved-identifier,
+bugprone-sizeof-container,
+bugprone-sizeof-expression,
+bugprone-spuriously-wake-up-functions,
+bugprone-string-constructor,
+bugprone-string-integer-assignment,
+bugprone-string-literal-with-embedded-nul,
+bugprone-suspicious-enum-usage,
+bugprone-suspicious-include,
+bugprone-suspicious-memory-comparison,
+bugprone-suspicious-memset-usage,
+bugprone-suspicious-missing-comma,
+bugprone-suspicious-semicolon,
+bugprone-suspicious-string-compare,
+bugprone-swapped-arguments,
+bugprone-terminating-continue,
+bugprone-throw-keyword-missing,
+bugprone-too-small-loop-variable,
+bugprone-undefined-memory-manipulation,
+bugprone-undelegated-constructor,
+bugprone-unhandled-self-assignment,
+bugprone-unused-raii,
+bugprone-unused-return-value,
+bugprone-use-after-move,
+bugprone-virtual-near-miss,
+cert-dcl21-cpp,
+cert-dcl58-cpp,
+cert-err34-c,
+cert-err52-cpp,
+cert-err60-cpp,
+cert-flp30-c,
+cert-msc50-cpp,
+cert-msc51-cpp,
+cert-str34-c,
+cppcoreguidelines-interfaces-global-init,
+cppcoreguidelines-narrowing-conversions,
+cppcoreguidelines-pro-type-member-init,
+cppcoreguidelines-pro-type-static-cast-downcast,
+cppcoreguidelines-slicing,
+google-default-arguments,
+google-explicit-constructor,
+google-runtime-operator,
+hicpp-exception-baseclass,
+hicpp-multiway-paths-covered,
+misc-misplaced-const,
+misc-new-delete-overloads,
+misc-no-recursion,
+misc-non-copyable-objects,
+misc-throw-by-value-catch-by-reference,
+misc-unconventional-assign-operator,
+misc-uniqueptr-reset-release,
+modernize-avoid-bind,
+modernize-concat-nested-namespaces,
+modernize-deprecated-headers,
+modernize-deprecated-ios-base-aliases,
+modernize-loop-convert,
+modernize-make-shared,
+modernize-make-unique,
+modernize-pass-by-value,
+modernize-raw-string-literal,
+modernize-redundant-void-arg,
+modernize-replace-auto-ptr,
+modernize-replace-disallow-copy-and-assign-macro,
+modernize-replace-random-shuffle,
+modernize-return-braced-init-list,
+modernize-shrink-to-fit,
+modernize-unary-static-assert,
+modernize-use-auto,
+modernize-use-bool-literals,
+modernize-use-emplace,
+modernize-use-equals-default,
+modernize-use-equals-delete,
+modernize-use-nodiscard,
+modernize-use-noexcept,
+modernize-use-nullptr,
+modernize-use-override,
+modernize-use-transparent-functors,
+modernize-use-uncaught-exceptions,
+mpi-buffer-deref,
+mpi-type-mismatch,
+openmp-use-default-none,
+performance-faster-string-find,
+performance-for-range-copy,
+performance-implicit-conversion-in-loop,
+performance-inefficient-algorithm,
+performance-inefficient-string-concatenation,
+performance-inefficient-vector-operation,
+performance-move-const-arg,
+performance-move-constructor-init,
+performance-no-automatic-move,
+performance-noexcept-move-constructor,
+performance-trivially-destructible,
+performance-type-promotion-in-math-fn,
+performance-unnecessary-copy-initialization,
+performance-unnecessary-value-param,
+portability-simd-intrinsics,
+readability-avoid-const-params-in-decls,
+readability-const-return-type,
+readability-container-size-empty,
+readability-convert-member-functions-to-static,
+readability-delete-null-pointer,
+readability-deleted-default,
+readability-inconsistent-declaration-parameter-name,
+readability-make-member-function-const,
+readability-misleading-indentation,
+readability-misplaced-array-index,
+readability-non-const-parameter,
+readability-redundant-control-flow,
+readability-redundant-declaration,
+readability-redundant-function-ptr-dereference,
+readability-redundant-smartptr-get,
+readability-redundant-string-cstr,
+readability-redundant-string-init,
+readability-simplify-subscript-expr,
+readability-static-accessed-through-instance,
+readability-static-definition-in-anonymous-namespace,
+readability-string-compare,
+readability-uniqueptr-delete-release,
+readability-use-anyofallof'
\ No newline at end of file
diff --git a/modules/platforms/cpp/client-test/src/ignite_client_test.cpp b/modules/platforms/cpp/client-test/src/ignite_client_test.cpp
index ef6f05cde7..ddb951c28e 100644
--- a/modules/platforms/cpp/client-test/src/ignite_client_test.cpp
+++ b/modules/platforms/cpp/client-test/src/ignite_client_test.cpp
@@ -29,7 +29,7 @@ using namespace ignite;
/**
* Test suite.
*/
-class client_test : public ignite_runner_suite {};
+class client_test : public ignite_runner_suite { };
TEST_F(client_test, get_configuration) {
IgniteClientConfiguration cfg{NODE_ADDRS};
diff --git a/modules/platforms/cpp/client-test/src/main.cpp b/modules/platforms/cpp/client-test/src/main.cpp
index cbe91c3325..1cd0d3a9ba 100644
--- a/modules/platforms/cpp/client-test/src/main.cpp
+++ b/modules/platforms/cpp/client-test/src/main.cpp
@@ -16,6 +16,7 @@
*/
#include "ignite_runner.h"
+
#include "common/ignite_error.h"
#include <gtest/gtest.h>
diff --git a/modules/platforms/cpp/client-test/src/tables_test.cpp b/modules/platforms/cpp/client-test/src/tables_test.cpp
index fc82788517..e2cd48f408 100644
--- a/modules/platforms/cpp/client-test/src/tables_test.cpp
+++ b/modules/platforms/cpp/client-test/src/tables_test.cpp
@@ -31,7 +31,7 @@ using namespace ignite;
/**
* Test suite.
*/
-class tables_test : public ignite_runner_suite {};
+class tables_test : public ignite_runner_suite { };
TEST_F(tables_test, tables_get_table_async_promises) {
IgniteClientConfiguration cfg{NODE_ADDRS};
@@ -141,9 +141,7 @@ TEST_F(tables_test, tables_get_tables_async_promises) {
auto tables = tablesPromise->get_future().get();
ASSERT_GT(tables.size(), 0);
- auto it = std::find_if(tables.begin(), tables.end(), [] (auto& table) {
- return table.getName() == "PUB.TBL1";
- });
+ auto it = std::find_if(tables.begin(), tables.end(), [](auto &table) { return table.getName() == "PUB.TBL1"; });
ASSERT_NE(it, tables.end());
}
diff --git a/modules/platforms/cpp/client/src/cluster_connection.h b/modules/platforms/cpp/client/src/cluster_connection.h
index 4a232bb09d..56d53247b4 100644
--- a/modules/platforms/cpp/client/src/cluster_connection.h
+++ b/modules/platforms/cpp/client/src/cluster_connection.h
@@ -39,7 +39,7 @@
namespace ignite::protocol {
-class Reader;
+class reader;
}
@@ -98,7 +98,7 @@ public:
* @param handler Response handler.
*/
template <typename T>
- void performRequest(ClientOperation op, const std::function<void(protocol::Writer &)> &wr,
+ void performRequest(ClientOperation op, const std::function<void(protocol::writer &)> &wr,
std::shared_ptr<ResponseHandlerImpl<T>> handler) {
while (true) {
auto channel = getRandomChannel();
@@ -120,7 +120,8 @@ public:
*/
template <typename T>
void performRequest(ClientOperation op, std::shared_ptr<ResponseHandlerImpl<T>> handler) {
- performRequest(op, [](protocol::Writer&) {}, std::move(handler));
+ performRequest(
+ op, [](protocol::writer &) {}, std::move(handler));
}
private:
diff --git a/modules/platforms/cpp/client/src/ignite_client.cpp b/modules/platforms/cpp/client/src/ignite_client.cpp
index 7b5a0febd7..3cac527f79 100644
--- a/modules/platforms/cpp/client/src/ignite_client.cpp
+++ b/modules/platforms/cpp/client/src/ignite_client.cpp
@@ -27,8 +27,7 @@ void IgniteClient::startAsync(IgniteClientConfiguration configuration, std::chro
ignite_callback<IgniteClient> callback) {
// TODO: IGNITE-17762 Async start should not require starting thread internally. Replace with async timer.
(void)std::async([cfg = std::move(configuration), timeout, callback = std::move(callback)]() mutable {
- auto res = result_of_operation<IgniteClient>(
- [cfg = std::move(cfg), timeout]() { return start(cfg, timeout); });
+ auto res = result_of_operation<IgniteClient>([cfg = std::move(cfg), timeout]() { return start(cfg, timeout); });
callback(std::move(res));
});
}
diff --git a/modules/platforms/cpp/client/src/node_connection.cpp b/modules/platforms/cpp/client/src/node_connection.cpp
index 5903eabcdb..efc441d751 100644
--- a/modules/platforms/cpp/client/src/node_connection.cpp
+++ b/modules/platforms/cpp/client/src/node_connection.cpp
@@ -46,10 +46,10 @@ bool NodeConnection::handshake() {
std::vector<std::byte> message;
{
- protocol::BufferAdapter buffer(message);
- buffer.writeRawData(bytes_view(protocol::MAGIC_BYTES.data(), protocol::MAGIC_BYTES.size()));
+ protocol::buffer_adapter buffer(message);
+ buffer.write_raw(bytes_view(protocol::MAGIC_BYTES.data(), protocol::MAGIC_BYTES.size()));
- protocol::Writer::writeMessageToBuffer(buffer, [&context = m_protocolContext](protocol::Writer &writer) {
+ protocol::write_message_to_buffer(buffer, [&context = m_protocolContext](protocol::writer &writer) {
auto ver = context.getVersion();
writer.write(ver.getMajor());
@@ -59,10 +59,10 @@ bool NodeConnection::handshake() {
writer.write(CLIENT_TYPE);
// Features.
- writer.writeBinaryEmpty();
+ writer.write_binary_empty();
// Extensions.
- writer.writeMapEmpty();
+ writer.write_map_empty();
});
}
@@ -70,14 +70,14 @@ bool NodeConnection::handshake() {
}
void NodeConnection::processMessage(bytes_view msg) {
- protocol::Reader reader(msg);
- auto responseType = reader.readInt32();
+ protocol::reader reader(msg);
+ auto responseType = reader.read_int32();
if (MessageType(responseType) != MessageType::RESPONSE) {
m_logger->logWarning("Unsupported message type: " + std::to_string(responseType));
return;
}
- auto reqId = reader.readInt64();
+ auto reqId = reader.read_int64();
auto handler = getAndRemoveHandler(reqId);
if (!handler) {
@@ -85,7 +85,7 @@ void NodeConnection::processMessage(bytes_view msg) {
return;
}
- auto err = protocol::readError(reader);
+ auto err = protocol::read_error(reader);
if (err) {
m_logger->logError("Error: " + err->what_str());
auto res = handler->setError(std::move(err.value()));
@@ -103,11 +103,11 @@ void NodeConnection::processMessage(bytes_view msg) {
ignite_result<void> NodeConnection::processHandshakeRsp(bytes_view msg) {
m_logger->logDebug("Got handshake response");
- protocol::Reader reader(msg);
+ protocol::reader reader(msg);
- auto verMajor = reader.readInt16();
- auto verMinor = reader.readInt16();
- auto verPatch = reader.readInt16();
+ auto verMajor = reader.read_int16();
+ auto verMinor = reader.read_int16();
+ auto verPatch = reader.read_int16();
ProtocolVersion ver(verMajor, verMinor, verPatch);
m_logger->logDebug("Server-side protocol version: " + ver.toString());
@@ -116,13 +116,13 @@ ignite_result<void> NodeConnection::processHandshakeRsp(bytes_view msg) {
if (ver != ProtocolContext::CURRENT_VERSION)
return {ignite_error("Unsupported server version: " + ver.toString())};
- auto err = protocol::readError(reader);
+ auto err = protocol::read_error(reader);
if (err)
return {ignite_error(err.value())};
- (void)reader.readInt64(); // TODO: IGNITE-17606 Implement heartbeats
- (void)reader.readStringNullable(); // Cluster node ID. Needed for partition-aware compute.
- (void)reader.readStringNullable(); // Cluster node name. Needed for partition-aware compute.
+ (void)reader.read_int64(); // TODO: IGNITE-17606 Implement heartbeats
+ (void)reader.read_string_nullable(); // Cluster node ID. Needed for partition-aware compute.
+ (void)reader.read_string_nullable(); // Cluster node name. Needed for partition-aware compute.
reader.skip(); // Features.
reader.skip(); // Extensions.
diff --git a/modules/platforms/cpp/client/src/node_connection.h b/modules/platforms/cpp/client/src/node_connection.h
index 81451b2e29..e06a294048 100644
--- a/modules/platforms/cpp/client/src/node_connection.h
+++ b/modules/platforms/cpp/client/src/node_connection.h
@@ -92,20 +92,20 @@ public:
* @return @c true on success and @c false otherwise.
*/
template <typename T>
- bool performRequest(ClientOperation op, const std::function<void(protocol::Writer &)> &wr,
+ bool performRequest(ClientOperation op, const std::function<void(protocol::writer &)> &wr,
std::shared_ptr<ResponseHandlerImpl<T>> handler) {
auto reqId = generateRequestId();
std::vector<std::byte> message;
{
- protocol::BufferAdapter buffer(message);
- buffer.reserveLengthHeader();
+ protocol::buffer_adapter buffer(message);
+ buffer.reserve_length_header();
- protocol::Writer writer(buffer);
+ protocol::writer writer(buffer);
writer.write(int32_t(op));
writer.write(reqId);
wr(writer);
- buffer.writeLengthHeader();
+ buffer.write_length_header();
{
std::lock_guard<std::mutex> lock(m_requestHandlersMutex);
diff --git a/modules/platforms/cpp/client/src/response_handler.h b/modules/platforms/cpp/client/src/response_handler.h
index 127f7998f6..29ec44edca 100644
--- a/modules/platforms/cpp/client/src/response_handler.h
+++ b/modules/platforms/cpp/client/src/response_handler.h
@@ -46,7 +46,7 @@ public:
/**
* Handle response.
*/
- [[nodiscard]] virtual ignite_result<void> handle(protocol::Reader &) = 0;
+ [[nodiscard]] virtual ignite_result<void> handle(protocol::reader &) = 0;
/**
* Set error.
@@ -75,7 +75,7 @@ public:
*
* @param func Function.
*/
- explicit ResponseHandlerImpl(std::function<T(protocol::Reader &)> readFunc, ignite_callback<T> callback)
+ explicit ResponseHandlerImpl(std::function<T(protocol::reader &)> readFunc, ignite_callback<T> callback)
: m_readFunc(std::move(readFunc))
, m_callback(std::move(callback))
, m_mutex() { }
@@ -85,7 +85,7 @@ public:
*
* @param reader Reader to be used to read response.
*/
- [[nodiscard]] ignite_result<void> handle(protocol::Reader &reader) final {
+ [[nodiscard]] ignite_result<void> handle(protocol::reader &reader) final {
ignite_callback<T> callback = removeCallback();
if (!callback)
return {};
@@ -121,7 +121,7 @@ private:
}
/** Read function. */
- std::function<T(protocol::Reader &)> m_readFunc;
+ std::function<T(protocol::reader &)> m_readFunc;
/** Promise. */
ignite_callback<T> m_callback;
diff --git a/modules/platforms/cpp/client/src/table/tables_impl.cpp b/modules/platforms/cpp/client/src/table/tables_impl.cpp
index a08eb024dd..8f128bdadf 100644
--- a/modules/platforms/cpp/client/src/table/tables_impl.cpp
+++ b/modules/platforms/cpp/client/src/table/tables_impl.cpp
@@ -15,18 +15,19 @@
* limitations under the License.
*/
+#include "tables_impl.h"
+
#include "ignite/protocol/reader.h"
#include "ignite/protocol/writer.h"
-#include "table/tables_impl.h"
namespace ignite::detail {
void TablesImpl::getTableAsync(const std::string &name, ignite_callback<std::optional<Table>> callback) {
- auto readerFunc = [name](protocol::Reader &reader) -> std::optional<Table> {
- if (reader.tryReadNil())
+ auto readerFunc = [name](protocol::reader &reader) -> std::optional<Table> {
+ if (reader.try_read_nil())
return std::nullopt;
- auto id = reader.readUuid();
+ auto id = reader.read_uuid();
auto tableImpl = std::make_shared<TableImpl>(name, id);
return std::make_optional(Table(tableImpl));
@@ -36,23 +37,23 @@ void TablesImpl::getTableAsync(const std::string &name, ignite_callback<std::opt
std::make_shared<ResponseHandlerImpl<std::optional<Table>>>(std::move(readerFunc), std::move(callback));
m_connection->performRequest(
- ClientOperation::TABLE_GET, [&name](protocol::Writer &writer) { writer.write(name); }, std::move(handler));
+ ClientOperation::TABLE_GET, [&name](protocol::writer &writer) { writer.write(name); }, std::move(handler));
}
void TablesImpl::getTablesAsync(ignite_callback<std::vector<Table>> callback) {
- auto readerFunc = [](protocol::Reader &reader) -> std::vector<Table> {
- if (reader.tryReadNil())
+ auto readerFunc = [](protocol::reader &reader) -> std::vector<Table> {
+ if (reader.try_read_nil())
return {};
std::vector<Table> tables;
- tables.reserve(reader.readMapSize());
+ tables.reserve(reader.read_map_size());
- reader.readMap<uuid, std::string>([&tables] (auto&& id, auto&& name) {
+ reader.read_map<uuid, std::string>([&tables](auto &&id, auto &&name) {
auto tableImpl = std::make_shared<TableImpl>(std::forward<std::string>(name), std::forward<uuid>(id));
tables.push_back(Table{tableImpl});
});
- return std::move(tables);
+ return tables;
};
auto handler =
diff --git a/modules/platforms/cpp/client/src/table/tables_impl.h b/modules/platforms/cpp/client/src/table/tables_impl.h
index b40eec4054..378ea5d451 100644
--- a/modules/platforms/cpp/client/src/table/tables_impl.h
+++ b/modules/platforms/cpp/client/src/table/tables_impl.h
@@ -17,14 +17,13 @@
#pragma once
-#include <future>
-#include <memory>
-
-#include "ignite/table/table.h"
-
#include "cluster_connection.h"
+#include "ignite/table/table.h"
#include "table/table_impl.h"
+#include <future>
+#include <memory>
+
namespace ignite::detail {
/**
diff --git a/modules/platforms/cpp/common/CMakeLists.txt b/modules/platforms/cpp/common/CMakeLists.txt
index f5b53892df..0cacc35d7e 100644
--- a/modules/platforms/cpp/common/CMakeLists.txt
+++ b/modules/platforms/cpp/common/CMakeLists.txt
@@ -26,7 +26,6 @@ set(HEADERS
guid.h
ignite_error.h
ignite_result.h
- platform.h
types.h
uuid.h)
diff --git a/modules/platforms/cpp/common/ignite_result.h b/modules/platforms/cpp/common/ignite_result.h
index 67b3957759..8eb58572e6 100644
--- a/modules/platforms/cpp/common/ignite_result.h
+++ b/modules/platforms/cpp/common/ignite_result.h
@@ -23,8 +23,8 @@
#include <functional>
#include <future>
#include <optional>
-#include <variant>
#include <string>
+#include <variant>
namespace ignite {
@@ -211,7 +211,6 @@ public:
*/
explicit operator bool() const noexcept { return !has_error(); }
-
private:
/** Error. */
std::optional<ignite_error> m_error;
@@ -244,7 +243,7 @@ ignite_result<T> result_of_operation(const std::function<T()> &operation) noexce
return {ignite_error(status_code::GENERIC, msg, std::current_exception())};
} catch (...) {
return {ignite_error(status_code::UNKNOWN, "Unknown error is encountered when processing network event",
- std::current_exception())};
+ std::current_exception())};
}
}
@@ -277,8 +276,7 @@ void result_set_promise(std::promise<T> &pr, ignite_result<T> &&res) {
template <typename T>
std::function<void(ignite_result<T>)> result_promise_setter(std::shared_ptr<std::promise<T>> pr) {
// TODO: IGNITE-17760 Move to common once it's re-factored
- return [pr = std::move(pr)](
- ignite_result<T> &&res) mutable { result_set_promise<T>(*pr, std::move(res)); };
+ return [pr = std::move(pr)](ignite_result<T> &&res) mutable { result_set_promise<T>(*pr, std::move(res)); };
}
} // namespace ignite
diff --git a/modules/platforms/cpp/common/platform.h b/modules/platforms/cpp/common/platform.h
deleted file mode 100644
index a08f231131..0000000000
--- a/modules/platforms/cpp/common/platform.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-#pragma once
-
-namespace ignite::platform {
-
-/**
- * Byte order utility class.
- */
-class ByteOrder {
-private:
- static constexpr uint32_t fourBytes = 0x01020304;
- static constexpr uint8_t lesserByte = (const uint8_t &)fourBytes;
-
-public:
- ByteOrder() = delete;
-
- static constexpr bool littleEndian = lesserByte == 0x04;
- static constexpr bool bigEndian = lesserByte == 0x01;
-
- static_assert(littleEndian || bigEndian, "Unknown byte order");
-};
-
-} // ignite::platform
diff --git a/modules/platforms/cpp/common/uuid.h b/modules/platforms/cpp/common/uuid.h
index 848b313e06..254ce99155 100644
--- a/modules/platforms/cpp/common/uuid.h
+++ b/modules/platforms/cpp/common/uuid.h
@@ -72,7 +72,9 @@ public:
*
* @return The version number of this instance.
*/
- [[nodiscard]] constexpr std::int32_t version() const noexcept { return static_cast<std::int32_t>((most >> 12) & 0x0f); }
+ [[nodiscard]] constexpr std::int32_t version() const noexcept {
+ return static_cast<std::int32_t>((most >> 12) & 0x0f);
+ }
/**
* The variant number associated with this instance. The variant
@@ -243,8 +245,8 @@ template <typename C, typename T>
is.flags(savedFlags);
- result = uuid(std::int64_t((parts[0] << 32) | (parts[1] << 16) | parts[2]),
- std::int64_t((parts[3] << 48) | parts[4]));
+ result =
+ uuid(std::int64_t((parts[0] << 32) | (parts[1] << 16) | parts[2]), std::int64_t((parts[3] << 48) | parts[4]));
return is;
}
diff --git a/modules/platforms/cpp/network/src/network/length_prefix_codec.cpp b/modules/platforms/cpp/network/src/network/length_prefix_codec.cpp
index fdd5aa7b40..e7d1bbb8d6 100644
--- a/modules/platforms/cpp/network/src/network/length_prefix_codec.cpp
+++ b/modules/platforms/cpp/network/src/network/length_prefix_codec.cpp
@@ -15,9 +15,10 @@
* limitations under the License.
*/
-#include "ignite/protocol/utils.h"
+#include "ignite/network/length_prefix_codec.h"
-#include <ignite/network/length_prefix_codec.h>
+#include "common/bytes.h"
+#include "ignite/protocol/utils.h"
namespace ignite::network {
@@ -61,7 +62,7 @@ DataBufferRef LengthPrefixCodec::decode(DataBufferRef &data) {
if (m_packet.size() < PACKET_HEADER_SIZE)
return {};
- m_packetSize = protocol::readInt32(m_packet.data());
+ m_packetSize = bytes::load<Endian::LITTLE, int32_t>(m_packet.data());
}
consume(data, m_packetSize + PACKET_HEADER_SIZE);
diff --git a/modules/platforms/cpp/protocol/include/ignite/protocol/buffer_adapter.h b/modules/platforms/cpp/protocol/include/ignite/protocol/buffer_adapter.h
index 1bb45fabe3..a1f9ed6cef 100644
--- a/modules/platforms/cpp/protocol/include/ignite/protocol/buffer_adapter.h
+++ b/modules/platforms/cpp/protocol/include/ignite/protocol/buffer_adapter.h
@@ -17,18 +17,18 @@
#pragma once
-#include <limits>
-
-#include <msgpack.h>
-
#include "common/types.h"
+#include <limits>
+
namespace ignite::protocol {
/**
- * BufferAdapter.
+ * Buffer adapter.
+ *
+ * Used to allow msgpack classes to write data to std::vector<std::byte>.
*/
-class BufferAdapter {
+class buffer_adapter {
public:
/** Length header size in bytes. */
static constexpr size_t LENGTH_HEADER_SIZE = 4;
@@ -38,43 +38,43 @@ public:
*
* @param data Data.
*/
- explicit BufferAdapter(std::vector<std::byte> &data)
+ explicit buffer_adapter(std::vector<std::byte> &data)
: m_buffer(data)
- , m_lengthPos(std::numeric_limits<std::size_t>::max()) { }
+ , m_length_pos(std::numeric_limits<std::size_t>::max()) { }
/**
* Write raw data.
*
* @param data Data to write.
*/
- void writeRawData(bytes_view data) { m_buffer.insert(m_buffer.end(), data.begin(), data.end()); }
+ void write_raw(bytes_view data) { m_buffer.insert(m_buffer.end(), data.begin(), data.end()); }
/**
* Get underlying data buffer view.
*
* @return Underlying data buffer view.
*/
- [[nodiscard]] bytes_view getData() const { return m_buffer; }
+ [[nodiscard]] bytes_view data() const { return m_buffer; }
/**
* Reserving space for length header.
*/
- void reserveLengthHeader() {
- m_lengthPos = m_buffer.size();
+ void reserve_length_header() {
+ m_length_pos = m_buffer.size();
m_buffer.insert(m_buffer.end(), 4, std::byte{0});
}
/**
* Write buffer length to previously reserved position.
*/
- void writeLengthHeader();
+ void write_length_header();
private:
- /** BufferAdapter. */
+ /** Buffer */
std::vector<std::byte> &m_buffer;
/** Length position. */
- std::size_t m_lengthPos{std::numeric_limits<std::size_t>::max()};
+ std::size_t m_length_pos{std::numeric_limits<std::size_t>::max()};
};
} // namespace ignite::protocol
diff --git a/modules/platforms/cpp/protocol/include/ignite/protocol/extension_types.h b/modules/platforms/cpp/protocol/include/ignite/protocol/extension_types.h
index d6b564b5fb..7ae226a216 100644
--- a/modules/platforms/cpp/protocol/include/ignite/protocol/extension_types.h
+++ b/modules/platforms/cpp/protocol/include/ignite/protocol/extension_types.h
@@ -24,7 +24,7 @@ namespace ignite::protocol {
/**
* Extension types.
*/
-enum class ExtensionTypes : std::int8_t {
+enum class extension_type : std::int8_t {
NUMBER = 1,
DECIMAL = 2,
diff --git a/modules/platforms/cpp/protocol/include/ignite/protocol/reader.h b/modules/platforms/cpp/protocol/include/ignite/protocol/reader.h
index 135a51bedf..1ec6f8740c 100644
--- a/modules/platforms/cpp/protocol/include/ignite/protocol/reader.h
+++ b/modules/platforms/cpp/protocol/include/ignite/protocol/reader.h
@@ -17,96 +17,144 @@
#pragma once
-#include <cstdint>
-#include <functional>
+#include "common/ignite_error.h"
+#include "common/types.h"
+#include "common/uuid.h"
+#include "ignite/protocol/utils.h"
#include <msgpack.h>
-#include "common/uuid.h"
-#include "common/types.h"
-
-#include "ignite/protocol/utils.h"
+#include <cstdint>
+#include <functional>
namespace ignite::protocol {
/**
* Reader.
*/
-class Reader {
+class reader {
public:
// Deleted
- Reader() = delete;
- Reader(Reader &&) = delete;
- Reader(const Reader &) = delete;
- Reader &operator=(Reader &&) = delete;
- Reader &operator=(const Reader &) = delete;
+ reader() = delete;
+ reader(reader &&) = delete;
+ reader(const reader &) = delete;
+ reader &operator=(reader &&) = delete;
+ reader &operator=(const reader &) = delete;
/**
* Constructor.
*
* @param buffer Buffer.
*/
- explicit Reader(bytes_view buffer);
+ explicit reader(bytes_view buffer);
/**
* Destructor.
*/
- ~Reader() { msgpack_unpacker_destroy(&m_unpacker); }
+ ~reader() { msgpack_unpacker_destroy(&m_unpacker); }
+
+ /**
+ * Read object of type T from msgpack stream.
+ *
+ * @tparam T Type of the object to read.
+ * @return Object of type T.
+ * @throw ignite_error if there is no object of specified type in the stream.
+ */
+ template <typename T>
+ [[nodiscard]] T read_object() {
+ check_data_in_stream();
+
+ auto res = unpack_object<T>(m_current_val.data);
+ next();
+
+ return res;
+ }
+
+ /**
+ * Read object of type T from msgpack stream or nil.
+ *
+ * @tparam T Type of the object to read.
+ * @return Object of type T or std::nullopt if there is nil in the stream.
+ * @throw ignite_error if there is no object of specified type in the stream.
+ */
+ template <typename T>
+ [[nodiscard]] std::optional<T> read_object_nullable() {
+ if (try_read_nil())
+ return std::nullopt;
+
+ return read_object<T>();
+ }
+
+ /**
+ * Read object of type T from msgpack stream or returns default value if the value in stream is nil.
+ *
+ * @tparam T Type of the object to read.
+ * @param on_nil Object to be returned on nil.
+ * @return Object of type T or @c on_nil if there is nil in stream.
+ * @throw ignite_error if there is no object of specified type in the stream.
+ */
+ template <typename T>
+ [[nodiscard]] T read_object_or_default(T &&on_nil) {
+ if (try_read_nil())
+ return std::forward<T>(on_nil);
+
+ return read_object<T>();
+ }
/**
* Read int16.
*
* @return Value.
*/
- [[nodiscard]] std::int16_t readInt16() { return std::int16_t(readInt64()); }
+ [[nodiscard]] std::int16_t read_int16() { return read_object<std::int16_t>(); }
/**
* Read int32.
*
* @return Value.
*/
- [[nodiscard]] std::int32_t readInt32() { return std::int32_t(readInt64()); }
+ [[nodiscard]] std::int32_t read_int32() { return read_object<std::int32_t>(); }
/**
* Read int64 number.
*
* @return Value.
*/
- [[nodiscard]] std::int64_t readInt64();
+ [[nodiscard]] std::int64_t read_int64() { return read_object<int64_t>(); }
/**
* Read string.
*
* @return String value.
*/
- [[nodiscard]] std::string readString();
+ [[nodiscard]] std::string read_string() { return read_object<std::string>(); }
/**
* Read string.
*
* @return String value or nullopt.
*/
- [[nodiscard]] std::optional<std::string> readStringNullable();
+ [[nodiscard]] std::optional<std::string> read_string_nullable() { return read_object_nullable<std::string>(); }
/**
* Read UUID.
*
* @return UUID value.
*/
- [[nodiscard]] uuid readUuid();
+ [[nodiscard]] uuid read_uuid() { return read_object<uuid>(); }
/**
* Read Map size.
*
* @return Map size.
*/
- [[nodiscard]] uint32_t readMapSize() const {
- checkDataInStream();
+ [[nodiscard]] uint32_t read_map_size() const {
+ check_data_in_stream();
- if (m_currentVal.data.type != MSGPACK_OBJECT_MAP)
+ if (m_current_val.data.type != MSGPACK_OBJECT_MAP)
throw ignite_error("The value in stream is not a Map");
- return m_currentVal.data.via.map.size;
+ return m_current_val.data.via.map.size;
}
/**
@@ -116,12 +164,12 @@ public:
* @tparam V Value type.
* @param handler Pair handler.
*/
- template<typename K, typename V>
- void readMap(const std::function<void(K&&, V&&)>& handler) {
- auto size = readMapSize();
+ template <typename K, typename V>
+ void read_map(const std::function<void(K &&, V &&)> &handler) {
+ auto size = read_map_size();
for (std::uint32_t i = 0; i < size; ++i) {
- auto key = unpack_object<K>(m_currentVal.data.via.map.ptr[i].key);
- auto val = unpack_object<V>(m_currentVal.data.via.map.ptr[i].val);
+ auto key = unpack_object<K>(m_current_val.data.via.map.ptr[i].key);
+ auto val = unpack_object<V>(m_current_val.data.via.map.ptr[i].val);
handler(std::move(key), std::move(val));
}
}
@@ -131,7 +179,7 @@ public:
*
* @return @c true if the value was nil.
*/
- bool tryReadNil();
+ bool try_read_nil();
/**
* Skip next value.
@@ -147,8 +195,8 @@ private:
/**
* Check whether there is a data in stream and throw ignite_error if there is none.
*/
- void checkDataInStream() const {
- if (m_moveRes < 0)
+ void check_data_in_stream() const {
+ if (m_move_res < 0)
throw ignite_error("No more data in stream");
}
@@ -159,10 +207,10 @@ private:
msgpack_unpacker m_unpacker;
/** Current value. */
- msgpack_unpacked m_currentVal;
+ msgpack_unpacked m_current_val;
/** Result of the last move operation. */
- msgpack_unpack_return m_moveRes;
+ msgpack_unpack_return m_move_res;
};
} // namespace ignite::protocol
diff --git a/modules/platforms/cpp/protocol/include/ignite/protocol/utils.h b/modules/platforms/cpp/protocol/include/ignite/protocol/utils.h
index 4d97d9df06..fe05c14728 100644
--- a/modules/platforms/cpp/protocol/include/ignite/protocol/utils.h
+++ b/modules/platforms/cpp/protocol/include/ignite/protocol/utils.h
@@ -17,185 +17,52 @@
#pragma once
-#include <cstddef>
-#include <cstdint>
-
-#include <array>
-#include <optional>
-
-#include "common/ignite_error.h"
#include "common/bytes.h"
+#include "common/ignite_error.h"
#include "common/types.h"
#include "common/uuid.h"
-
#include "ignite/protocol/extension_types.h"
+#include <array>
+#include <optional>
+
+#include <cstddef>
+#include <cstdint>
+
struct msgpack_object;
namespace ignite::protocol {
-class Reader;
+class reader;
/** Magic bytes. */
static constexpr std::array<std::byte, 4> MAGIC_BYTES = {
std::byte('I'), std::byte('G'), std::byte('N'), std::byte('I')};
-/**
- * Read uint64 from bytes stream.
- *
- * @param data Data.
- * @param offset Offset.
- * @return Value
- */
-inline uint64_t readUint64(const std::byte *data, size_t offset = 0) {
- // TODO IGNITE-17760: Replace read and write functions with ones from common/Bytes.h
- return (std::uint64_t(data[offset]) << 56) | (std::uint64_t(data[offset + 1]) << 48)
- | (std::uint64_t(data[offset + 2]) << 40) | (std::uint64_t(data[offset + 3]) << 32)
- | (std::uint64_t(data[offset + 4]) << 24) | (std::uint64_t(data[offset + 5]) << 16)
- | (std::uint64_t(data[offset + 6]) << 8) | std::uint64_t(data[offset + 7]);
-}
-
-/**
- * Read int64 from bytes stream.
- *
- * @param data Data.
- * @param offset Offset.
- * @return Value
- */
-inline int64_t readInt64(const std::byte *data, size_t offset = 0) {
- return std::int64_t(readUint64(data, offset));
-}
-
-/**
- * Read uint32 from bytes stream.
- *
- * @param data Data.
- * @param offset Offset.
- * @return Value
- */
-inline uint32_t readUint32(const std::byte *data, size_t offset = 0) {
- return (std::uint32_t(data[offset]) << 24) | (std::uint32_t(data[offset + 1]) << 16)
- | (std::uint32_t(data[offset + 2]) << 8) | std::uint32_t(data[offset + 3]);
-}
-
-/**
- * Read int32 from bytes stream.
- *
- * @param data Data.
- * @param offset Offset.
- * @return Value
- */
-inline int32_t readInt32(const std::byte *data, size_t offset = 0) {
- return std::int32_t(readUint32(data, offset));
-}
-
-/**
- * Read uint16 from bytes stream.
- *
- * @param data Data.
- * @param offset Offset.
- * @return Value
- */
-inline uint16_t readUint16(const std::byte *data, size_t offset = 0) {
- return std::uint16_t(data[offset + 1]) | (std::uint16_t(data[offset]) << 8);
-}
-
-/**
- * Read int16 from bytes stream.
- *
- * @param data Data.
- * @param offset Offset.
- * @return Value
- */
-inline int16_t readInt16(const std::byte *data, size_t offset = 0) {
- return std::int16_t(readUint16(data, offset));
+template <typename T>
+[[nodiscard]] T unpack_object(const msgpack_object &) {
+ static_assert(sizeof(T) == 0, "Unpacking is not implemented for the type");
}
/**
- * Write uint64 to byte stream.
- *
- * @param value Value to write.
- * @param buffer Buffer.
- * @param offset Offset.
- * @return Value
- */
-inline void writeUint64(uint64_t value, std::byte *buffer, size_t offset = 0) {
- buffer[offset] = std::byte((value & 0xFF000000'00000000) >> 56);
- buffer[offset + 1] = std::byte((value & 0x00FF0000'00000000) >> 48);
- buffer[offset + 2] = std::byte((value & 0x0000FF00'00000000) >> 40);
- buffer[offset + 3] = std::byte((value & 0x000000FF'00000000) >> 32);
- buffer[offset + 4] = std::byte((value & 0x00000000'FF000000) >> 24);
- buffer[offset + 5] = std::byte((value & 0x00000000'00FF0000) >> 16);
- buffer[offset + 6] = std::byte((value & 0x00000000'0000FF00) >> 8);
- buffer[offset + 7] = std::byte(value & 0x00000000'000000FF);
-}
-
-/**
- * Write int64 to byte stream.
- *
- * @param value Value to write.
- * @param buffer Buffer.
- * @param offset Offset.
- * @return Value
- */
-inline void writeInt64(int64_t value, std::byte *buffer, size_t offset = 0) {
- return writeUint64(std::uint64_t(value), buffer, offset);
-}
-
-/**
- * Write uint32 to byte stream.
- *
- * @param value Value to write.
- * @param buffer Buffer.
- * @param offset Offset.
- * @return Value
- */
-inline void writeUint32(uint32_t value, std::byte *buffer, size_t offset = 0) {
- buffer[offset] = std::byte((value & 0xFF000000) >> 24);
- buffer[offset + 1] = std::byte((value & 0x00FF0000) >> 16);
- buffer[offset + 2] = std::byte((value & 0x0000FF00) >> 8);
- buffer[offset + 3] = std::byte(value & 0x000000FF);
-}
-
-/**
- * Write int32 to byte stream.
- *
- * @param value Value to write.
- * @param buffer Buffer.
- * @param offset Offset.
- * @return Value
- */
-inline void writeInt32(int32_t value, std::byte *buffer, size_t offset = 0) {
- return writeUint32(std::uint32_t(value), buffer, offset);
-}
-
-/**
- * Write uint16 to byte stream.
+ * Unpack number.
*
- * @param value Value to write.
- * @param buffer Buffer.
- * @param offset Offset.
- * @return Value
+ * @param object MsgPack object.
+ * @return Number.
+ * @throw ignite_error if the object is not a number.
*/
-inline void writeUint16(uint16_t value, std::byte *buffer, size_t offset = 0) {
- buffer[offset] = std::byte((value & 0xFF00) >> 8);
- buffer[offset + 1] = std::byte(value & 0x00FF);
-}
+template <>
+[[nodiscard]] std::int64_t unpack_object(const msgpack_object &object);
/**
- * Write int16 to byte stream.
+ * Unpack number.
*
- * @param value Value to write.
- * @param buffer Buffer.
- * @param offset Offset.
- * @return Value
+ * @param object MsgPack object.
+ * @return Number.
+ * @throw ignite_error if the object is not a number.
*/
-inline void writeInt16(int16_t value, std::byte *buffer, size_t offset = 0) {
- return writeUint16(std::uint16_t(value), buffer, offset);
-}
-
-template<typename T>
-T unpack_object(const msgpack_object&);
+template <>
+[[nodiscard]] std::int32_t unpack_object(const msgpack_object &object);
/**
* Unpack number.
@@ -204,8 +71,8 @@ T unpack_object(const msgpack_object&);
* @return Number.
* @throw ignite_error if the object is not a number.
*/
-template<>
-int64_t unpack_object(const msgpack_object& object);
+template <>
+[[nodiscard]] std::int16_t unpack_object(const msgpack_object &object);
/**
* Unpack string.
@@ -214,8 +81,8 @@ int64_t unpack_object(const msgpack_object& object);
* @return String.
* @throw ignite_error if the object is not a string.
*/
-template<>
-std::string unpack_object(const msgpack_object& object);
+template <>
+[[nodiscard]] std::string unpack_object(const msgpack_object &object);
/**
* Unpack UUID.
@@ -224,22 +91,22 @@ std::string unpack_object(const msgpack_object& object);
* @return UUID.
* @throw ignite_error if the object is not a UUID.
*/
-template<>
-uuid unpack_object(const msgpack_object& object);
+template <>
+[[nodiscard]] uuid unpack_object(const msgpack_object &object);
/**
* Make random UUID.
*
* @return Random UUID instance.
*/
-ignite::uuid makeRandomUuid();
+[[nodiscard]] ignite::uuid make_random_uuid();
/**
* Read error.
*
- * @param reader Reader.
- * @return Error.
+ * @param reader reader.
+ * @return Error if there is any.
*/
-std::optional<ignite_error> readError(protocol::Reader &reader);
+[[nodiscard]] std::optional<ignite_error> read_error(protocol::reader &reader);
} // namespace ignite::protocol
diff --git a/modules/platforms/cpp/protocol/include/ignite/protocol/writer.h b/modules/platforms/cpp/protocol/include/ignite/protocol/writer.h
index a79adfa60f..713bf33c04 100644
--- a/modules/platforms/cpp/protocol/include/ignite/protocol/writer.h
+++ b/modules/platforms/cpp/protocol/include/ignite/protocol/writer.h
@@ -17,49 +17,41 @@
#pragma once
+#include "common/types.h"
+#include "ignite/protocol/buffer_adapter.h"
+
+#include <msgpack.h>
+
#include <cstdint>
#include <functional>
#include <memory>
#include <string_view>
-#include <msgpack.h>
-
-#include "common/types.h"
-#include "ignite/protocol/buffer_adapter.h"
-
namespace ignite::protocol {
/**
* Writer.
*/
-class Writer {
+class writer {
public:
// Default
- ~Writer() = default;
+ ~writer() = default;
// Deleted
- Writer() = delete;
- Writer(Writer &&) = delete;
- Writer(const Writer &) = delete;
- Writer &operator=(Writer &&) = delete;
- Writer &operator=(const Writer &) = delete;
-
- /**
- * Write message to buffer.
- *
- * @param buffer Buffer to use.
- * @param script Function.
- */
- static void writeMessageToBuffer(BufferAdapter &buffer, const std::function<void(Writer &)> &script);
+ writer() = delete;
+ writer(writer &&) = delete;
+ writer(const writer &) = delete;
+ writer &operator=(writer &&) = delete;
+ writer &operator=(const writer &) = delete;
/**
* Constructor.
*
* @param buffer Buffer.
*/
- explicit Writer(BufferAdapter &buffer)
+ explicit writer(buffer_adapter &buffer)
: m_buffer(buffer)
- , m_packer(msgpack_packer_new(&m_buffer, writeCallback), msgpack_packer_free) {
+ , m_packer(msgpack_packer_new(&m_buffer, write_callback), msgpack_packer_free) {
assert(m_packer.get());
}
@@ -68,28 +60,28 @@ public:
*
* @param value Value to write.
*/
- void write(int8_t value) { msgpack_pack_int8(m_packer.get(), value); }
+ void write(std::int8_t value) { msgpack_pack_int8(m_packer.get(), value); }
/**
* Write int value.
*
* @param value Value to write.
*/
- void write(int16_t value) { msgpack_pack_int16(m_packer.get(), value); }
+ void write(std::int16_t value) { msgpack_pack_int16(m_packer.get(), value); }
/**
* Write int value.
*
* @param value Value to write.
*/
- void write(int32_t value) { msgpack_pack_int32(m_packer.get(), value); }
+ void write(std::int32_t value) { msgpack_pack_int32(m_packer.get(), value); }
/**
* Write int value.
*
* @param value Value to write.
*/
- void write(int64_t value) { msgpack_pack_int64(m_packer.get(), value); }
+ void write(std::int64_t value) { msgpack_pack_int64(m_packer.get(), value); }
/**
* Write string value.
@@ -101,12 +93,12 @@ public:
/**
* Write empty binary data.
*/
- void writeBinaryEmpty() { msgpack_pack_bin(m_packer.get(), 0); }
+ void write_binary_empty() { msgpack_pack_bin(m_packer.get(), 0); }
/**
* Write empty map.
*/
- void writeMapEmpty() { msgpack_pack_map(m_packer.get(), 0); }
+ void write_map_empty() { msgpack_pack_map(m_packer.get(), 0); }
private:
/**
@@ -117,13 +109,28 @@ private:
* @param len Data length.
* @return Write result.
*/
- static int writeCallback(void *data, const char *buf, size_t len);
+ static int write_callback(void *data, const char *buf, size_t len);
/** Buffer adapter. */
- BufferAdapter &m_buffer;
+ buffer_adapter &m_buffer;
/** Packer. */
std::unique_ptr<msgpack_packer, void (*)(msgpack_packer *)> m_packer;
};
+/**
+ * Write message to buffer.
+ *
+ * @param buffer Buffer to use.
+ * @param func Function.
+ */
+inline void write_message_to_buffer(buffer_adapter &buffer, const std::function<void(writer &)> &func) {
+ buffer.reserve_length_header();
+
+ protocol::writer writer(buffer);
+ func(writer);
+
+ buffer.write_length_header();
+}
+
} // namespace ignite::protocol
diff --git a/modules/platforms/cpp/protocol/src/buffer_adapter.cpp b/modules/platforms/cpp/protocol/src/buffer_adapter.cpp
index 852f1b721e..1be59a1f52 100644
--- a/modules/platforms/cpp/protocol/src/buffer_adapter.cpp
+++ b/modules/platforms/cpp/protocol/src/buffer_adapter.cpp
@@ -15,20 +15,21 @@
* limitations under the License.
*/
-#include "common/ignite_error.h"
-
#include "ignite/protocol/buffer_adapter.h"
+
+#include "common/bytes.h"
+#include "common/ignite_error.h"
#include "ignite/protocol/utils.h"
namespace ignite::protocol {
-void BufferAdapter::writeLengthHeader() {
- if (m_lengthPos == std::numeric_limits<std::size_t>::max() || m_lengthPos + LENGTH_HEADER_SIZE > m_buffer.size())
+void buffer_adapter::write_length_header() {
+ if (m_length_pos == std::numeric_limits<std::size_t>::max() || m_length_pos + LENGTH_HEADER_SIZE > m_buffer.size())
throw ignite_error("Length header was not reserved properly in buffer");
- auto length = std::int32_t(m_buffer.size() - (m_lengthPos + LENGTH_HEADER_SIZE));
+ auto length = std::int32_t(m_buffer.size() - (m_length_pos + LENGTH_HEADER_SIZE));
- writeInt32(length, m_buffer.data(), m_lengthPos);
+ bytes::store<Endian::LITTLE, int32_t>(m_buffer.data() + m_length_pos, length);
}
} // namespace ignite::protocol
diff --git a/modules/platforms/cpp/protocol/src/reader.cpp b/modules/platforms/cpp/protocol/src/reader.cpp
index 42431fadfa..85aa35bfd9 100644
--- a/modules/platforms/cpp/protocol/src/reader.cpp
+++ b/modules/platforms/cpp/protocol/src/reader.cpp
@@ -15,76 +15,41 @@
* limitations under the License.
*/
-#include "common/ignite_error.h"
-#include "common/bytes.h"
-
#include "ignite/protocol/reader.h"
+
+#include "common/bytes.h"
#include "ignite/protocol/utils.h"
namespace ignite::protocol {
-Reader::Reader(bytes_view buffer)
+reader::reader(bytes_view buffer)
: m_buffer(buffer)
, m_unpacker()
- , m_currentVal()
- , m_moveRes(MSGPACK_UNPACK_SUCCESS) {
+ , m_current_val()
+ , m_move_res(MSGPACK_UNPACK_SUCCESS) {
// TODO: Research if we can get rid of copying here.
msgpack_unpacker_init(&m_unpacker, MSGPACK_UNPACKER_INIT_BUFFER_SIZE);
msgpack_unpacker_reserve_buffer(&m_unpacker, m_buffer.size());
memcpy(msgpack_unpacker_buffer(&m_unpacker), m_buffer.data(), m_buffer.size());
msgpack_unpacker_buffer_consumed(&m_unpacker, m_buffer.size());
- msgpack_unpacked_init(&m_currentVal);
-
- next();
-}
-
-std::int64_t Reader::readInt64() {
- checkDataInStream();
-
- auto res = unpack_object<int64_t>(m_currentVal.data);
- next();
-
- return res;
-}
-
-std::string Reader::readString() {
- checkDataInStream();
+ msgpack_unpacked_init(&m_current_val);
- std::string res = unpack_object<std::string>(m_currentVal.data);
next();
-
- return res;
-}
-
-std::optional<std::string> Reader::readStringNullable() {
- if (tryReadNil())
- return std::nullopt;
-
- return readString();
-}
-
-uuid Reader::readUuid() {
- checkDataInStream();
-
- uuid res = unpack_object<uuid>(m_currentVal.data);
- next();
-
- return res;
}
-bool Reader::tryReadNil() {
- if (m_currentVal.data.type != MSGPACK_OBJECT_NIL)
+bool reader::try_read_nil() {
+ if (m_current_val.data.type != MSGPACK_OBJECT_NIL)
return false;
next();
return true;
}
-void Reader::next() {
- checkDataInStream();
+void reader::next() {
+ check_data_in_stream();
- m_moveRes = msgpack_unpacker_next(&m_unpacker, &m_currentVal);
+ m_move_res = msgpack_unpacker_next(&m_unpacker, &m_current_val);
}
} // namespace ignite::protocol
diff --git a/modules/platforms/cpp/protocol/src/utils.cpp b/modules/platforms/cpp/protocol/src/utils.cpp
index 7d9eccadfe..4d5de58b19 100644
--- a/modules/platforms/cpp/protocol/src/utils.cpp
+++ b/modules/platforms/cpp/protocol/src/utils.cpp
@@ -15,28 +15,57 @@
* limitations under the License.
*/
+#include "ignite/protocol/utils.h"
+#include "ignite/protocol/reader.h"
+
+#include <msgpack.h>
+
+#include <limits>
#include <mutex>
#include <random>
#include <sstream>
+#include <type_traits>
-#include <msgpack.h>
+namespace ignite::protocol {
-#include "ignite/protocol/reader.h"
-#include "ignite/protocol/utils.h"
+template <typename T>
+T unpack_int(const msgpack_object &object) {
+ static_assert(
+ std::numeric_limits<T>::is_integer && std::numeric_limits<T>::is_signed, "Type T is not a signed integer type");
-namespace ignite::protocol {
+ auto i64_val = unpack_object<std::int64_t>(object);
+
+ // TODO: maybe disable these checks on non-debug builds
+ if (i64_val > std::int64_t(std::numeric_limits<T>::max()))
+ throw ignite_error("The number in stream is too large to fit in type: " + std::to_string(i64_val));
+
+ if (i64_val < std::int64_t(std::numeric_limits<T>::min()))
+ throw ignite_error("The number in stream is too small to fit in type: " + std::to_string(i64_val));
+
+ return T(i64_val);
+}
-template<>
-int64_t unpack_object(const msgpack_object &object) {
+template <>
+std::int64_t unpack_object(const msgpack_object &object) {
if (object.type != MSGPACK_OBJECT_NEGATIVE_INTEGER && object.type != MSGPACK_OBJECT_POSITIVE_INTEGER)
throw ignite_error("The value in stream is not an integer number");
return object.via.i64;
}
-template<>
+template <>
+std::int32_t unpack_object(const msgpack_object &object) {
+ return unpack_int<std::int32_t>(object);
+}
+
+template <>
+std::int16_t unpack_object(const msgpack_object &object) {
+ return unpack_int<std::int16_t>(object);
+}
+
+template <>
uuid unpack_object(const msgpack_object &object) {
- if (object.type != MSGPACK_OBJECT_EXT && object.via.ext.type != std::int8_t(ExtensionTypes::UUID))
+ if (object.type != MSGPACK_OBJECT_EXT && object.via.ext.type != std::int8_t(extension_type::UUID))
throw ignite_error("The value in stream is not a UUID");
if (object.via.ext.size != 16)
@@ -50,7 +79,7 @@ uuid unpack_object(const msgpack_object &object) {
return {msb, lsb};
}
-template<>
+template <>
std::string unpack_object(const msgpack_object &object) {
if (object.type != MSGPACK_OBJECT_STR)
throw ignite_error("The value in stream is not a string");
@@ -58,7 +87,7 @@ std::string unpack_object(const msgpack_object &object) {
return {object.via.str.ptr, object.via.str.size};
}
-uuid makeRandomUuid() {
+uuid make_random_uuid() {
static std::mutex randomMutex;
static std::random_device rd;
static std::mt19937 gen(rd());
@@ -70,18 +99,18 @@ uuid makeRandomUuid() {
return {distrib(gen), distrib(gen)};
}
-std::optional<ignite_error> readError(Reader &reader) {
- if (reader.tryReadNil())
+std::optional<ignite_error> read_error(reader &reader) {
+ if (reader.try_read_nil())
return std::nullopt;
- uuid traceId = reader.tryReadNil() ? makeRandomUuid() : reader.readUuid();
- int32_t code = reader.tryReadNil() ? 65537 : reader.readInt32();
- std::string className = reader.readString();
- std::string message = reader.readString();
+ auto trace_id = reader.try_read_nil() ? make_random_uuid() : reader.read_uuid();
+ auto code = reader.read_object_or_default<std::int32_t>(65537);
+ auto class_name = reader.read_string();
+ auto message = reader.read_string();
std::stringstream errMsgBuilder;
- errMsgBuilder << className << ": " << message << " (" << code << ", " << traceId << ")";
+ errMsgBuilder << class_name << ": " << message << " (" << code << ", " << trace_id << ")";
return {ignite_error(status_code(code), errMsgBuilder.str())};
}
diff --git a/modules/platforms/cpp/protocol/src/writer.cpp b/modules/platforms/cpp/protocol/src/writer.cpp
index f6323d0ebd..f006d588fb 100644
--- a/modules/platforms/cpp/protocol/src/writer.cpp
+++ b/modules/platforms/cpp/protocol/src/writer.cpp
@@ -19,27 +19,18 @@
namespace ignite::protocol {
-void Writer::writeMessageToBuffer(BufferAdapter &buffer, const std::function<void(Writer &)> &script) {
- buffer.reserveLengthHeader();
-
- protocol::Writer writer(buffer);
- script(writer);
-
- buffer.writeLengthHeader();
-}
-
-int Writer::writeCallback(void *data, const char *buf, size_t len) {
+int writer::write_callback(void *data, const char *buf, size_t len) {
if (!data)
return 0;
- auto buffer = static_cast<BufferAdapter *>(data);
+ auto buffer = static_cast<buffer_adapter *>(data);
// We do not support messages larger than MAX_INT32
- if (buffer->getData().size() + len > std::numeric_limits<int32_t>::max())
+ if (buffer->data().size() + len > std::numeric_limits<int32_t>::max())
return -1;
auto bytes = reinterpret_cast<const std::byte *>(buf);
- buffer->writeRawData(bytes_view{bytes, len});
+ buffer->write_raw(bytes_view{bytes, len});
return 0;
}
diff --git a/modules/platforms/cpp/schema/binary_tuple_builder.h b/modules/platforms/cpp/schema/binary_tuple_builder.h
index 8ffda6c644..c72f22e143 100644
--- a/modules/platforms/cpp/schema/binary_tuple_builder.h
+++ b/modules/platforms/cpp/schema/binary_tuple_builder.h
@@ -322,9 +322,7 @@ private:
* @param value Actual element value.
* @return Required size.
*/
- static SizeT gauge_number(const big_integer &value) noexcept {
- return value.is_zero() ? 0 : value.byte_size();
- }
+ static SizeT gauge_number(const big_integer &value) noexcept { return value.is_zero() ? 0 : value.byte_size(); }
/**
* @brief Computes required binary size for a given value.
@@ -342,9 +340,7 @@ private:
* @param value Actual element value.
* @return Required size.
*/
- static SizeT gauge_uuid(const uuid &value) noexcept {
- return value == uuid() ? 0 : 16;
- }
+ static SizeT gauge_uuid(const uuid &value) noexcept { return value == uuid() ? 0 : 16; }
/**
* @brief Computes required binary size for a given value.
@@ -352,9 +348,7 @@ private:
* @param value Actual element value.
* @return Required size.
*/
- static SizeT gauge_date(const ignite_date &value) noexcept {
- return value == ignite_date() ? 0 : 3;
- }
+ static SizeT gauge_date(const ignite_date &value) noexcept { return value == ignite_date() ? 0 : 3; }
/**
* @brief Computes required binary size for a given value.
diff --git a/modules/platforms/cpp/schema/binary_tuple_parser.cpp b/modules/platforms/cpp/schema/binary_tuple_parser.cpp
index 9e329702a1..21829aa5b0 100644
--- a/modules/platforms/cpp/schema/binary_tuple_parser.cpp
+++ b/modules/platforms/cpp/schema/binary_tuple_parser.cpp
@@ -18,7 +18,6 @@
#include "binary_tuple_parser.h"
#include "../common/bytes.h"
-#include "../common/platform.h"
#include <cassert>
#include <cstring>
@@ -29,13 +28,13 @@ namespace ignite {
namespace {
template <typename T>
-T loadBytesAs(bytes_view bytes, std::size_t offset = 0) noexcept {
+T load_as(bytes_view bytes, std::size_t offset = 0) noexcept {
return bytes::load<Endian::LITTLE, T>(bytes.data() + offset);
}
-ignite_date loadBytesAsDate(bytes_view bytes) {
- std::int32_t date = loadBytesAs<std::uint16_t>(bytes);
- date |= std::int32_t(loadBytesAs<std::int8_t>(bytes, 2)) << 16;
+ignite_date load_date(bytes_view bytes) {
+ std::int32_t date = load_as<std::uint16_t>(bytes);
+ date |= std::int32_t(load_as<std::int8_t>(bytes, 2)) << 16;
std::int32_t day = date & 31;
std::int32_t month = (date >> 5) & 15;
@@ -44,32 +43,32 @@ ignite_date loadBytesAsDate(bytes_view bytes) {
return {year, month, day};
}
-ignite_time loadBytesAsTime(bytes_view bytes) {
- std::uint64_t time = loadBytesAs<std::uint32_t>(bytes);
+ignite_time load_time(bytes_view bytes) {
+ std::uint64_t time = load_as<std::uint32_t>(bytes);
- std::uint32_t nano;
+ std::int32_t nano;
switch (bytes.size()) {
case 4:
- nano = ((int)time & ((1 << 10) - 1)) * 1000 * 1000;
+ nano = ((std::int32_t)time & ((1 << 10) - 1)) * 1000 * 1000;
time >>= 10;
break;
case 5:
- time |= std::uint64_t(loadBytesAs<std::uint8_t>(bytes, 4)) << 32;
- nano = ((int)time & ((1 << 20) - 1)) * 1000;
+ time |= std::uint64_t(load_as<std::uint8_t>(bytes, 4)) << 32;
+ nano = ((std::int32_t)time & ((1 << 20) - 1)) * 1000;
time >>= 20;
break;
case 6:
- time |= std::uint64_t(loadBytesAs<std::uint16_t>(bytes, 4)) << 32;
- nano = ((int)time & ((1 << 30) - 1));
+ time |= std::uint64_t(load_as<std::uint16_t>(bytes, 4)) << 32;
+ nano = ((std::int32_t)time & ((1 << 30) - 1));
time >>= 30;
break;
}
- std::uint32_t second = ((int)time) & 63;
- std::uint32_t minute = ((int)time >> 6) & 63;
- std::uint32_t hour = ((int)time >> 12) & 31;
+ std::int_fast8_t second = ((int)time) & 63;
+ std::int_fast8_t minute = ((int)time >> 6) & 63;
+ std::int_fast8_t hour = ((int)time >> 12) & 31;
- return {int(hour), int(minute), int(second), int(nano)};
+ return {hour, minute, second, nano};
}
} // namespace
@@ -79,6 +78,7 @@ binary_tuple_parser::binary_tuple_parser(IntT num_elements, bytes_view data)
, element_count(num_elements)
, element_index(0)
, has_nullmap(false) {
+ assert(!data.empty());
binary_tuple_header header;
header.flags = binary_tuple[0];
@@ -86,25 +86,31 @@ binary_tuple_parser::binary_tuple_parser(IntT num_elements, bytes_view data)
entry_size = header.get_entry_size();
has_nullmap = header.get_nullmap_flag();
- size_t nullmapSize = 0;
+ SizeT nullmap_size = 0;
if (has_nullmap) {
- nullmapSize = binary_tuple_schema::get_nullmap_size(element_count);
+ nullmap_size = binary_tuple_schema::get_nullmap_size(element_count);
}
- size_t tableSize = entry_size * element_count;
- next_entry = binary_tuple.data() + binary_tuple_header::SIZE + nullmapSize;
- value_base = next_entry + tableSize;
+ SizeT table_size = entry_size * element_count;
+ next_entry = binary_tuple.data() + binary_tuple_header::SIZE + nullmap_size;
+ value_base = next_entry + table_size;
+ if (value_base > binary_tuple.end()) {
+ throw std::out_of_range("Too short byte buffer");
+ }
next_value = value_base;
+ // Load the tuple end offset (little-endian).
+ std::uint64_t le_end_offset = 0;
+ memcpy(&le_end_offset, value_base - entry_size, entry_size);
+
// Fix tuple size if needed.
- uint64_t offset = 0;
- static_assert(platform::ByteOrder::littleEndian);
- memcpy(&offset, next_entry + tableSize - entry_size, entry_size);
- const std::byte *tupleEnd = value_base + offset;
- const std::byte *currentEnd = &(*binary_tuple.end());
- if (currentEnd > tupleEnd) {
- binary_tuple.remove_suffix(currentEnd - tupleEnd);
+ const std::byte *tuple_end = value_base + bytes::ltoh(le_end_offset);
+ const std::byte *given_end = &(*binary_tuple.end());
+ if (given_end > tuple_end) {
+ binary_tuple.remove_suffix(given_end - tuple_end);
+ } else if (given_end < tuple_end) {
+ throw std::out_of_range("Too short byte buffer");
}
}
@@ -113,13 +119,13 @@ element_view binary_tuple_parser::get_next() {
++element_index;
- uint64_t offset = 0;
- static_assert(platform::ByteOrder::littleEndian);
- memcpy(&offset, next_entry, entry_size);
+ // Load next entry offset (little-endian).
+ std::uint64_t le_offset = 0;
+ memcpy(&le_offset, next_entry, entry_size);
next_entry += entry_size;
const std::byte *value = next_value;
- next_value = value_base + offset;
+ next_value = value_base + bytes::ltoh(le_offset);
const size_t length = next_value - value;
if (length == 0 && has_nullmap && binary_tuple_schema::has_null(binary_tuple, element_index - 1)) {
@@ -166,7 +172,7 @@ std::int8_t binary_tuple_parser::get_int8(bytes_view bytes) {
case 0:
return 0;
case 1:
- return loadBytesAs<std::int8_t>(bytes);
+ return load_as<std::int8_t>(bytes);
default:
throw std::out_of_range("Bad element size");
}
@@ -177,9 +183,9 @@ std::int16_t binary_tuple_parser::get_int16(bytes_view bytes) {
case 0:
return 0;
case 1:
- return loadBytesAs<std::int8_t>(bytes);
+ return load_as<std::int8_t>(bytes);
case 2:
- return loadBytesAs<std::int16_t>(bytes);
+ return load_as<std::int16_t>(bytes);
default:
throw std::out_of_range("Bad element size");
}
@@ -190,11 +196,11 @@ std::int32_t binary_tuple_parser::get_int32(bytes_view bytes) {
case 0:
return 0;
case 1:
- return loadBytesAs<std::int8_t>(bytes);
+ return load_as<std::int8_t>(bytes);
case 2:
- return loadBytesAs<std::int16_t>(bytes);
+ return load_as<std::int16_t>(bytes);
case 4:
- return loadBytesAs<std::int32_t>(bytes);
+ return load_as<std::int32_t>(bytes);
default:
throw std::out_of_range("Bad element size");
}
@@ -205,13 +211,13 @@ std::int64_t binary_tuple_parser::get_int64(bytes_view bytes) {
case 0:
return 0;
case 1:
- return loadBytesAs<std::int8_t>(bytes);
+ return load_as<std::int8_t>(bytes);
case 2:
- return loadBytesAs<std::int16_t>(bytes);
+ return load_as<std::int16_t>(bytes);
case 4:
- return loadBytesAs<std::int32_t>(bytes);
+ return load_as<std::int32_t>(bytes);
case 8:
- return loadBytesAs<std::int64_t>(bytes);
+ return load_as<std::int64_t>(bytes);
default:
throw std::out_of_range("Bad element size");
}
@@ -222,7 +228,7 @@ float binary_tuple_parser::get_float(bytes_view bytes) {
case 0:
return 0.0f;
case 4:
- return loadBytesAs<float>(bytes);
+ return load_as<float>(bytes);
default:
throw std::out_of_range("Bad element size");
}
@@ -233,9 +239,9 @@ double binary_tuple_parser::get_double(bytes_view bytes) {
case 0:
return 0.0f;
case 4:
- return loadBytesAs<float>(bytes);
+ return load_as<float>(bytes);
case 8:
- return loadBytesAs<double>(bytes);
+ return load_as<double>(bytes);
default:
throw std::out_of_range("Bad element size");
}
@@ -250,7 +256,7 @@ uuid binary_tuple_parser::get_uuid(bytes_view bytes) {
case 0:
return uuid();
case 16:
- return uuid(loadBytesAs<std::int64_t>(bytes), loadBytesAs<std::int64_t>(bytes, 8));
+ return uuid(load_as<std::int64_t>(bytes), load_as<std::int64_t>(bytes, 8));
default:
throw std::out_of_range("Bad element size");
}
@@ -261,7 +267,7 @@ ignite_date binary_tuple_parser::get_date(bytes_view bytes) {
case 0:
return ignite_date();
case 3:
- return loadBytesAsDate(bytes);
+ return load_date(bytes);
default:
throw std::out_of_range("Bad element size");
}
@@ -274,7 +280,7 @@ ignite_time binary_tuple_parser::get_time(bytes_view bytes) {
case 4:
case 5:
case 6:
- return loadBytesAsTime(bytes);
+ return load_time(bytes);
default:
throw std::out_of_range("Bad element size");
}
@@ -287,7 +293,7 @@ ignite_date_time binary_tuple_parser::get_date_time(bytes_view bytes) {
case 7:
case 8:
case 9:
- return ignite_date_time(loadBytesAsDate(bytes), loadBytesAsTime(bytes.substr(3)));
+ return ignite_date_time(load_date(bytes), load_time(bytes.substr(3)));
default:
throw std::out_of_range("Bad element size");
}
@@ -298,12 +304,12 @@ ignite_timestamp binary_tuple_parser::get_timestamp(bytes_view bytes) {
case 0:
return ignite_timestamp();
case 8: {
- std::int64_t seconds = loadBytesAs<std::int64_t>(bytes);
+ std::int64_t seconds = load_as<std::int64_t>(bytes);
return ignite_timestamp(seconds, 0);
}
case 12: {
- std::int64_t seconds = loadBytesAs<std::int64_t>(bytes);
- std::int32_t nanos = loadBytesAs<std::int32_t>(bytes);
+ std::int64_t seconds = load_as<std::int64_t>(bytes);
+ std::int32_t nanos = load_as<std::int32_t>(bytes);
return ignite_timestamp(seconds, nanos);
}
default:
diff --git a/modules/platforms/cpp/schema/ignite_time.h b/modules/platforms/cpp/schema/ignite_time.h
index 201b588565..e82a3fab75 100644
--- a/modules/platforms/cpp/schema/ignite_time.h
+++ b/modules/platforms/cpp/schema/ignite_time.h
@@ -41,7 +41,8 @@ public:
* @param second Second-of-minute, from 0 to 59.
* @param nano Nano-of-second, from 0 to 999,999,999.
*/
- constexpr ignite_time(int hour, int minute, int second = 0, int nano = 0)
+ constexpr ignite_time(
+ std::int_fast8_t hour, std::int_fast8_t minute, std::int_fast8_t second = 0, std::int32_t nano = 0)
: hour(hour)
, minute(minute)
, second(second)
@@ -52,22 +53,22 @@ public:
/**
* Gets the hour-of-day field.
*/
- constexpr int get_hour() const noexcept { return hour; }
+ constexpr auto get_hour() const noexcept { return hour; }
/**
* Gets the minute-of-hour field.
*/
- constexpr int get_minute() const noexcept { return minute; }
+ constexpr auto get_minute() const noexcept { return minute; }
/**
* Gets the second-of-minute field.
*/
- constexpr int get_second() const noexcept { return second; }
+ constexpr auto get_second() const noexcept { return second; }
/**
* Gets the nano-of-second field.
*/
- constexpr int get_nano() const noexcept { return nano; }
+ constexpr std::int32_t get_nano() const noexcept { return nano; }
/**
* Compare to another value.