Skip to content

Commit

Permalink
[FIXUP] Make error UNWRAP compile
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanLF6768 committed Jun 16, 2024
1 parent 04c95d1 commit 0d3c28f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 23 additions & 1 deletion common/Inc/obc/bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,32 @@ concept Buffer = requires(T& buf, V v, std::size_t i) {
} && std::semiregular<V>;

/**
* @brief Convert a trivial struct into a byte buffer.
* @brief Convert a trivial struct into a readonly byte buffer.
*
* Can be used to facilitate trivial deserialization of C-style structs sent on
* a bus.
*
* @warning For portability, the struct should be tightly packed (containing
* explicit padding fields if required) with fixed sized integers.
*
* @tparam T type of the struct to translate.
*/
template<typename T>
requires std::is_trivially_copyable_v<T>
auto StructAsBuffer(const T& s) -> std::span<const std::byte, sizeof(T)> {
// This function is constrained to only operate on POD structs
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return {reinterpret_cast<const std::byte*>(&s), sizeof(T)};
}

/**
* @brief Convert a trivial struct into a read-write byte buffer.
*
* Can be used to facilitate trivial deserialization of C-style structs sent on
* a bus.
*
* @warning For portability, the struct should be tightly packed (containing
* explicit padding fields if required) with fixed sized integers.
*
* @tparam T type of the struct to translate.
*/
Expand Down
3 changes: 2 additions & 1 deletion common/Inc/obc/utils/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ concept ExpectedReturn =
Specializes<T, std::expected> && MaybeError<typename T::error_type> &&
std::convertible_to<T, std::expected<R, typename T::error_type>>;

/*This functionality is impossible is impossible to implement without
/*
* This functionality is impossible is impossible to implement without
* macros since unwrapping is an operation which can return from the
* enclosing context.
*/
Expand Down

0 comments on commit 0d3c28f

Please sign in to comment.