add write id
This commit is contained in:
@@ -9,6 +9,7 @@ class PacketHandler;
|
||||
using PacketMessage = Message<option::MsgIdType<std::uint8_t>, // add id() operation
|
||||
option::ReadOperations, // add read() operation
|
||||
option::WriteOperations, // add write() operation
|
||||
option::WriteId, // write id before data
|
||||
option::Handler<PacketHandler> // add dispatch() operation
|
||||
>;
|
||||
|
||||
|
||||
@@ -30,8 +30,11 @@ struct MessageInterfaceBuilder {
|
||||
// add valid functionality if Valid tpe was provided
|
||||
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.
|
||||
using Type = Base6;
|
||||
using Type = Base7;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
@@ -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<option::WriteOperations, TOptions...> : pub
|
||||
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>
|
||||
struct MessageInterfaceParsedOptions<option::Handler<T>, TOptions...> : public MessageInterfaceParsedOptions<TOptions...> {
|
||||
static const bool HasHandler = true;
|
||||
@@ -118,7 +124,7 @@ template <typename TBase>
|
||||
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 <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> {
|
||||
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 sp
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user