Commit 38fa6481 authored by Dominik Charousset's avatar Dominik Charousset

Integrate missed review feedback

parent aa1dee57
......@@ -37,28 +37,26 @@ public:
// -- constructors, destructors, and assignment operators --------------------
binary_deserializer(actor_system& sys, span<const byte> bytes)
: super(sys), current_(bytes.begin()), end_(bytes.end()) {
// nop
}
binary_deserializer(actor_system& sys, span<const byte> bytes);
binary_deserializer(execution_unit* ctx, span<const byte> bytes)
: super(ctx), current_(bytes.begin()), end_(bytes.end()) {
// nop
}
binary_deserializer(execution_unit* ctx, span<const byte> bytes);
template <class T>
binary_deserializer(actor_system& sys, const std::vector<T>& buf)
: binary_deserializer(sys, as_bytes(make_span(buf.data(), buf.size()))) {
: binary_deserializer(sys, as_bytes(make_span(buf))) {
// nop
}
template <class T>
binary_deserializer(execution_unit* ctx, const std::vector<T>& buf)
: binary_deserializer(ctx, as_bytes(make_span(buf.data(), buf.size()))) {
: binary_deserializer(ctx, as_bytes(make_span(buf))) {
// nop
}
binary_deserializer(actor_system& sys, const char* buf, size_t buf_size);
binary_deserializer(execution_unit* ctx, const char* buf, size_t buf_size);
// -- overridden member functions --------------------------------------------
error begin_object(uint16_t& typenr, std::string& name) override;
......@@ -74,23 +72,24 @@ public:
// -- properties -------------------------------------------------------------
/// Returns the current read position.
const byte* current() const {
return current_;
}
const char* current() const CAF_DEPRECATED_MSG("use remaining() instead");
/// Returns the past-the-end iterator.
const byte* end() const {
return end_;
}
const char* end() const CAF_DEPRECATED_MSG("use remaining() instead");
/// Returns how many bytes are still available to read.
size_t remaining() const;
size_t remaining() const noexcept{
return static_cast<size_t>(end_ - current_);
}
/// Returns the remaining bytes.
span<const byte> remainder() const noexcept {
return make_span(current_, end_);
}
/// Jumps `num_bytes` forward.
/// @pre `num_bytes <= remaining()`
void skip(size_t num_bytes) {
current_ += num_bytes;
}
void skip(size_t num_bytes);
protected:
error apply_impl(int8_t&) override;
......
......@@ -57,6 +57,9 @@ using enable_if_t = typename std::enable_if<V, T>::type;
template <class Trait, class T = void>
using enable_if_tt = typename std::enable_if<Trait::value, T>::type;
template <class T>
using remove_reference_t = typename std::remove_reference<T>::type;
/// Checks whether `T` is inspectable by `Inspector`.
template <class Inspector, class T>
class is_inspectable {
......
......@@ -43,6 +43,11 @@ public:
using value_type = typename container_type::value_type;
// -- invariants -------------------------------------------------------------
static_assert(sizeof(value_type) == 1,
"container must have a byte-sized value type");
// -- constructors, destructors, and assignment operators --------------------
serializer_impl(actor_system& sys, container_type& buf)
......
......@@ -211,7 +211,7 @@ span<byte> as_writable_bytes(span<T> xs) {
/// Convenience function to make using `caf::span` more convenient without the
/// deduction guides.
template <class T>
auto make_span(T& xs) -> span<detail::decay_t<decltype(xs[0])>> {
auto make_span(T& xs) -> span<detail::remove_reference_t<decltype(xs[0])>> {
return {xs.data(), xs.size()};
}
......
......@@ -50,6 +50,32 @@ error apply_float(binary_deserializer& bs, T& x) {
} // namespace
binary_deserializer::binary_deserializer(actor_system& sys,
span<const byte> bytes)
: super(sys), current_(bytes.data()), end_(bytes.data() + bytes.size()) {
// nop
}
binary_deserializer::binary_deserializer(execution_unit* ctx,
span<const byte> bytes)
: super(ctx), current_(bytes.data()), end_(bytes.data() + bytes.size()) {
// nop
}
binary_deserializer::binary_deserializer(actor_system& sys, const char* buf,
size_t buf_size)
: binary_deserializer(sys, make_span(reinterpret_cast<const byte*>(buf),
buf_size)) {
// nop
}
binary_deserializer::binary_deserializer(execution_unit* ctx, const char* buf,
size_t buf_size)
: binary_deserializer(ctx, make_span(reinterpret_cast<const byte*>(buf),
buf_size)) {
// nop
}
error binary_deserializer::begin_object(uint16_t& nr, std::string& name) {
if (auto err = apply(nr))
return err;
......@@ -89,8 +115,17 @@ error binary_deserializer::apply_raw(size_t num_bytes, void* storage) {
return none;
}
size_t binary_deserializer::remaining() const {
return static_cast<size_t>(end_ - current_);
const char* binary_deserializer::current() const {
return reinterpret_cast<const char*>(current_);
}
const char* binary_deserializer::end() const {
return reinterpret_cast<const char*>(end_);
}
void binary_deserializer::skip(size_t num_bytes) {
CAF_ASSERT(num_bytes <= remaining());
current_ += num_bytes;
}
error binary_deserializer::apply_impl(int8_t& x) {
......@@ -149,8 +184,7 @@ error binary_deserializer::apply_impl(std::string& x) {
return err;
if (!range_check(str_size))
return sec::end_of_stream;
x.assign(reinterpret_cast<const char*>(current_),
reinterpret_cast<const char*>(current_) + str_size);
x.assign(reinterpret_cast<const char*>(current_), str_size);
current_ += str_size;
return end_sequence();
}
......
......@@ -53,6 +53,7 @@ struct test_data {
ts_(ts),
te_(te),
str_(str) {
// nop
}
test_data()
......@@ -61,6 +62,7 @@ struct test_data {
caf::timestamp{
caf::timestamp::duration{1478715821 * 1000000000ll}},
test_enum::b, "Lorem ipsum dolor sit amet.") {
// nop
}
int32_t i32_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment