Remove high and low byte union for message length

refactor
PgSocks 2 years ago
parent ca82982a76
commit 6e10db0e07

@ -11,13 +11,7 @@ struct PACKED Header {
uint8_t preamble;
// The length of the message includes the preamble and CRC16 at the end
union {
uint16_t length;
struct {
uint8_t length_l;
uint8_t length_h;
};
};
// This is a CRC8 checksum for the preamble and length together
uint8_t crc;

@ -127,8 +127,8 @@ void
req_finalize(struct Client* client, uint8_t cmdset, uint8_t cmdid, uint8_t hostbyte, bool need_ack, size_t length, union Request* req) {
req->header.preamble = 0x55;
req->header.length_l = length & 0xFF;
req->header.length_h = ((length >> 8) & 0x3) | 4;
//req->header.length = length & 0x1FFF | 0x400;
req->header.length = length;
req->header.crc = crc8(req, 3);
req->header.seq_id = client->seq++;
req->header.sender = client->hostbyte;

@ -4,7 +4,7 @@
enum MESSAGEERR
message_validate(const union Message* message) {
uint16_t length = (message->header.length_h & 0x3) * 0xFF + message->header.length_l;
uint16_t length = message->header.length;
if(message->header.crc != crc8(message, 3))
return MESSAGEERR_HEADERCRC;

Loading…
Cancel
Save