11#include < boost/asio.hpp>
22
3- #ifdef BUILD_EXAMPLES
4- #include " ../../../tftp_common/tftp_common.hpp"
5- #else
6- #include < tftp_common/tftp_common.hpp>
7- #endif
3+ #include < tftp/tftp.hpp>
84
95#include < algorithm>
106#include < cstdlib>
117#include < fstream>
128#include < iostream>
139#include < string>
1410
15- using namespace tftp_common ::packets;
11+ using namespace tftp ::packets;
1612using boost::asio::ip::udp;
1713
1814namespace tftp_client {
1915
2016template <typename Packet> bool try_parse (std::uint8_t *data, std::size_t len, Packet &packet) {
21- auto [result, _] = parse (data, len, packet);
22- if (result)
17+ auto result = Parser<Packet>::parse (data, len);
18+ packet = std::move (result.get ().Packet );
19+
20+ if (result.isSuccess ())
2321 return true ;
2422 else {
2523 Error errPacket;
26- auto [ result, _] = parse (data, len, errPacket );
27- if (result)
24+ auto result = Parser<Error>:: parse (data, len);
25+ if (result. isSuccess () )
2826 throw errPacket;
2927 }
3028 return false ;
@@ -38,8 +36,7 @@ class TFTPClient {
3836 std::size_t blockSize = 512 ;
3937
4038 std::size_t getBlockSize (const OptionAcknowledgment &packet) const {
41- const auto &Options = packet.getOptions ();
42- if (Options.count (" blksize" ) != 0 ) {
39+ if (packet.hasOption (" blksize" )) {
4340 return std::atoi (packet.getOptionValue (" blksize" ).data ());
4441 }
4542 return 512 ;
@@ -58,7 +55,7 @@ class TFTPClient {
5855 if (!file && file.eof ())
5956 return ;
6057
61- std::size_t packetSize = Request (Type::WriteRequest, toPath, transferMode, optionsNames, optionsValues)
58+ std::size_t packetSize = Request (tftp::packets::types:: Type::WriteRequest, toPath, transferMode, optionsNames, optionsValues)
6259 .serialize (sendBuffer.begin ());
6360 socket.send_to (boost::asio::buffer (sendBuffer, packetSize), receiverEndpoint);
6461 std::size_t bytesRead = socket.receive_from (boost::asio::buffer (recvBuffer), senderEndpoint);
@@ -108,7 +105,7 @@ class TFTPClient {
108105 if (!file)
109106 return ;
110107
111- std::size_t packetSize = Request (Type::ReadRequest, fromPath, transferMode, optionsNames, optionsValues)
108+ std::size_t packetSize = Request (tftp::packets::types:: Type::ReadRequest, fromPath, transferMode, optionsNames, optionsValues)
112109 .serialize (sendBuffer.begin ());
113110 socket.send_to (boost::asio::buffer (sendBuffer, packetSize), receiverEndpoint);
114111 std::size_t bytesRead = socket.receive_from (boost::asio::buffer (recvBuffer), senderEndpoint);
0 commit comments