Skip to content

Commit

Permalink
Allow fixed serialization for any trivially copyable type.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Feb 5, 2024
1 parent 0130c59 commit d5fdf2a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nth/io/deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool deserialize(D& d, deserializable_with<D> auto&... values) {
// `std::memcpy`ing the bytes. If reading is unsuccessful, returns `false`, and
// the value of `x` is unspecified.
template <int&..., typename T>
requires std::integral<T> or std::floating_point<T>
requires std::is_trivially_copyable_v<T>
bool deserialize_fixed(reader auto& r, T& x) { return r.read(nth::bytes(x)); }

// Attempts to read a fixed-length encoding into `l` from `r`. If successful,
Expand Down
2 changes: 1 addition & 1 deletion nth/io/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool serialize(S& s, serializable_with<S> auto&... values) {
// Writes `x` to `w` with the same bit-representation, taking exactly
// `sizeof(x)` bytes. Returns whether or not the write succeeded.
template <int&..., typename T>
requires std::integral<T> or std::floating_point<T>
requires std::is_trivially_copyable_v<T>
bool serialize_fixed(writer auto& w, T x) { return w.write(nth::bytes(x)); }

// Writes a length-prefixed integer to `w` with the value `n`. The length prefix
Expand Down

0 comments on commit d5fdf2a

Please sign in to comment.