diff --git a/include/sp/default/DefaultPacket.h b/include/sp/default/DefaultPacket.h index 048b0e5..43a0770 100644 --- a/include/sp/default/DefaultPacket.h +++ b/include/sp/default/DefaultPacket.h @@ -9,6 +9,7 @@ class PacketHandler; using PacketMessage = Message, // add id() operation option::ReadOperations, // add read() operation option::WriteOperations, // add write() operation + option::WriteId, // write id before data option::Handler // add dispatch() operation >; diff --git a/include/sp/protocol/MessageInterfaceBuilder.h b/include/sp/protocol/MessageInterfaceBuilder.h index e2b4462..4fb0b71 100644 --- a/include/sp/protocol/MessageInterfaceBuilder.h +++ b/include/sp/protocol/MessageInterfaceBuilder.h @@ -30,8 +30,11 @@ struct MessageInterfaceBuilder { // add valid functionality if Valid tpe was provided using Base6 = typename MessageInterfaceProcessValid::Type; + // add write id functionality if write id and write was provided + using Base7 = typename MessageInterfaceProcessWriteId::Type; + // The last Base6 must be taken as final type. - using Type = Base6; + using Type = Base7; }; } // namespace details diff --git a/include/sp/protocol/MessageInterfaces.h b/include/sp/protocol/MessageInterfaces.h index 6ba36b1..275994a 100644 --- a/include/sp/protocol/MessageInterfaces.h +++ b/include/sp/protocol/MessageInterfaces.h @@ -14,6 +14,7 @@ struct MessageInterfaceParsedOptions<> { static const bool HasLittleEndian = false; static const bool HasReadOperations = false; static const bool HasWriteOperations = false; + static const bool HasWriteId = false; static const bool HasHandler = false; static const bool HasValid = false; }; @@ -43,6 +44,11 @@ struct MessageInterfaceParsedOptions : pub static const bool HasWriteOperations = true; }; +template +struct MessageInterfaceParsedOptions : public MessageInterfaceParsedOptions { + static const bool HasWriteId = true; +}; + template struct MessageInterfaceParsedOptions, TOptions...> : public MessageInterfaceParsedOptions { static const bool HasHandler = true; @@ -118,7 +124,7 @@ template class MessageInterfaceWriteBase : public TBase { public: void Write(DataBuffer& buffer) { - return WriteImpl(buffer); + WriteImpl(buffer); } protected: @@ -151,7 +157,15 @@ class MessageInterfaceValidityBase : public TBase { virtual bool ValidImpl() const = 0; }; - +// Writing id functionality chunk +template +class MessageInterfaceWriteIdBase : public TBase { + public: + void Write(DataBuffer& buffer) { + this->WriteData(this->GetId(), buffer); + this->WriteImpl(buffer); + } +}; @@ -239,5 +253,19 @@ template struct MessageInterfaceProcessValid { using Type = TBase; }; + +// Build id writing +template +struct MessageInterfaceProcessWriteId; + +template +struct MessageInterfaceProcessWriteId { + using Type = MessageInterfaceWriteIdBase; +}; + +template +struct MessageInterfaceProcessWriteId { + using Type = TBase; +}; } // namespace details } // namespace sp diff --git a/include/sp/protocol/Options.h b/include/sp/protocol/Options.h index bc1d1ae..ff784cb 100644 --- a/include/sp/protocol/Options.h +++ b/include/sp/protocol/Options.h @@ -15,6 +15,9 @@ struct ReadOperations {}; // Enable writing struct WriteOperations {}; +// Enable id writing +struct WriteId {}; + // Use little endian for serialisation (instead of default big) struct LittleEndian {};