Commit aa1dee57 authored by Jakob Otto's avatar Jakob Otto

Rework constructors of binary_serializer

parent 7290e438
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "caf/byte.hpp" #include "caf/byte.hpp"
#include "caf/deserializer.hpp" #include "caf/deserializer.hpp"
#include "caf/span.hpp"
namespace caf { namespace caf {
...@@ -36,32 +37,25 @@ public: ...@@ -36,32 +37,25 @@ public:
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
template <class ValueType> binary_deserializer(actor_system& sys, span<const byte> bytes)
binary_deserializer(actor_system& sys, const ValueType* buf, size_t buf_size) : super(sys), current_(bytes.begin()), end_(bytes.end()) {
: super(sys), // nop
current_(reinterpret_cast<const byte*>(buf)),
end_(reinterpret_cast<const byte*>(buf) + buf_size) {
static_assert(sizeof(ValueType) == 1, "sizeof(Value type) > 1");
} }
template <class ValueType> binary_deserializer(execution_unit* ctx, span<const byte> bytes)
binary_deserializer(execution_unit* ctx, const ValueType* buf, : super(ctx), current_(bytes.begin()), end_(bytes.end()) {
size_t buf_size) // nop
: super(ctx),
current_(reinterpret_cast<const byte*>(buf)),
end_(reinterpret_cast<const byte*>(buf) + buf_size) {
static_assert(sizeof(ValueType) == 1, "sizeof(Value type) > 1");
} }
template <class BufferType> template <class T>
binary_deserializer(actor_system& sys, const BufferType& buf) binary_deserializer(actor_system& sys, const std::vector<T>& buf)
: binary_deserializer(sys, buf.data(), buf.size()) { : binary_deserializer(sys, as_bytes(make_span(buf.data(), buf.size()))) {
// nop // nop
} }
template <class BufferType> template <class T>
binary_deserializer(execution_unit* ctx, const BufferType& buf) binary_deserializer(execution_unit* ctx, const std::vector<T>& buf)
: binary_deserializer(ctx, buf.data(), buf.size()) { : binary_deserializer(ctx, as_bytes(make_span(buf.data(), buf.size()))) {
// nop // nop
} }
......
...@@ -149,8 +149,8 @@ error binary_deserializer::apply_impl(std::string& x) { ...@@ -149,8 +149,8 @@ error binary_deserializer::apply_impl(std::string& x) {
return err; return err;
if (!range_check(str_size)) if (!range_check(str_size))
return sec::end_of_stream; return sec::end_of_stream;
x.assign(reinterpret_cast<char*>(const_cast<byte*>(current_)), x.assign(reinterpret_cast<const char*>(current_),
reinterpret_cast<char*>(const_cast<byte*>(current_)) + str_size); reinterpret_cast<const char*>(current_) + str_size);
current_ += str_size; current_ += str_size;
return end_sequence(); 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