add write id

This commit is contained in:
2025-02-07 21:10:06 +01:00
parent 032800b220
commit 6725a63c07
4 changed files with 38 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ class PacketHandler;
using PacketMessage = Message<option::MsgIdType<std::uint8_t>, // add id() operation using PacketMessage = Message<option::MsgIdType<std::uint8_t>, // add id() operation
option::ReadOperations, // add read() operation option::ReadOperations, // add read() operation
option::WriteOperations, // add write() operation option::WriteOperations, // add write() operation
option::WriteId, // write id before data
option::Handler<PacketHandler> // add dispatch() operation option::Handler<PacketHandler> // add dispatch() operation
>; >;

View File

@@ -30,8 +30,11 @@ struct MessageInterfaceBuilder {
// add valid functionality if Valid tpe was provided // add valid functionality if Valid tpe was provided
using Base6 = typename MessageInterfaceProcessValid<Base5, ParsedOptions::HasValid>::Type; using Base6 = typename MessageInterfaceProcessValid<Base5, ParsedOptions::HasValid>::Type;
// add write id functionality if write id and write was provided
using Base7 = typename MessageInterfaceProcessWriteId<Base6, ParsedOptions::HasWriteId && ParsedOptions::HasWriteOperations>::Type;
// The last Base6 must be taken as final type. // The last Base6 must be taken as final type.
using Type = Base6; using Type = Base7;
}; };
} // namespace details } // namespace details

View File

@@ -14,6 +14,7 @@ struct MessageInterfaceParsedOptions<> {
static const bool HasLittleEndian = false; static const bool HasLittleEndian = false;
static const bool HasReadOperations = false; static const bool HasReadOperations = false;
static const bool HasWriteOperations = false; static const bool HasWriteOperations = false;
static const bool HasWriteId = false;
static const bool HasHandler = false; static const bool HasHandler = false;
static const bool HasValid = false; static const bool HasValid = false;
}; };
@@ -43,6 +44,11 @@ struct MessageInterfaceParsedOptions<option::WriteOperations, TOptions...> : pub
static const bool HasWriteOperations = true; static const bool HasWriteOperations = true;
}; };
template <typename... TOptions>
struct MessageInterfaceParsedOptions<option::WriteId, TOptions...> : public MessageInterfaceParsedOptions<TOptions...> {
static const bool HasWriteId = true;
};
template <typename T, typename... TOptions> template <typename T, typename... TOptions>
struct MessageInterfaceParsedOptions<option::Handler<T>, TOptions...> : public MessageInterfaceParsedOptions<TOptions...> { struct MessageInterfaceParsedOptions<option::Handler<T>, TOptions...> : public MessageInterfaceParsedOptions<TOptions...> {
static const bool HasHandler = true; static const bool HasHandler = true;
@@ -118,7 +124,7 @@ template <typename TBase>
class MessageInterfaceWriteBase : public TBase { class MessageInterfaceWriteBase : public TBase {
public: public:
void Write(DataBuffer& buffer) { void Write(DataBuffer& buffer) {
return WriteImpl(buffer); WriteImpl(buffer);
} }
protected: protected:
@@ -151,7 +157,15 @@ class MessageInterfaceValidityBase : public TBase {
virtual bool ValidImpl() const = 0; virtual bool ValidImpl() const = 0;
}; };
// Writing id functionality chunk
template <typename TBase>
class MessageInterfaceWriteIdBase : public TBase {
public:
void Write(DataBuffer& buffer) {
this->WriteData(this->GetId(), buffer);
this->WriteImpl(buffer);
}
};
@@ -239,5 +253,19 @@ template <typename TBase>
struct MessageInterfaceProcessValid<TBase, false> { struct MessageInterfaceProcessValid<TBase, false> {
using Type = TBase; using Type = TBase;
}; };
// Build id writing
template <typename TBase, bool THasValid>
struct MessageInterfaceProcessWriteId;
template <typename TBase>
struct MessageInterfaceProcessWriteId<TBase, true> {
using Type = MessageInterfaceWriteIdBase<TBase>;
};
template <typename TBase>
struct MessageInterfaceProcessWriteId<TBase, false> {
using Type = TBase;
};
} // namespace details } // namespace details
} // namespace sp } // namespace sp

View File

@@ -15,6 +15,9 @@ struct ReadOperations {};
// Enable writing // Enable writing
struct WriteOperations {}; struct WriteOperations {};
// Enable id writing
struct WriteId {};
// Use little endian for serialisation (instead of default big) // Use little endian for serialisation (instead of default big)
struct LittleEndian {}; struct LittleEndian {};