Skip to content

Commit

Permalink
fixed bit logic for success flag depending on event flag
Browse files Browse the repository at this point in the history
  • Loading branch information
99oblivius committed Oct 14, 2024
1 parent 94a7055 commit af61659
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/handler/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void CommandHandler::Handler(std::string_view& packet, std::vector<uint8_t>& res
std::string msg = "";

uint8_t header = 0;
int success_flag = 0;

if (packet.empty()) {
action = 0xFF;
Expand All @@ -21,12 +22,14 @@ void CommandHandler::Handler(std::string_view& packet, std::vector<uint8_t>& res
if ((uint8_t)packet[0] & 0x80) {
EventHandler(packet, action, msg, ec);
header |= 1 << 7;
success_flag = (bool)ec ? 0 : 1;
} else {
RequestHandler(packet, action, msg, ec);
success_flag = msg.empty() ? 0 : 1;
}
}

header |= ((msg.empty() ? 0 : 1) | (bool)ec ? 0 : 1) << 6;
header |= success_flag << 6;
header |= static_cast<uint8_t>(action) & 0x3F;
response.push_back(header);

Expand Down

0 comments on commit af61659

Please sign in to comment.