20 assert(Buffer !=
nullptr);
26 std::size_t BytesRead = 0;
27 for (std::size_t Idx = 0; Idx != Len; ++Idx) {
28 const auto Byte = Buffer[Idx];
34 Packet.Type_ = std::uint16_t(Byte) << 0;
38 Packet.Type_ |= std::uint16_t(Byte) << 8;
39 Packet.Type_ = ntohs(Packet.Type_);
51 Packet.Filename.push_back(Byte);
62 Packet.Mode.push_back(Byte);
68 Packet.OptionsNames.push_back(std::move(Name));
77 Packet.OptionsValues.push_back(std::move(Value));
84 Value.push_back(Byte);
99 assert(Buffer !=
nullptr);
102 std::size_t Step = 0;
103 std::size_t BytesRead = 0;
104 for (std::size_t Idx = 0; Idx != Len; ++Idx) {
105 const auto Byte = Buffer[Idx];
111 Packet.Type_ = std::uint16_t(Byte) << 0;
115 Packet.Type_ |= std::uint16_t(Byte) << 8;
116 Packet.Type_ = ntohs(Packet.Type_);
125 Packet.Block = std::uint16_t(Byte) << 0;
129 Packet.Block |= std::uint16_t(Byte) << 8;
130 Packet.Block = ntohs(Packet.Block);
135 Packet.DataBuffer.push_back(Byte);
137 if (Idx == Len - 1) {
154 assert(Buffer !=
nullptr);
157 std::size_t Step = 0;
158 std::size_t BytesRead = 0;
159 for (std::size_t Idx = 0; Idx != Len; ++Idx) {
160 const auto Byte = Buffer[Idx];
166 Packet.Type_ = std::uint16_t(Byte) << 0;
170 Packet.Type_ |= std::uint16_t(Byte) << 8;
171 Packet.Type_ = ntohs(Packet.Type_);
180 Packet.Block = std::uint16_t(Byte) << 0;
184 Packet.Block |= std::uint16_t(Byte) << 8;
185 Packet.Block = ntohs(Packet.Block);
199 assert(Buffer !=
nullptr);
202 std::size_t Step = 0;
203 std::size_t BytesRead = 0;
204 for (std::size_t Idx = 0; Idx != Len; ++Idx) {
205 const auto Byte = Buffer[Idx];
211 Packet.Type_ = std::uint16_t(Byte) << 0;
215 Packet.Type_ |= std::uint16_t(Byte) << 8;
216 Packet.Type_ = ntohs(Packet.Type_);
225 Packet.ErrorCode = std::uint16_t(Byte) << 0;
229 Packet.ErrorCode |= std::uint16_t(Byte) << 8;
230 Packet.ErrorCode = ntohs(Packet.ErrorCode);
238 Packet.ErrorMessage.push_back(Byte);
253 assert(Buffer !=
nullptr);
258 std::size_t Step = 0;
259 std::size_t BytesRead = 0;
260 for (std::size_t Idx = 0; Idx != Len; ++Idx) {
261 const auto Byte = Buffer[Idx];
267 Packet.Type_ = std::uint16_t(Byte) << 0;
271 Packet.Type_ |= std::uint16_t(Byte) << 8;
272 Packet.Type_ = ntohs(Packet.Type_);
284 Name.push_back(Byte);
289 Packet.Options.emplace(std::move(Name), std::move(Value));
291 if (Idx == Len - 1) {
296 Value.push_back(Byte);
Acknowledgment Trivial File Transfer Protocol packet.
Definition: packets.hpp:219
Data Trivial File Transfer Protocol packet.
Definition: packets.hpp:166
Error Trivial File Transfer Protocol packet.
Definition: packets.hpp:253
Option Acknowledgment Trivial File Transfer Protocol packet.
Definition: packets.hpp:301
Read/Write Request (RRQ/WRQ) Trivial File Transfer Protocol packet.
Definition: packets.hpp:77
@ AcknowledgmentPacket
Acknowledgment (ACK) operation code.
Definition: packets.hpp:31
@ ReadRequest
Read request (RRQ) operation code.
Definition: packets.hpp:25
@ OptionAcknowledgmentPacket
Option Acknowledgment (OACK) operation code.
Definition: packets.hpp:35
@ DataPacket
Data (DATA) operation code.
Definition: packets.hpp:29
@ WriteRequest
Write request (WRQ) operation code.
Definition: packets.hpp:27
@ ErrorPacket
Error (ERROR) operation code.
Definition: packets.hpp:33
Definition: packets.hpp:16
ParseResult parse(const std::uint8_t *Buffer, std::size_t Len, Request &Packet)
Definition: parsers.hpp:19
The result of parsing a single packet.
Definition: parsers.hpp:8
bool Success
if the parsing was successful
Definition: parsers.hpp:10
std::size_t BytesRead
count of bytes read
Definition: parsers.hpp:12