MCPcopy Create free account
hub / github.com/MeisApps/pcbu-desktop / WritePacket

Method WritePacket

common/src/connection/BaseConnection.cpp:104–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104PacketError BaseConnection::WritePacket(SOCKET socket, uint16_t packetId, const std::vector<uint8_t> &data) {
105 PacketError error{};
106 spdlog::debug("Writing packet header...");
107 uint64_t packetHeader = htonll(PACKET_HEADER);
108 error = WriteData(socket, reinterpret_cast<const char *>(&packetHeader), sizeof(packetHeader));
109 if(error != PacketError::NONE) {
110 spdlog::error("Writing packet header failed.");
111 return error;
112 }
113
114 spdlog::debug("Writing packet ID... (ID={0:X})", packetId);
115 uint16_t packetIdNet = htons(packetId);
116 error = WriteData(socket, reinterpret_cast<const char *>(&packetIdNet), sizeof(packetIdNet));
117 if(error != PacketError::NONE) {
118 spdlog::error("Writing packet ID failed.");
119 return error;
120 }
121
122 spdlog::debug("Writing packet length... (Len={})", data.size());
123 uint16_t packetSize = htons(static_cast<uint16_t>(data.size()));
124 error = WriteData(socket, reinterpret_cast<const char *>(&packetSize), sizeof(packetSize));
125 if(error != PacketError::NONE) {
126 spdlog::error("Writing packet length failed.");
127 return error;
128 }
129
130 spdlog::debug("Writing packet data...");
131 error = WriteData(socket, reinterpret_cast<const char *>(data.data()), data.size());
132 if(error != PacketError::NONE) {
133 spdlog::error("Writing packet data failed. (Len={})", packetSize);
134 return error;
135 }
136 spdlog::debug("Done writing packet.");
137 return PacketError::NONE;
138}
139
140std::pair<PacketError, std::vector<uint8_t>> BaseConnection::ReadData(SOCKET socket, uint32_t size) {
141 uint32_t bytesRead = 0;

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected