empty inside

old
Brett 2023-11-06 00:59:46 -05:00
parent 0c8065f390
commit 6e9ba1091f
7 changed files with 64 additions and 46 deletions

Binary file not shown.

View File

@ -73,3 +73,7 @@
1177 1269 1699239246742802185 AssignmentProject b2c28a88f620cb6b
1 1215 1699239290003321502 CMakeFiles/AssignmentProject.dir/src/main.cpp.o 2b6a871f4782c17
1215 1306 1699239290095322610 AssignmentProject b2c28a88f620cb6b
1 332 1699249408404357031 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/filesystem.cpp.o 9cc43f95baec43fd
1 1078 1699249409148366620 CMakeFiles/AssignmentProject.dir/src/main.cpp.o 2b6a871f4782c17
333 1522 1699249409584372239 libraries/BLT/libBLT.a fff5a821b8ed7db
1522 1615 1699249409684373529 AssignmentProject b2c28a88f620cb6b

Binary file not shown.

View File

@ -1,3 +1,3 @@
Start testing: Nov 05 21:54 EST
Start testing: Nov 06 00:43 EST
----------------------------------------------------------
End testing: Nov 05 21:54 EST
End testing: Nov 06 00:43 EST

@ -1 +1 @@
Subproject commit 288076ed02c7735cef394d10e923a246ef9a769c
Subproject commit 1a72728aeb9299d168868bb1c79f319031d9d8a1

View File

@ -35,63 +35,55 @@
constexpr size_t PACKET_SIZE = 512;
// header:
// 1 byte type
// 0: data send
// 1: data ack
// 2: data resend
// 3:
// 8 bytes send_id
// 8 bytes recv_id
constexpr size_t HEADER_SIZE = 32;
class packet
{
private:
std::uint8_t* buffer = new std::uint8_t[PACKET_SIZE];
protected:
blt::scoped_buffer<std::uint8_t> buffer;
public:
packet(): buffer(PACKET_SIZE)
{}
explicit packet(size_t size): buffer(size)
{}
size_t used = 0;
packet() = default;
packet(const packet& copy) = default;
packet(const packet& copy)
{
for (size_t i = 0; i < PACKET_SIZE; i++)
buffer[i] = copy[i];
used = copy.used;
}
packet(packet&& move) noexcept = default;
packet(packet&& move) noexcept
{
delete[] buffer;
buffer = move.buffer;
used = move.used;
move.buffer = nullptr;
}
packet& operator=(const packet& copy) = default;
packet& operator=(const packet& copy)
{
if (&copy == this)
return *this;
for (size_t i = 0; i < PACKET_SIZE; i++)
buffer[i] = copy[i];
used = copy.used;
return *this;
}
packet& operator=(packet&& move) noexcept
{
delete[] buffer;
buffer = move.buffer;
move.buffer = nullptr;
used = move.used;
return *this;
}
packet& operator=(packet&& move) noexcept = default;
std::uint8_t* data()
{
return buffer;
return buffer.data();
}
[[nodiscard]] const std::uint8_t* data() const
{
return buffer.data();
}
std::uint8_t& operator[](size_t index)
{
BLT_ASSERT(index < PACKET_SIZE);
return buffer[index];
}
[[nodiscard]] const std::uint8_t& operator[](size_t index) const
{
BLT_ASSERT(index < PACKET_SIZE);
return buffer[index];
}
@ -100,10 +92,7 @@ class packet
return used;
}
~packet()
{
delete[] buffer;
}
~packet() = default;
};
void mangle(packet& packet)
@ -203,6 +192,31 @@ class pipe
}
};
class transceiver
{
private:
// the pipe to send on
pipe& uplink;
// the pipe to receive on
pipe& downlink;
public:
transceiver(pipe& uplink, pipe& downlink): uplink(uplink), downlink(downlink)
{}
void send(const packet& p)
{
packet datagram{PACKET_SIZE + HEADER_SIZE};
std::memcpy(&datagram.data()[HEADER_SIZE], p.data(), PACKET_SIZE);
uplink.send(datagram);
}
};
/**
* Load a file and split it into data segments
* @param path
* @param packets
*/
void load_packets(const std::string& path, std::vector<packet>& packets)
{
std::ifstream file(path);