Commit aa1dee57 authored by Jakob Otto's avatar Jakob Otto

Rework constructors of binary_serializer

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