Skip to content

Commit

Permalink
Rename Buffer[View] to SerialBuffer[View]
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa committed Sep 15, 2024
1 parent 3d66ead commit 999d3b8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sts1CobcSw/Edu/Edu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ auto ReceiveDataPacket() -> Result<void>
template<typename T>
auto Receive() -> Result<T>
{
auto buffer = Buffer<T>{};
auto buffer = SerialBuffer<T>{};
OUTCOME_TRY(Receive(buffer));
return Deserialize<T>(buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/Periphery/Eps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ auto ReadAdc(hal::GpioPin * adcCsPin) -> AdcValues
RODOS::AT(RODOS::NOW() + conversionTime);

// Resolution is 12 bit, sent like this: [0 0 0 0 MSB x x x], [x x x x x x x LSB]
auto adcData = Buffer<AdcValues>{};
auto adcData = SerialBuffer<AdcValues>{};
adcCsPin->Reset();
hal::ReadFrom(&framEpsSpi, Span(&adcData), spiTimeout);
adcCsPin->Set();
Expand Down
13 changes: 6 additions & 7 deletions Sts1CobcSw/Serial/Serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,24 @@ inline constexpr auto defaultEndianness = std::endian::little;

template<typename T>
requires(serialSize<T> != 0)
using Buffer = std::array<Byte, serialSize<T>>;
using SerialBuffer = std::array<Byte, serialSize<T>>;

// TODO: Maybe remove this type alias or prepend "Serial" to both again
template<typename T>
requires(serialSize<T> != 0)
using BufferView = std::span<Byte const, serialSize<T>>;
using SerialBufferView = std::span<Byte const, serialSize<T>>;


template<typename T>
[[nodiscard]] auto Serialize(T const & t) -> Buffer<T>;
[[nodiscard]] auto Serialize(T const & t) -> SerialBuffer<T>;

template<std::endian endianness, typename T>
[[nodiscard]] auto Serialize(T const & t) -> Buffer<T>;
[[nodiscard]] auto Serialize(T const & t) -> SerialBuffer<T>;

template<std::default_initializable T>
[[nodiscard]] auto Deserialize(BufferView<T> bufferView) -> T;
[[nodiscard]] auto Deserialize(SerialBufferView<T> bufferView) -> T;

template<std::endian endianness, std::default_initializable T>
[[nodiscard]] auto Deserialize(BufferView<T> bufferView) -> T;
[[nodiscard]] auto Deserialize(SerialBufferView<T> bufferView) -> T;

// Must be overloaded for user-defined types to be serializable
template<std::endian endianness, TriviallySerializable T>
Expand Down
10 changes: 5 additions & 5 deletions Sts1CobcSw/Serial/Serial.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
namespace sts1cobcsw
{
template<typename T>
inline auto Serialize(T const & t) -> Buffer<T>
inline auto Serialize(T const & t) -> SerialBuffer<T>
{
return Serialize<defaultEndianness>(t);
}


template<std::endian endianness, typename T>
inline auto Serialize(T const & t) -> Buffer<T>
inline auto Serialize(T const & t) -> SerialBuffer<T>
{
auto buffer = Buffer<T>{};
auto buffer = SerialBuffer<T>{};
(void)SerializeTo<endianness>(buffer.data(), t);
return buffer;
}


template<std::default_initializable T>
inline auto Deserialize(BufferView<T> bufferView) -> T
inline auto Deserialize(SerialBufferView<T> bufferView) -> T
{
return Deserialize<defaultEndianness, T>(bufferView);
}


template<std::endian endianness, std::default_initializable T>
inline auto Deserialize(BufferView<T> bufferView) -> T
inline auto Deserialize(SerialBufferView<T> bufferView) -> T
{
auto t = T{};
(void)DeserializeFrom<endianness>(bufferView.data(), &t);
Expand Down

0 comments on commit 999d3b8

Please sign in to comment.