diff --git a/tftp_common/details/parsers.hpp b/tftp_common/details/parsers.hpp index a7cf534..cdf0b04 100644 --- a/tftp_common/details/parsers.hpp +++ b/tftp_common/details/parsers.hpp @@ -7,34 +7,26 @@ namespace tftp_common::packets { /// The result of parsing a single packet -template -struct ParseResult { +template struct ParseResult { T Packet; std::size_t BytesRead; }; /// Return type of `parse` functions -template -struct ParseReturn : public std::variant, std::nullopt_t> { +template struct ParseReturn : public std::variant, std::nullopt_t> { using base = std::variant, std::nullopt_t>; using base::base; - ParseResult get() const noexcept { - return std::get>(*this); - } + ParseResult get() const noexcept { return std::get>(*this); } - bool isSuccess() const noexcept { - return !std::holds_alternative(*this); - } + bool isSuccess() const noexcept { return !std::holds_alternative(*this); } }; -template -struct Parser { +template struct Parser { using PacketType = T; }; -template <> -struct Parser { +template <> struct Parser { /// Parse read/write request packet from buffer converting all fields to host byte order /// @param[Buffer] Assumptions: \p Buffer is not a nullptr, it's size is greater or equal than \p Len /// @param[Len] Assumptions: \p Len is greater than zero @@ -84,7 +76,8 @@ struct Parser { case 3: if (Byte == 0u) { if (Idx == Len - 1) { - return ParseResult{Request{(types::Type) Type_, std::move(Filename), std::move(Mode)}, BytesRead}; + return ParseResult{Request{(types::Type)Type_, std::move(Filename), std::move(Mode)}, + BytesRead}; } Step++; } else { @@ -106,7 +99,9 @@ struct Parser { OptionsValues.push_back(std::move(Value)); if (Idx == Len - 1) { - return ParseResult{Request{(types::Type) Type_, std::move(Filename), std::move(Mode), std::move(OptionsNames), std::move(OptionsValues)}, BytesRead}; + return ParseResult{Request{(types::Type)Type_, std::move(Filename), std::move(Mode), + std::move(OptionsNames), std::move(OptionsValues)}, + BytesRead}; } Step--; } else { @@ -121,8 +116,7 @@ struct Parser { } }; -template <> -struct Parser { +template <> struct Parser { /// Parse data packet from buffer converting all fields to host byte order /// @param[Buffer] Assumptions: \p Buffer is not a nullptr, it's size is greater or equal than \p Len /// @param[Len] Assumptions: \p Len is greater than zero @@ -135,7 +129,6 @@ struct Parser { std::uint16_t Block; std::vector DataBuffer; - std::size_t Step = 0; std::size_t BytesRead = 0; for (std::size_t Idx = 0; Idx != Len; ++Idx) { @@ -184,8 +177,7 @@ struct Parser { } }; -template <> -struct Parser { +template <> struct Parser { /// Parse acknowledgment packet from buffer converting all fields to host byte order /// @param[Buffer] Assumptions: \p Buffer is not a nullptr, it's size is greater or equal than \p Len /// @param[Len] Assumptions: \p Len is greater than zero @@ -235,8 +227,7 @@ struct Parser { } }; -template <> -struct Parser { +template <> struct Parser { /// Parse error packet from buffer converting all fields to host byte order /// @param[Buffer] Assumptions: \p Buffer is not a nullptr, it's size is greater or equal than \p Len /// @param[Len] Assumptions: \p Len is greater than zero @@ -296,8 +287,7 @@ struct Parser { } }; -template <> -struct Parser { +template <> struct Parser { /// Parse error packet from buffer converting all fields to host byte order /// @param[Buffer] Assumptions: \p Buffer is not a nullptr, it's size is greater or equal than \p Len