Commit 5459caf1 authored by Dominik Charousset's avatar Dominik Charousset

Rename {pos => current}, add remaining() getter

parent 47538648
......@@ -60,8 +60,8 @@ public:
// -- properties -------------------------------------------------------------
/// Returns the current read position.
const char* pos() const {
return pos_;
const char* current() const {
return current_;
}
/// Returns the past-the-end iterator.
......@@ -69,6 +69,9 @@ public:
return end_;
}
/// Returns how many bytes are still available to read.
size_t remaining() const;
protected:
error apply_impl(int8_t&) override;
......@@ -100,10 +103,10 @@ protected:
private:
bool range_check(size_t read_size) {
return pos_ + read_size <= end_;
return current_ + read_size <= end_;
}
const char* pos_;
const char* current_;
const char* end_;
};
......
......@@ -26,6 +26,7 @@
#include "caf/detail/network_order.hpp"
#include "caf/sec.hpp"
namespace caf {
namespace {
......@@ -52,13 +53,13 @@ error apply_float(binary_deserializer& bs, T& x) {
binary_deserializer::binary_deserializer(actor_system& sys, const char* buf,
size_t buf_size)
: super(sys), pos_(buf), end_(buf + buf_size) {
: super(sys), current_(buf), end_(buf + buf_size) {
// nop
}
binary_deserializer::binary_deserializer(execution_unit* ctx, const char* buf,
size_t buf_size)
: super(ctx), pos_(buf), end_(buf + buf_size) {
: super(ctx), current_(buf), end_(buf + buf_size) {
// nop
}
......@@ -99,11 +100,15 @@ error binary_deserializer::end_sequence() {
error binary_deserializer::apply_raw(size_t num_bytes, void* storage) {
if (!range_check(num_bytes))
return sec::end_of_stream;
memcpy(storage, pos_, num_bytes);
pos_ += num_bytes;
memcpy(storage, current_, num_bytes);
current_ += num_bytes;
return none;
}
size_t binary_deserializer::remaining() const {
return static_cast<size_t>(end_ - current_);
}
error binary_deserializer::apply_impl(int8_t& x) {
return apply_raw(sizeof(int8_t), &x);
}
......@@ -160,8 +165,8 @@ error binary_deserializer::apply_impl(std::string& x) {
return err;
if (!range_check(str_size))
return sec::end_of_stream;
x.assign(pos_, pos_ + str_size);
pos_ += str_size;
x.assign(current_, current_ + str_size);
current_ += str_size;
return end_sequence();
}
......
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