Add canonical cellular action input codec
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (ecs) (push) Canceled after 1m39s
Foundation / checks (network) (push) Canceled after 1m8s
Foundation / checks (client) (push) Canceled after 1m49s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (ecs) (push) Canceled after 1m39s
Foundation / checks (network) (push) Canceled after 1m8s
Foundation / checks (client) (push) Canceled after 1m49s
This commit is contained in:
@@ -581,4 +581,39 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
return std::unexpected(SessionCodecError::unknown_type);
|
||||
}
|
||||
}
|
||||
|
||||
std::array<std::uint8_t, cellular_action_input_bytes>
|
||||
encode_cellular_action_input(const CellularActionInput& input) {
|
||||
std::vector<std::uint8_t> bytes;
|
||||
bytes.reserve(cellular_action_input_bytes);
|
||||
put(bytes, input.tick, 8);
|
||||
put(bytes, static_cast<std::uint16_t>(input.move_x), 2);
|
||||
put(bytes, static_cast<std::uint16_t>(input.move_y), 2);
|
||||
bytes.push_back(input.has_intake_target ? 1 : 0);
|
||||
put(bytes, 0, 3);
|
||||
put(bytes, input.intake_x_um, 4);
|
||||
put(bytes, input.intake_y_um, 4);
|
||||
std::array<std::uint8_t, cellular_action_input_bytes> out{};
|
||||
std::ranges::copy(bytes, out.begin());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::expected<CellularActionInput, SessionCodecError>
|
||||
decode_cellular_action_input(std::span<const std::uint8_t> bytes) {
|
||||
if (bytes.size() != cellular_action_input_bytes)
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
if (bytes[12] > 1 || bytes[13] != 0 || bytes[14] != 0 || bytes[15] != 0)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
CellularActionInput input;
|
||||
input.tick = get(bytes, 0, 8);
|
||||
input.move_x = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(bytes, 8, 2)));
|
||||
input.move_y = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(bytes, 10, 2)));
|
||||
input.has_intake_target = bytes[12] != 0;
|
||||
input.intake_x_um = static_cast<std::uint32_t>(get(bytes, 16, 4));
|
||||
input.intake_y_um = static_cast<std::uint32_t>(get(bytes, 20, 4));
|
||||
if (input.tick == 0 ||
|
||||
(!input.has_intake_target && (input.intake_x_um != 0 || input.intake_y_um != 0)))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return input;
|
||||
}
|
||||
} // namespace evo::network
|
||||
|
||||
Reference in New Issue
Block a user