Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
eoan-ermine committed Jun 14, 2023
1 parent a16d1c9 commit b209913
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
6 changes: 2 additions & 4 deletions tests/packets_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ TEST(Error, Serialization) {
/// order
TEST(OptionAcknowledgment, Serialization) {
std::unordered_map<std::string, std::string> Options = {
{"saveFiles", "true"}, {"discardQualifiers", "false"},
{"secret", "Ix0e86yG8YpFzwz1gS0XxJW3"}
};
{"saveFiles", "true"}, {"discardQualifiers", "false"}, {"secret", "Ix0e86yG8YpFzwz1gS0XxJW3"}};
auto Packet = OptionAcknowledgment{Options};

std::size_t OptionsSize = 0;
Expand All @@ -171,7 +169,7 @@ TEST(OptionAcknowledgment, Serialization) {

std::size_t BaseOffset = sizeof(std::uint16_t);
// option names and values
for (const auto& [Key, Value]: Options) {
for (const auto &[Key, Value] : Options) {
EXPECT_STRING(Buffer, BaseOffset, Key);
BaseOffset += Key.size() + 1;
EXPECT_STRING(Buffer, BaseOffset, Value);
Expand Down
6 changes: 2 additions & 4 deletions tests/parse_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,8 @@ TEST(OptionAcknowledgment, Parse) {
ASSERT_EQ(Packet.getType(), Type::OptionAcknowledgmentPacket);

std::unordered_map<std::string, std::string> Options = {
{"saveFiles", "true"}, {"discardQualifiers", "false"},
{"secret", "Ix0e86yG8YpFzwz1gS0XxJW3"}
};
for (const auto& [Key, Value]: Options) {
{"saveFiles", "true"}, {"discardQualifiers", "false"}, {"secret", "Ix0e86yG8YpFzwz1gS0XxJW3"}};
for (const auto &[Key, Value] : Options) {
ASSERT_EQ(Packet.getOptionValue(Key), Value);
}

Expand Down
17 changes: 6 additions & 11 deletions tftp_common/packets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>
#include <unordered_map>
#include <vector>

namespace tftp_common::packets {

Expand Down Expand Up @@ -255,8 +255,7 @@ class OptionAcknowledgment {
public:
/// Use with parsing functions only
OptionAcknowledgment() = default;
OptionAcknowledgment(std::unordered_map<std::string, std::string> Options)
: Options(std::move(Options)) { }
OptionAcknowledgment(std::unordered_map<std::string, std::string> Options) : Options(std::move(Options)) {}

/// Convert packet to network byte order and serialize it into the given buffer by the iterator
/// @param[It] Requirements: \p *(It) must be assignable from \p std::uint8_t
Expand All @@ -266,8 +265,8 @@ class OptionAcknowledgment {
*(It++) = static_cast<std::uint8_t>(htons(Type_) >> 8);

std::size_t OptionsSize = 0;
for (const auto& [Key, Value]: Options) {
for (auto Byte: Key) {
for (const auto &[Key, Value] : Options) {
for (auto Byte : Key) {
*(It++) = static_cast<std::uint8_t>(Byte);
}
*(It++) = '\0';
Expand All @@ -284,15 +283,11 @@ class OptionAcknowledgment {
std::uint16_t getType() const { return Type_; }

/// Get all options
const std::unordered_map<std::string, std::string>& getOptions() const {
return Options;
}
const std::unordered_map<std::string, std::string> &getOptions() const { return Options; }

/// Get option value by its name
/// @throws std::out_of_range if there's no option with the specified name
std::string_view getOptionValue(const std::string& OptionName) const {
return Options.at(OptionName);
}
std::string_view getOptionValue(const std::string &OptionName) const { return Options.at(OptionName); }

private:
friend ParseResult parse(const std::uint8_t *Buffer, std::size_t Len, OptionAcknowledgment &Packet);
Expand Down

0 comments on commit b209913

Please sign in to comment.