Skip to content

Commit

Permalink
Clean up TLS syntax library's use of integer types
Browse files Browse the repository at this point in the history
  • Loading branch information
bifurcation committed Oct 31, 2024
1 parent 1f192cc commit 5c03956
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/tls_syntax/include/tls/tls_syntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
#include <optional>
#include <stdexcept>
#include <vector>
#include <cstdint>
#include <cstddef>

#include <tls/compat.h>

namespace MLS_NAMESPACE::tls {

using std::size_t;
using std::uint8_t;
using std::uint16_t;
using std::uint32_t;
using std::uint64_t;
using std::ptrdiff_t;

// For indicating no min or max in vector definitions
const size_t none = std::numeric_limits<size_t>::max();

Expand Down Expand Up @@ -288,8 +297,9 @@ operator>>(istream& str, std::vector<T>& vec)
// NB: Remember that we store the vector in reverse order
// NB: This requires that T be default-constructible
istream r;
const auto size_diff = static_cast<ptrdiff_t>(size);
r._buffer =
std::vector<uint8_t>{ str._buffer.end() - size, str._buffer.end() };
std::vector<uint8_t>{ str._buffer.end() - size_diff, str._buffer.end() };

vec.clear();
while (r._buffer.size() > 0) {
Expand All @@ -298,7 +308,7 @@ operator>>(istream& str, std::vector<T>& vec)
}

// Truncate the primary buffer
str._buffer.erase(str._buffer.end() - size, str._buffer.end());
str._buffer.erase(str._buffer.end() - size_diff, str._buffer.end());

return str;
}
Expand Down

0 comments on commit 5c03956

Please sign in to comment.