Skip to content

Commit

Permalink
Get use of structured bindings
Browse files Browse the repository at this point in the history
I forgot that project use C++17 and not C++14
  • Loading branch information
eoan-ermine committed Jun 14, 2023
1 parent ee716aa commit a16d1c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions tests/packets_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ TEST(OptionAcknowledgment, Serialization) {

std::size_t BaseOffset = sizeof(std::uint16_t);
// option names and values
for (auto It = Options.cbegin(), End = Options.cend(); It != End; ++It) {
EXPECT_STRING(Buffer, BaseOffset, It->first);
BaseOffset += It->first.size() + 1;
EXPECT_STRING(Buffer, BaseOffset, It->second);
BaseOffset += It->second.size() + 1;
for (const auto& [Key, Value]: Options) {
EXPECT_STRING(Buffer, BaseOffset, Key);
BaseOffset += Key.size() + 1;
EXPECT_STRING(Buffer, BaseOffset, Value);
BaseOffset += Value.size() + 1;
}

EXPECT_EQ(Buffer.size(), PacketSize);
Expand Down
4 changes: 2 additions & 2 deletions tests/parse_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ TEST(OptionAcknowledgment, Parse) {
{"saveFiles", "true"}, {"discardQualifiers", "false"},
{"secret", "Ix0e86yG8YpFzwz1gS0XxJW3"}
};
for (auto It = Options.cbegin(), End = Options.cend(); It != End; ++It) {
ASSERT_EQ(Packet.getOptionValue(It->first), It->second);
for (const auto& [Key, Value]: Options) {
ASSERT_EQ(Packet.getOptionValue(Key), Value);
}

ASSERT_EQ(success, true);
Expand Down
8 changes: 4 additions & 4 deletions tftp_common/packets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,16 @@ class OptionAcknowledgment {
*(It++) = static_cast<std::uint8_t>(htons(Type_) >> 8);

std::size_t OptionsSize = 0;
for (auto OIt = Options.cbegin(), OEnd = Options.cend(); OIt != OEnd; ++OIt) {
for (auto Byte: OIt->first) {
for (const auto& [Key, Value]: Options) {
for (auto Byte: Key) {
*(It++) = static_cast<std::uint8_t>(Byte);
}
*(It++) = '\0';
for (auto Byte : OIt->second) {
for (auto Byte : Value) {
*(It++) = static_cast<std::uint8_t>(Byte);
}
*(It++) = '\0';
OptionsSize += OIt->first.size() + OIt->second.size() + 2;
OptionsSize += Key.size() + Value.size() + 2;
}

return sizeof(Type) + OptionsSize;
Expand Down

0 comments on commit a16d1c9

Please sign in to comment.