diff --git a/include/sp/common/ByteSwapping.h b/include/sp/common/ByteSwapping.h index 5eb2e5a..f8754c7 100644 --- a/include/sp/common/ByteSwapping.h +++ b/include/sp/common/ByteSwapping.h @@ -16,7 +16,7 @@ void SwapBytes(T& value) { std::reverse(ptr, ptr + sizeof(T)); } -bool IsSystemBigEndian() { +static bool IsSystemBigEndian() { static constexpr std::uint16_t test = 10; static const bool isBigEndian = reinterpret_cast(&test)[1] == 10; return isBigEndian; diff --git a/include/sp/protocol/message/MessageInterfacesImpl.h b/include/sp/protocol/message/MessageInterfacesImpl.h index 9ccf3f9..5f464a8 100644 --- a/include/sp/protocol/message/MessageInterfacesImpl.h +++ b/include/sp/protocol/message/MessageInterfacesImpl.h @@ -30,7 +30,7 @@ class MessageInterfaceBigEndian : public TBase { } template - void WriteData(T value, DataBuffer& buffer) { + void WriteData(T value, DataBuffer& buffer) const { ToNetwork(value); buffer << value; } @@ -71,12 +71,12 @@ class MessageInterfaceReadBase : public TBase { template class MessageInterfaceWriteBase : public TBase { public: - void Write(DataBuffer& buffer) { + void Write(DataBuffer& buffer) const { WriteImpl(buffer); } protected: - virtual void WriteImpl(DataBuffer& buffer) = 0; + virtual void WriteImpl(DataBuffer& buffer) const = 0; }; // Handler functionality chunk @@ -85,12 +85,12 @@ class MessageInterfaceHandlerBase : public TBase { public: using HandlerType = typename THandler::HandlerT; - void Dispatch(HandlerType& handler) { + void Dispatch(HandlerType& handler) const { DispatchImpl(handler); } protected: - virtual void DispatchImpl(HandlerType& handler) = 0; + virtual void DispatchImpl(HandlerType& handler) const = 0; }; // Validity functionality chunk @@ -109,7 +109,7 @@ class MessageInterfaceValidityBase : public TBase { template class MessageInterfaceWriteIdBase : public TBase { public: - void Write(DataBuffer& buffer) { + void Write(DataBuffer& buffer) const { this->WriteData(this->GetId(), buffer); this->WriteImpl(buffer); } diff --git a/include/sp/protocol/message/MessagesImpl.h b/include/sp/protocol/message/MessagesImpl.h index 00a5b45..fd4838a 100644 --- a/include/sp/protocol/message/MessagesImpl.h +++ b/include/sp/protocol/message/MessagesImpl.h @@ -26,8 +26,8 @@ class MessageImplDispatchBase : public TBase { using Handler = typename TBase::HandlerType; protected: - virtual void DispatchImpl(Handler& handler) override { - handler.Handle(static_cast(*this)); + virtual void DispatchImpl(Handler& handler) const override { + handler.Handle(static_cast(*this)); } }; @@ -113,13 +113,13 @@ class MessageImplFieldsWriteBase : public TBase { private: // normal writing template - void WriteField(Field& field, DataBuffer& buffer) { + void WriteField(const Field& field, DataBuffer& buffer) const { this->WriteData(field.GetValue(), buffer); } // writing field in bitfield template - void WriteField(Field& field, TFieldType& data, std::size_t offset) { + void WriteField(const Field& field, TFieldType& data, std::size_t offset) const { static constexpr std::size_t TotalBitCount = sizeof(TFieldType) * 8; // we suppose that the first element is at the highest bits data |= (field.GetValue() & ((1 << IAlignment) - 1)) << TotalBitCount - IAlignment - offset; @@ -127,7 +127,7 @@ class MessageImplFieldsWriteBase : public TBase { // writing bitfield template - void WriteField(Field, 0>& field, DataBuffer& buffer) { + void WriteField(const Field, 0>& field, DataBuffer& buffer) const { TContainer data = 0; std::size_t offset = 0; TupleForEach( @@ -139,9 +139,9 @@ class MessageImplFieldsWriteBase : public TBase { this->WriteData(data, buffer); } - void WriteImpl(DataBuffer& buffer) override { + void WriteImpl(DataBuffer& buffer) const override { auto& allFields = this->GetFields(); - TupleForEach([&buffer, this](auto& field) { this->WriteField(field, buffer); }, allFields); + TupleForEach([&buffer, this](const auto& field) { this->WriteField(field, buffer); }, allFields); } };