Deprecate byte

parent 52914200
......@@ -233,7 +233,6 @@ caf_add_component(
binary_serializer
blocking_actor
broadcast_downstream_manager
byte
composition
config_option
config_option_set
......
......@@ -21,8 +21,8 @@
namespace caf {
/// Deserializes C++ objects from sequence of bytes. Does not perform run-time
/// type checks.
/// Deserializes C++ objects from sequence of bytes. Does not perform
/// run-time type checks.
class CAF_CORE_EXPORT binary_deserializer
: public load_inspector_base<binary_deserializer> {
public:
......@@ -46,14 +46,14 @@ public:
binary_deserializer(execution_unit* ctx, const void* buf,
size_t size) noexcept
: binary_deserializer(ctx,
make_span(reinterpret_cast<const byte*>(buf), size)) {
: binary_deserializer(
ctx, make_span(reinterpret_cast<const std::byte*>(buf), size)) {
// nop
}
binary_deserializer(actor_system& sys, const void* buf, size_t size) noexcept
: binary_deserializer(sys,
make_span(reinterpret_cast<const byte*>(buf), size)) {
: binary_deserializer(
sys, make_span(reinterpret_cast<const std::byte*>(buf), size)) {
// nop
}
......@@ -64,8 +64,8 @@ public:
return static_cast<size_t>(end_ - current_);
}
/// Returns the remaining bytes.
span<const byte> remainder() const noexcept {
/// Returns the remaining std::bytes.
span<const std::byte> remainder() const noexcept {
return make_span(current_, end_);
}
......@@ -79,15 +79,15 @@ public:
void skip(size_t num_bytes);
/// Assigns a new input.
void reset(span<const byte> bytes) noexcept;
void reset(span<const std::byte> bytes) noexcept;
/// Returns the current read position.
const byte* current() const noexcept {
const std::byte* current() const noexcept {
return current_;
}
/// Returns the end of the assigned memory block.
const byte* end() const noexcept {
const std::byte* end() const noexcept {
return end_;
}
......@@ -155,7 +155,7 @@ public:
bool value(bool& x) noexcept;
bool value(byte& x) noexcept;
bool value(std::byte& x) noexcept;
bool value(uint8_t& x) noexcept;
......@@ -196,23 +196,23 @@ public:
bool value(std::u32string& x);
bool value(span<byte> x) noexcept;
bool value(span<std::byte> x) noexcept;
bool value(std::vector<bool>& x);
private:
explicit binary_deserializer(actor_system& sys) noexcept;
/// Checks whether we can read `read_size` more bytes.
/// Checks whether we can read `read_size` more std::bytes.
bool range_check(size_t read_size) const noexcept {
return current_ + read_size <= end_;
}
/// Points to the current read position.
const byte* current_;
const std::byte* current_;
/// Points to the end of the assigned memory block.
const byte* end_;
const std::byte* end_;
/// Provides access to the ::proxy_registry and to the ::actor_system.
execution_unit* context_;
......
......@@ -9,7 +9,6 @@
#include <type_traits>
#include <vector>
#include "caf/byte.hpp"
#include "caf/byte_buffer.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/squashed_int.hpp"
......@@ -32,7 +31,7 @@ public:
using container_type = byte_buffer;
using value_type = byte;
using value_type = std::byte;
// -- constructors, destructors, and assignment operators --------------------
......@@ -137,7 +136,7 @@ public:
return end_sequence();
}
bool value(byte x);
bool value(std::byte x);
bool value(bool x);
......@@ -174,7 +173,7 @@ public:
bool value(const std::u32string& x);
bool value(span<const byte> x);
bool value(span<const std::byte> x);
bool value(const std::vector<bool>& x);
......
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#include <cstdint>
#include <type_traits>
#pragma once
namespace caf {
/// A C++11/14 drop-in replacement for C++17's `std::byte`.
enum class byte : uint8_t {};
template <class IntegerType,
class = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr IntegerType to_integer(byte x) noexcept {
return static_cast<IntegerType>(x);
}
template <class IntegerType,
class E = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr byte& operator<<=(byte& x, IntegerType shift) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) << shift);
}
template <class IntegerType,
class E = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr byte operator<<(byte x, IntegerType shift) noexcept {
return static_cast<byte>(to_integer<uint8_t>(x) << shift);
}
template <class IntegerType,
class E = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr byte& operator>>=(byte& x, IntegerType shift) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) >> shift);
}
template <class IntegerType,
class E = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr byte operator>>(byte x, IntegerType shift) noexcept {
return static_cast<byte>(static_cast<unsigned char>(x) >> shift);
}
inline byte& operator|=(byte& x, byte y) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) | to_integer<uint8_t>(y));
}
constexpr byte operator|(byte x, byte y) noexcept {
return static_cast<byte>(to_integer<uint8_t>(x) | to_integer<uint8_t>(y));
}
inline byte& operator&=(byte& x, byte y) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) & to_integer<uint8_t>(y));
}
constexpr byte operator&(byte x, byte y) noexcept {
return static_cast<byte>(to_integer<uint8_t>(x) & to_integer<uint8_t>(y));
}
inline byte& operator^=(byte& x, byte y) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) ^ to_integer<uint8_t>(y));
}
constexpr byte operator^(byte x, byte y) noexcept {
return static_cast<byte>(to_integer<uint8_t>(x) ^ to_integer<uint8_t>(y));
}
constexpr byte operator~(byte x) noexcept {
return static_cast<byte>(~to_integer<uint8_t>(x));
}
} // namespace caf
// Deprecated include. The next CAF release won't include this header.
\ No newline at end of file
......@@ -4,13 +4,12 @@
#pragma once
#include <cstddef>
#include <vector>
#include "caf/byte.hpp"
namespace caf {
/// A buffer for storing binary data.
using byte_buffer = std::vector<byte>;
using byte_buffer = std::vector<std::byte>;
} // namespace caf
......@@ -4,15 +4,16 @@
#pragma once
#include "caf/byte.hpp"
#include <cstddef>
#include "caf/span.hpp"
namespace caf {
/// Convenience alias for referring to a writable sequence of bytes.
using byte_span = span<byte>;
using byte_span = span<std::byte>;
/// Convenience alias for referring to a read-only sequence of bytes.
using const_byte_span = span<const byte>;
using const_byte_span = span<const std::byte>;
} // namespace caf
......@@ -122,7 +122,7 @@ public:
bool end_associative_array() override;
bool value(byte& x) override;
bool value(std::byte& x) override;
bool value(bool& x) override;
......@@ -154,7 +154,7 @@ public:
bool value(std::u32string& x) override;
bool value(span<byte> x) override;
bool value(span<std::byte> x) override;
private:
// Sets `type` according to the `@type` field in `obj` or to the type ID of
......
......@@ -86,7 +86,7 @@ public:
bool end_associative_array() override;
bool value(byte x) override;
bool value(std::byte x) override;
bool value(bool x) override;
......@@ -118,7 +118,7 @@ public:
bool value(const std::u32string& x) override;
bool value(span<const byte> x) override;
bool value(span<const std::byte> x) override;
private:
bool push(config_value&& x);
......
......@@ -10,7 +10,6 @@
#include <type_traits>
#include <utility>
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/fwd.hpp"
......@@ -127,7 +126,7 @@ public:
/// Reads `x` from the input.
/// @param x A reference to a builtin type.
/// @returns `true` on success, `false` otherwise.
virtual bool value(byte& x) = 0;
virtual bool value(std::byte& x) = 0;
/// @copydoc value
virtual bool value(bool& x) = 0;
......@@ -185,16 +184,16 @@ public:
/// @copydoc value
virtual bool value(std::u32string&) = 0;
/// Reads a byte sequence from the input.
/// @param x The byte sequence.
/// Reads a std::byte sequence from the input.
/// @param x The std::byte sequence.
/// @returns A non-zero error code on failure, `sec::success` otherwise.
virtual bool value(span<byte> x) = 0;
virtual bool value(span<std::byte> x) = 0;
using super::list;
/// Adds each boolean in `xs` to the output. Derived classes can override this
/// member function to pack the booleans, for example to avoid using one byte
/// for each value in a binary output format.
/// member function to pack the booleans, for example to avoid using one
/// std::byte for each value in a binary output format.
virtual bool list(std::vector<bool>& xs);
protected:
......
......@@ -4,10 +4,10 @@
#pragma once
#include <cstddef>
#include <memory>
#include <new>
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/padded_size.hpp"
......@@ -21,14 +21,16 @@ public:
/// Uses placement new to create a copy of the wrapped value at given memory
/// region.
/// @returns the past-the-end pointer of the object, i.e., the first byte for
/// @returns the past-the-end pointer of the object, i.e., the first std::byte
/// for
/// the *next* object.
virtual byte* copy_init(byte* storage) const = 0;
virtual std::byte* copy_init(std::byte* storage) const = 0;
/// Uses placement new to move the wrapped value to given memory region.
/// @returns the past-the-end pointer of the object, i.e., the first byte for
/// @returns the past-the-end pointer of the object, i.e., the first std::byte
/// for
/// the *next* object.
virtual byte* move_init(byte* storage) = 0;
virtual std::byte* move_init(std::byte* storage) = 0;
};
template <class T>
......@@ -38,12 +40,12 @@ public:
// nop
}
byte* copy_init(byte* storage) const override {
std::byte* copy_init(std::byte* storage) const override {
new (storage) T(value_);
return storage + padded_size_v<T>;
}
byte* move_init(byte* storage) override {
std::byte* move_init(std::byte* storage) override {
new (storage) T(std::move(value_));
return storage + padded_size_v<T>;
}
......
......@@ -5,10 +5,10 @@
#pragma once
#include <atomic>
#include <cstddef>
#include <cstdlib>
#include <new>
#include "caf/byte.hpp"
#include "caf/config.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/implicit_conversions.hpp"
......@@ -78,12 +78,12 @@ public:
}
/// Returns the memory region for storing the message elements.
byte* storage() noexcept {
std::byte* storage() noexcept {
return storage_;
}
/// @copydoc storage
const byte* storage() const noexcept {
const std::byte* storage() const noexcept {
return storage_;
}
......@@ -99,10 +99,10 @@ public:
/// Returns the memory location for the object at given index.
/// @pre `index < size()`
byte* at(size_t index) noexcept;
std::byte* at(size_t index) noexcept;
/// @copydoc at
const byte* at(size_t index) const noexcept;
const std::byte* at(size_t index) const noexcept;
void inc_constructed_elements() {
++constructed_elements_;
......@@ -113,41 +113,42 @@ public:
init_impl(storage(), std::forward<Ts>(xs)...);
}
byte* stepwise_init(byte* pos) {
std::byte* stepwise_init(std::byte* pos) {
return pos;
}
template <class T, class... Ts>
byte* stepwise_init(byte* pos, T&& x, Ts&&... xs) {
std::byte* stepwise_init(std::byte* pos, T&& x, Ts&&... xs) {
using type = strip_and_convert_t<T>;
new (pos) type(std::forward<T>(x));
++constructed_elements_;
return stepwise_init(pos + padded_size_v<type>, std::forward<Ts>(xs)...);
}
byte* stepwise_init_from(byte* pos, const message& msg);
std::byte* stepwise_init_from(std::byte* pos, const message& msg);
byte* stepwise_init_from(byte* pos, const message_data* other);
std::byte* stepwise_init_from(std::byte* pos, const message_data* other);
template <class Tuple, size_t... Is>
byte* stepwise_init_from(byte* pos, Tuple&& tup, std::index_sequence<Is...>) {
std::byte*
stepwise_init_from(std::byte* pos, Tuple&& tup, std::index_sequence<Is...>) {
return stepwise_init(pos, std::get<Is>(std::forward<Tuple>(tup))...);
}
template <class... Ts>
byte* stepwise_init_from(byte* pos, std::tuple<Ts...>&& tup) {
std::byte* stepwise_init_from(std::byte* pos, std::tuple<Ts...>&& tup) {
return stepwise_init_from(pos, std::move(tup),
std::make_index_sequence<sizeof...(Ts)>{});
}
template <class... Ts>
byte* stepwise_init_from(byte* pos, std::tuple<Ts...>& tup) {
std::byte* stepwise_init_from(std::byte* pos, std::tuple<Ts...>& tup) {
return stepwise_init_from(pos, tup,
std::make_index_sequence<sizeof...(Ts)>{});
}
template <class... Ts>
byte* stepwise_init_from(byte* pos, const std::tuple<Ts...>& tup) {
std::byte* stepwise_init_from(std::byte* pos, const std::tuple<Ts...>& tup) {
return stepwise_init_from(pos, tup,
std::make_index_sequence<sizeof...(Ts)>{});
}
......@@ -158,24 +159,24 @@ public:
}
private:
void init_impl(byte*) {
void init_impl(std::byte*) {
// End of recursion.
}
template <class T, class... Ts>
void init_impl(byte* storage, T&& x, Ts&&... xs) {
void init_impl(std::byte* storage, T&& x, Ts&&... xs) {
using type = strip_and_convert_t<T>;
new (storage) type(std::forward<T>(x));
++constructed_elements_;
init_impl(storage + padded_size_v<type>, std::forward<Ts>(xs)...);
}
void init_from_impl(byte*) {
void init_from_impl(std::byte*) {
// End of recursion.
}
template <class T, class... Ts>
void init_from_impl(byte* pos, T&& x, Ts&&... xs) {
void init_from_impl(std::byte* pos, T&& x, Ts&&... xs) {
init_from_impl(stepwise_init_from(pos, std::forward<T>(x)),
std::forward<Ts>(xs)...);
}
......@@ -183,7 +184,7 @@ private:
mutable std::atomic<size_t> rc_;
type_id_list types_;
size_t constructed_elements_;
byte storage_[];
std::byte storage_[];
};
// -- related non-members ------------------------------------------------------
......
......@@ -42,7 +42,7 @@ public:
bool end_sequence() override;
bool value(byte x) override;
bool value(std::byte x) override;
bool value(bool x) override;
......@@ -74,7 +74,7 @@ public:
bool value(const std::u32string& x) override;
bool value(span<const byte> x) override;
bool value(span<const std::byte> x) override;
using super::list;
......
......@@ -86,7 +86,7 @@ public:
return end_sequence();
}
bool value(byte x);
bool value(std::byte x);
bool value(bool x);
......@@ -114,7 +114,7 @@ public:
bool value(const std::u32string& x);
bool value(span<const byte> x);
bool value(span<const std::byte> x);
using super::list;
......
......@@ -957,9 +957,9 @@ CAF_ADD_TRIVIAL_INSPECTOR_VALUE(long double)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(std::u16string)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(std::u32string)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(std::vector<bool>)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(span<byte>)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(span<std::byte>)
CAF_ADD_TRIVIAL_SAVE_INSPECTOR_VALUE(span<const byte>)
CAF_ADD_TRIVIAL_SAVE_INSPECTOR_VALUE(span<const std::byte>)
CAF_ADD_TRIVIAL_LOAD_INSPECTOR_VALUE(std::string)
......@@ -995,12 +995,12 @@ struct is_builtin_inspector_type {
};
template <bool IsLoading>
struct is_builtin_inspector_type<byte, IsLoading> {
struct is_builtin_inspector_type<std::byte, IsLoading> {
static constexpr bool value = true;
};
template <bool IsLoading>
struct is_builtin_inspector_type<span<byte>, IsLoading> {
struct is_builtin_inspector_type<span<std::byte>, IsLoading> {
static constexpr bool value = true;
};
......@@ -1025,7 +1025,7 @@ struct is_builtin_inspector_type<string_view, false> {
};
template <>
struct is_builtin_inspector_type<span<const byte>, false> {
struct is_builtin_inspector_type<span<const std::byte>, false> {
static constexpr bool value = true;
};
......
......@@ -4,6 +4,7 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <memory>
#include <vector>
......@@ -179,7 +180,6 @@ config_option make_config_option(T& storage, string_view category,
// -- enums --------------------------------------------------------------------
enum class byte : uint8_t;
enum class exit_reason : uint8_t;
enum class invoke_message_result;
enum class pec : uint8_t;
......@@ -189,9 +189,10 @@ enum class stream_priority : uint8_t;
// -- aliases ------------------------------------------------------------------
using actor_id = uint64_t;
using byte_buffer = std::vector<byte>;
using byte_span = span<byte>;
using const_byte_span = span<const byte>;
using byte [[deprecated("Use `std::byte` instead")]] = std::byte;
using byte_buffer = std::vector<std::byte>;
using byte_span = span<std::byte>;
using const_byte_span = span<const std::byte>;
using ip_address = ipv6_address;
using ip_endpoint = ipv6_endpoint;
using ip_subnet = ipv6_subnet;
......
......@@ -4,10 +4,10 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include "caf/byte.hpp"
#include "caf/detail/ieee_754.hpp"
#include "caf/inspector_access.hpp"
#include "caf/save_inspector_base.hpp"
......@@ -112,7 +112,7 @@ public:
return true;
}
bool value(byte x) noexcept {
bool value(std::byte x) noexcept {
return value(static_cast<uint8_t>(x));
}
......@@ -135,7 +135,7 @@ public:
return true;
}
bool value(span<const byte> x) noexcept {
bool value(span<const std::byte> x) noexcept {
auto begin = reinterpret_cast<const uint8_t*>(x.data());
append(begin, begin + x.size());
return true;
......
......@@ -4,7 +4,6 @@
#pragma once
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/ieee_754.hpp"
#include "caf/save_inspector_base.hpp"
......@@ -13,6 +12,7 @@
#include "caf/type_id.hpp"
#include <array>
#include <cstddef>
#include <cstdint>
namespace caf::hash {
......@@ -27,7 +27,7 @@ public:
using super = save_inspector_base<sha1>;
/// Array type for storing a 160-bit hash.
using result_type = std::array<byte, hash_size>;
using result_type = std::array<std::byte, hash_size>;
sha1() noexcept;
......@@ -126,7 +126,7 @@ public:
return true;
}
bool value(span<const byte> x) noexcept {
bool value(span<const std::byte> x) noexcept {
auto begin = reinterpret_cast<const uint8_t*>(x.data());
append(begin, begin + x.size());
return true;
......
......@@ -169,7 +169,7 @@ public:
bool end_associative_array() override;
bool value(byte& x) override;
bool value(std::byte& x) override;
bool value(bool& x) override;
......@@ -201,7 +201,7 @@ public:
bool value(std::u32string& x) override;
bool value(span<byte> x) override;
bool value(span<std::byte> x) override;
private:
[[nodiscard]] position pos() const noexcept;
......
......@@ -143,7 +143,7 @@ public:
bool end_associative_array() override;
bool value(byte x) override;
bool value(std::byte x) override;
bool value(bool x) override;
......@@ -175,7 +175,7 @@ public:
bool value(const std::u32string& x) override;
bool value(span<const byte> x) override;
bool value(span<const std::byte> x) override;
private:
// -- implementation details -------------------------------------------------
......
......@@ -11,7 +11,6 @@
#include <type_traits>
#include <utility>
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/fwd.hpp"
......@@ -104,7 +103,7 @@ public:
/// Adds `x` to the output.
/// @param x A value for a builtin type.
/// @returns `true` on success, `false` otherwise.
virtual bool value(byte x) = 0;
virtual bool value(std::byte x) = 0;
/// @copydoc value
virtual bool value(bool x) = 0;
......@@ -157,16 +156,16 @@ public:
/// @copydoc value
virtual bool value(const std::u32string& x) = 0;
/// Adds `x` as raw byte block to the output.
/// @param x The byte sequence.
/// Adds `x` as raw std::byte block to the output.
/// @param x The std::byte sequence.
/// @returns A non-zero error code on failure, `sec::success` otherwise.
virtual bool value(span<const byte> x) = 0;
virtual bool value(span<const std::byte> x) = 0;
using super::list;
/// Adds each boolean in `xs` to the output. Derived classes can override this
/// member function to pack the booleans, for example to avoid using one byte
/// for each value in a binary output format.
/// member function to pack the booleans, for example to avoid using one
/// std::byte for each value in a binary output format.
virtual bool list(const std::vector<bool>& xs);
protected:
......
......@@ -5,9 +5,9 @@
#pragma once
#include <array>
#include <cstddef>
#include <type_traits>
#include "caf/byte.hpp"
#include "caf/detail/type_traits.hpp"
namespace caf {
......@@ -197,13 +197,13 @@ auto cend(const span<T>& xs) -> decltype(xs.cend()) {
}
template <class T>
span<const byte> as_bytes(span<T> xs) {
return {reinterpret_cast<const byte*>(xs.data()), xs.size_bytes()};
span<const std::byte> as_bytes(span<T> xs) {
return {reinterpret_cast<const std::byte*>(xs.data()), xs.size_bytes()};
}
template <class T>
span<byte> as_writable_bytes(span<T> xs) {
return {reinterpret_cast<byte*>(xs.data()), xs.size_bytes()};
span<std::byte> as_writable_bytes(span<T> xs) {
return {reinterpret_cast<std::byte*>(xs.data()), xs.size_bytes()};
}
/// Convenience function to make using `caf::span` more convenient without the
......
......@@ -38,8 +38,8 @@ struct sum_type_index {
template <class Trait, class T>
struct sum_type_index<Trait, T, true> {
static constexpr int value =
detail::tl_index_of<typename Trait::types, T>::value;
static constexpr int value
= detail::tl_index_of<typename Trait::types, T>::value;
};
template <class Trait, class T>
......@@ -48,7 +48,6 @@ make_sum_type_token() {
return {};
}
/// Returns a reference to the value of a sum type.
/// @pre `holds_alternative<T>(x)`
template <class T, class U, class Trait = sum_type_access<U>>
......@@ -60,7 +59,7 @@ auto get(U& x) -> decltype(Trait::get(x, make_sum_type_token<Trait, T>())) {
/// @pre `holds_alternative<T>(x)`
template <class T, class U, class Trait = sum_type_access<U>>
auto get(const U& x)
-> decltype(Trait::get(x, make_sum_type_token<Trait, T>())) {
-> decltype(Trait::get(x, make_sum_type_token<Trait, T>())) {
return Trait::get(x, make_sum_type_token<Trait, T>());
}
......@@ -68,7 +67,7 @@ auto get(const U& x)
/// `nullptr` otherwise.
template <class T, class U, class Trait = sum_type_access<U>>
auto get_if(U* x)
-> decltype(Trait::get_if(x, make_sum_type_token<Trait, T>())) {
-> decltype(Trait::get_if(x, make_sum_type_token<Trait, T>())) {
return Trait::get_if(x, make_sum_type_token<Trait, T>());
}
......@@ -76,7 +75,7 @@ auto get_if(U* x)
/// `nullptr` otherwise.
template <class T, class U, class Trait = sum_type_access<U>>
auto get_if(const U* x)
-> decltype(Trait::get_if(x, make_sum_type_token<Trait, T>())) {
-> decltype(Trait::get_if(x, make_sum_type_token<Trait, T>())) {
return Trait::get_if(x, make_sum_type_token<Trait, T>());
}
......@@ -99,8 +98,8 @@ struct sum_type_visit_result_impl<false, F, Ts...> {};
template <class F, class... Ts>
struct sum_type_visit_result
: sum_type_visit_result_impl<
detail::conjunction<SumType<Ts>()...>::value, F, Ts...> {};
: sum_type_visit_result_impl<detail::conjunction<SumType<Ts>()...>::value, F,
Ts...> {};
template <class F, class... Ts>
using sum_type_visit_result_t =
......@@ -129,7 +128,6 @@ struct visit_impl<Result, 0> {
}
};
template <class Result, size_t I, class Visitor>
struct visit_impl_continuation {
Visitor& f;
......
......@@ -5,11 +5,11 @@
#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>
#include "caf/byte.hpp"
#include "caf/detail/comparable.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/error.hpp"
......@@ -23,7 +23,7 @@ namespace caf {
/// can read all UUID versions, it can only create random-generated ones.
class CAF_CORE_EXPORT uuid : detail::comparable<uuid> {
public:
using array_type = std::array<byte, 16>;
using array_type = std::array<std::byte, 16>;
/// Creates the nil UUID with all 128 bits set to zero.
uuid() noexcept;
......
......@@ -84,7 +84,7 @@ void binary_deserializer::skip(size_t num_bytes) {
current_ += num_bytes;
}
void binary_deserializer::reset(span<const byte> bytes) noexcept {
void binary_deserializer::reset(span<const std::byte> bytes) noexcept {
current_ = bytes.data();
end_ = current_ + bytes.size();
}
......@@ -166,7 +166,7 @@ bool binary_deserializer::value(bool& x) noexcept {
return true;
}
bool binary_deserializer::value(byte& x) noexcept {
bool binary_deserializer::value(std::byte& x) noexcept {
if (range_check(1)) {
x = *current_++;
return true;
......@@ -240,7 +240,7 @@ bool binary_deserializer::value(long double& x) {
return false;
}
bool binary_deserializer::value(span<byte> x) noexcept {
bool binary_deserializer::value(span<std::byte> x) noexcept {
if (!range_check(x.size())) {
emplace_error(sec::end_of_stream);
return false;
......
......@@ -33,7 +33,7 @@ binary_serializer::binary_serializer(actor_system& sys,
void binary_serializer::skip(size_t num_bytes) {
auto remaining = buf_.size() - write_pos_;
if (remaining < num_bytes)
buf_.insert(buf_.end(), num_bytes - remaining, byte{0});
buf_.insert(buf_.end(), num_bytes - remaining, std::byte{0});
write_pos_ += num_bytes;
}
......@@ -103,7 +103,7 @@ bool binary_serializer::begin_field(string_view, bool is_present,
}
}
bool binary_serializer::value(span<const byte> x) {
bool binary_serializer::value(span<const std::byte> x) {
CAF_ASSERT(write_pos_ <= buf_.size());
auto buf_size = buf_.size();
if (write_pos_ == buf_size) {
......@@ -124,7 +124,7 @@ bool binary_serializer::value(span<const byte> x) {
return true;
}
bool binary_serializer::value(byte x) {
bool binary_serializer::value(std::byte x) {
if (write_pos_ == buf_.size())
buf_.emplace_back(x);
else
......@@ -138,11 +138,11 @@ bool binary_serializer::value(bool x) {
}
bool binary_serializer::value(int8_t x) {
return value(static_cast<byte>(x));
return value(static_cast<std::byte>(x));
}
bool binary_serializer::value(uint8_t x) {
return value(static_cast<byte>(x));
return value(static_cast<std::byte>(x));
}
bool binary_serializer::value(int16_t x) {
......
......@@ -459,11 +459,11 @@ bool pull(config_value_reader& reader, T& x) {
} // namespace
bool config_value_reader::value(byte& x) {
bool config_value_reader::value(std::byte& x) {
CHECK_NOT_EMPTY();
auto tmp = uint8_t{0};
if (pull(*this, tmp)) {
x = static_cast<byte>(tmp);
x = static_cast<std::byte>(tmp);
return true;
} else {
return false;
......@@ -545,7 +545,7 @@ bool config_value_reader::value(std::u32string&) {
return false;
}
bool config_value_reader::value(span<byte> bytes) {
bool config_value_reader::value(span<std::byte> bytes) {
CHECK_NOT_EMPTY();
std::string x;
if (!pull(*this, x))
......@@ -566,7 +566,7 @@ bool config_value_reader::value(span<byte> bytes) {
}
detail::parser::add_ascii<16>(value, c);
}
bytes[index / 2] = static_cast<byte>(value);
bytes[index / 2] = static_cast<std::byte>(value);
}
return true;
}
......
......@@ -313,7 +313,7 @@ bool config_value_writer::end_associative_array() {
return true;
}
bool config_value_writer::value(byte x) {
bool config_value_writer::value(std::byte x) {
return push(config_value{static_cast<config_value::integer>(x)});
}
......@@ -384,7 +384,7 @@ bool config_value_writer::value(const std::u32string&) {
return false;
}
bool config_value_writer::value(span<const byte> x) {
bool config_value_writer::value(span<const std::byte> x) {
std::string str;
detail::append_hex(str, x.data(), x.size());
return push(config_value{std::move(str)});
......
......@@ -75,7 +75,7 @@ message_data::make_uninitialized(type_id_list types) {
return {new (vptr) message_data(types), false};
}
byte* message_data::at(size_t index) noexcept {
std::byte* message_data::at(size_t index) noexcept {
if (index == 0)
return storage();
auto gmos = global_meta_objects();
......@@ -85,7 +85,7 @@ byte* message_data::at(size_t index) noexcept {
return ptr;
}
const byte* message_data::at(size_t index) const noexcept {
const std::byte* message_data::at(size_t index) const noexcept {
if (index == 0)
return storage();
auto gmos = global_meta_objects();
......@@ -95,11 +95,13 @@ const byte* message_data::at(size_t index) const noexcept {
return ptr;
}
byte* message_data::stepwise_init_from(byte* pos, const message& msg) {
std::byte* message_data::stepwise_init_from(std::byte* pos,
const message& msg) {
return stepwise_init_from(pos, msg.cptr());
}
byte* message_data::stepwise_init_from(byte* pos, const message_data* other) {
std::byte* message_data::stepwise_init_from(std::byte* pos,
const message_data* other) {
CAF_ASSERT(other != nullptr);
CAF_ASSERT(other != this);
auto gmos = global_meta_objects();
......
......@@ -89,7 +89,7 @@ bool serialized_size_inspector::end_sequence() {
return true;
}
bool serialized_size_inspector::value(byte x) {
bool serialized_size_inspector::value(std::byte x) {
result += sizeof(x);
return true;
}
......@@ -176,7 +176,7 @@ bool serialized_size_inspector::value(const std::u32string& x) {
return end_sequence();
}
bool serialized_size_inspector::value(span<const byte> x) {
bool serialized_size_inspector::value(span<const std::byte> x) {
result += x.size();
return true;
}
......
......@@ -73,8 +73,8 @@ bool stringification_inspector::end_sequence() {
return true;
}
bool stringification_inspector::value(byte x) {
return value(span<const byte>(&x, 1));
bool stringification_inspector::value(std::byte x) {
return value(span<const std::byte>(&x, 1));
}
bool stringification_inspector::value(bool x) {
......@@ -165,7 +165,7 @@ bool stringification_inspector::int_value(uint64_t x) {
return true;
}
bool stringification_inspector::value(span<const byte> x) {
bool stringification_inspector::value(span<const std::byte> x) {
sep();
detail::append_hex(result_, x.data(), x.size());
return true;
......
......@@ -72,7 +72,7 @@ std::string to_string(const error& x) {
auto append = [&result](const_void_ptr ptr,
const_meta_ptr meta) -> const_void_ptr {
meta->stringify(result, ptr);
return static_cast<const byte*>(ptr) + meta->padded_size;
return static_cast<const std::byte*>(ptr) + meta->padded_size;
};
auto code = x.code();
append(&code, detail::global_meta_object(x.category()));
......
......@@ -27,10 +27,10 @@ sha1::result_type sha1::result() noexcept {
length_ = 0;
sealed_ = true;
}
std::array<byte, sha1::hash_size> buf;
std::array<std::byte, sha1::hash_size> buf;
for (size_t i = 0; i < hash_size; ++i) {
auto tmp = intermediate_[i >> 2] >> 8 * (3 - (i & 0x03));
buf[i] = static_cast<byte>(tmp);
buf[i] = static_cast<std::byte>(tmp);
}
return buf;
}
......
......@@ -424,10 +424,10 @@ bool json_reader::end_associative_array() {
}
}
bool json_reader::value(byte& x) {
bool json_reader::value(std::byte& x) {
auto tmp = uint8_t{0};
if (value(tmp)) {
x = static_cast<byte>(tmp);
x = static_cast<std::byte>(tmp);
return true;
} else {
return false;
......@@ -601,9 +601,9 @@ bool json_reader::value(std::u32string&) {
return false;
}
bool json_reader::value(span<byte>) {
bool json_reader::value(span<std::byte>) {
emplace_error(sec::runtime_error, class_name, __func__,
"byte span support not implemented yet");
"std::byte span support not implemented yet");
return false;
}
......
......@@ -288,8 +288,8 @@ bool json_writer::end_associative_array() {
}
}
bool json_writer::value(byte x) {
return number(to_integer<uint8_t>(x));
bool json_writer::value(std::byte x) {
return number(static_cast<uint8_t>(x));
}
bool json_writer::value(bool x) {
......@@ -396,7 +396,7 @@ bool json_writer::value(const std::u32string&) {
return false;
}
bool json_writer::value(span<const byte> x) {
bool json_writer::value(span<const std::byte> x) {
switch (top()) {
case type::element:
add('"');
......
......@@ -48,13 +48,13 @@ public:
// nop
}
byte* copy_init(byte* storage) const override {
std::byte* copy_init(std::byte* storage) const override {
auto* meta = global_meta_object(src_.type_at(index_));
meta->copy_construct(storage, src_.data().at(index_));
return storage + meta->padded_size;
}
byte* move_init(byte* storage) override {
std::byte* move_init(std::byte* storage) override {
return copy_init(storage);
}
......
......@@ -20,7 +20,7 @@ namespace caf {
namespace {
byte nil_bytes[16];
std::byte nil_bytes[16];
} // namespace
......@@ -67,40 +67,40 @@ uuid::variant_field variant_table[] = {
} // namespace
uuid::variant_field uuid::variant() const noexcept {
return variant_table[to_integer<size_t>(bytes_[8]) >> 5];
return variant_table[static_cast<size_t>(bytes_[8]) >> 5];
}
uuid::version_field uuid::version() const noexcept {
return static_cast<version_field>(to_integer<int>(bytes_[6]) >> 4);
return static_cast<version_field>(static_cast<int>(bytes_[6]) >> 4);
}
uint64_t uuid::timestamp() const noexcept {
// Assemble octets like this (L = low, M = mid, H = high):
// 0H HH MM MM LL LL LL LL
byte ts[8];
std::byte ts[8];
memcpy(ts + 4, bytes_.data() + 0, 4);
memcpy(ts + 2, bytes_.data() + 4, 2);
memcpy(ts + 0, bytes_.data() + 6, 2);
ts[0] &= byte{0x0F};
ts[0] &= std::byte{0x0F};
uint64_t result;
memcpy(&result, ts, 8);
// UUIDs are stored in network byte order.
// UUIDs are stored in network std::byte order.
return detail::from_network_order(result);
}
uint16_t uuid::clock_sequence() const noexcept {
// Read clk_seq_(hi|low) fields and strip the variant bits.
byte cs[2];
std::byte cs[2];
memcpy(cs, bytes_.data() + 8, 2);
cs[0] &= byte{0x3F};
cs[0] &= std::byte{0x3F};
uint16_t result;
memcpy(&result, cs, 2);
// UUIDs are stored in network byte order.
// UUIDs are stored in network std::byte order.
return detail::from_network_order(result);
}
uint64_t uuid::node() const noexcept {
byte n[8];
std::byte n[8];
memset(n, 0, 2);
memcpy(n + 2, bytes_.data() + 10, 6);
uint64_t result;
......@@ -132,7 +132,7 @@ parse_result parse_impl(string_parser_state& ps, uuid::array_type& x) noexcept {
if (!isxdigit(c2) || !detail::parser::add_ascii<16>(value, c2))
return false;
ps.next();
*pos++ = static_cast<byte>(value);
*pos++ = static_cast<std::byte>(value);
return true;
};
// Parse the formatted string.
......@@ -153,7 +153,7 @@ parse_result parse_impl(string_parser_state& ps, uuid::array_type& x) noexcept {
// Check whether the bytes form a valid UUID.
if (memcmp(x.data(), nil_bytes, 16) == 0)
return valid_uuid;
if (auto subtype = to_integer<long>(x[6]) >> 4; subtype == 0 || subtype > 5)
if (auto subtype = static_cast<long>(x[6]) >> 4; subtype == 0 || subtype > 5)
return invalid_version;
return valid_uuid;
}
......@@ -173,9 +173,9 @@ uuid uuid::random(unsigned seed) noexcept {
std::uniform_int_distribution<> rng{0, 255};
uuid result;
for (size_t index = 0; index < 16; ++index)
result.bytes_[index] = static_cast<byte>(rng(engine));
result.bytes_[6] = (result.bytes_[6] & byte{0x0F}) | byte{0x50};
result.bytes_[8] = (result.bytes_[8] & byte{0x3F}) | byte{0x80};
result.bytes_[index] = static_cast<std::byte>(rng(engine));
result.bytes_[6] = (result.bytes_[6] & std::byte{0x0F}) | std::byte{0x50};
result.bytes_[8] = (result.bytes_[8] & std::byte{0x3F}) | std::byte{0x80};
return result;
}
......
......@@ -9,12 +9,12 @@
#include "core-test.hpp"
#include "nasty.hpp"
#include <cstddef>
#include <cstring>
#include <vector>
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/byte.hpp"
#include "caf/byte_buffer.hpp"
#include "caf/timestamp.hpp"
......@@ -22,12 +22,12 @@ using namespace caf;
namespace {
byte operator"" _b(unsigned long long int x) {
return static_cast<byte>(x);
std::byte operator"" _b(unsigned long long int x) {
return static_cast<std::byte>(x);
}
byte operator"" _b(char x) {
return static_cast<byte>(x);
std::byte operator"" _b(char x) {
return static_cast<std::byte>(x);
}
struct arr {
......@@ -44,14 +44,14 @@ bool inspect(Inspector& f, arr& x) {
struct fixture {
template <class... Ts>
void load(const std::vector<byte>& buf, Ts&... xs) {
void load(const std::vector<std::byte>& buf, Ts&... xs) {
binary_deserializer source{nullptr, buf};
if (!(source.apply(xs) && ...))
CAF_FAIL("binary_deserializer failed to load: " << source.get_error());
}
template <class T>
auto load(const std::vector<byte>& buf) {
auto load(const std::vector<std::byte>& buf) {
auto result = T{};
load(buf, result);
return result;
......@@ -166,14 +166,14 @@ CAF_TEST(binary serializer picks up inspect functions) {
10_b, 11_b, 12_b, 13_b, 14_b, 15_b, 16_b, 17_b, 18_b, 19_b);
}
SUBTEST("custom struct") {
test_data value{
-345,
-1234567890123456789ll,
3.45,
54.3,
caf::timestamp{caf::timestamp::duration{1478715821 * 1000000000ll}},
test_enum::b,
"Lorem ipsum dolor sit amet."};
test_data value{-345,
-1234567890123456789ll,
3.45,
54.3,
caf::timestamp{
caf::timestamp::duration{1478715821 * 1000000000ll}},
test_enum::b,
"Lorem ipsum dolor sit amet."};
CHECK_LOAD(test_data, value,
// 32-bit i32_ member: -345
0xFF_b, 0xFF_b, 0xFE_b, 0xA7_b,
......
......@@ -9,12 +9,12 @@
#include "core-test.hpp"
#include "nasty.hpp"
#include <cstddef>
#include <cstring>
#include <vector>
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/byte.hpp"
#include "caf/byte_buffer.hpp"
#include "caf/timestamp.hpp"
......@@ -22,12 +22,12 @@ using namespace caf;
namespace {
byte operator"" _b(unsigned long long int x) {
return static_cast<byte>(x);
std::byte operator"" _b(unsigned long long int x) {
return static_cast<std::byte>(x);
}
byte operator"" _b(char x) {
return static_cast<byte>(x);
std::byte operator"" _b(char x) {
return static_cast<std::byte>(x);
}
struct arr {
......@@ -165,13 +165,8 @@ CAF_TEST(binary serializer picks up inspect functions) {
}
SUBTEST("custom struct") {
caf::timestamp ts{caf::timestamp::duration{1478715821 * 1000000000ll}};
test_data value{-345,
-1234567890123456789ll,
3.45,
54.3,
ts,
test_enum::b,
"Lorem ipsum dolor sit amet."};
test_data value{-345, -1234567890123456789ll, 3.45, 54.3, ts,
test_enum::b, "Lorem ipsum dolor sit amet."};
CHECK_SAVE(test_data, value,
// 32-bit i32_ member: -345
0xFF_b, 0xFF_b, 0xFE_b, 0xA7_b,
......
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#define CAF_SUITE byte
#include "caf/byte.hpp"
#include "core-test.hpp"
#include <cstdint>
#include "caf/detail/parser/add_ascii.hpp"
#include "caf/raise_error.hpp"
using namespace caf;
namespace {
byte operator"" _b(const char* str, size_t n) {
size_t consumed = 0;
uint8_t result = 0;
for (size_t i = 0; i < n; ++i) {
if (str[i] != '\'') {
if (!detail::parser::add_ascii<2>(result, str[i]))
CAF_RAISE_ERROR(std::logic_error,
"invalid character or over-/underflow");
else
++consumed;
}
}
if (consumed != 8)
CAF_RAISE_ERROR(std::logic_error, "too few digits, expected exactly 8");
return static_cast<byte>(result);
}
struct fixture {
fixture() {
// Sanity checks.
if ("0001'1100"_b != static_cast<byte>(0x1C))
CAF_FAIL("operator \"\"_b broken");
if ("1000'0001"_b != static_cast<byte>(0x81))
CAF_FAIL("operator \"\"_b broken");
}
};
} // namespace
CAF_TEST_FIXTURE_SCOPE(byte_tests, fixture)
CAF_TEST(to integer) {
CAF_CHECK_EQUAL(to_integer<int>("0110'1001"_b), 0x69);
}
CAF_TEST(left shift) {
auto x = "0000'0001"_b;
x <<= 1;
CAF_CHECK_EQUAL(x, "0000'0010"_b);
CAF_CHECK_EQUAL("0000'0010"_b << 1, "0000'0100"_b);
CAF_CHECK_EQUAL("0000'0010"_b << 2, "0000'1000"_b);
CAF_CHECK_EQUAL("0000'0010"_b << 3, "0001'0000"_b);
CAF_CHECK_EQUAL("0000'0010"_b << 4, "0010'0000"_b);
CAF_CHECK_EQUAL("0000'0010"_b << 5, "0100'0000"_b);
CAF_CHECK_EQUAL("0000'0010"_b << 6, "1000'0000"_b);
CAF_CHECK_EQUAL("0000'0010"_b << 7, "0000'0000"_b);
}
CAF_TEST(right shift) {
auto x = "0100'0000"_b;
x >>= 1;
CAF_CHECK_EQUAL(x, "0010'0000"_b);
CAF_CHECK_EQUAL("0100'0000"_b >> 1, "0010'0000"_b);
CAF_CHECK_EQUAL("0100'0000"_b >> 2, "0001'0000"_b);
CAF_CHECK_EQUAL("0100'0000"_b >> 3, "0000'1000"_b);
CAF_CHECK_EQUAL("0100'0000"_b >> 4, "0000'0100"_b);
CAF_CHECK_EQUAL("0100'0000"_b >> 5, "0000'0010"_b);
CAF_CHECK_EQUAL("0100'0000"_b >> 6, "0000'0001"_b);
CAF_CHECK_EQUAL("0100'0000"_b >> 7, "0000'0000"_b);
}
CAF_TEST(bitwise or) {
auto x = "0001'1110"_b;
x |= "0111'1000"_b;
CAF_CHECK_EQUAL(x, "0111'1110"_b);
CAF_CHECK_EQUAL("0001'1110"_b | "0111'1000"_b, "0111'1110"_b);
}
CAF_TEST(bitwise and) {
auto x = "0001'1110"_b;
x &= "0111'1000"_b;
CAF_CHECK_EQUAL(x, "0001'1000"_b);
CAF_CHECK_EQUAL("0001'1110"_b & "0111'1000"_b, "0001'1000"_b);
}
CAF_TEST(bitwise xor) {
auto x = "0001'1110"_b;
x ^= "0111'1000"_b;
CAF_CHECK_EQUAL(x, "0110'0110"_b);
CAF_CHECK_EQUAL("0001'1110"_b ^ "0111'1000"_b, "0110'0110"_b);
}
CAF_TEST(bitwise not) {
CAF_CHECK_EQUAL(~"0111'1110"_b, "1000'0001"_b);
}
CAF_TEST_FIXTURE_SCOPE_END()
......@@ -15,7 +15,7 @@ namespace {
template <class... Ts>
auto make_hash(Ts... xs) {
static_assert(sizeof...(Ts) == 20);
return hash::sha1::result_type{{static_cast<byte>(xs)...}};
return hash::sha1::result_type{{static_cast<std::byte>(xs)...}};
}
} // namespace
......
......@@ -187,10 +187,10 @@ struct testee : deserializer {
return true;
}
bool value(byte& x) override {
bool value(std::byte& x) override {
new_line();
log += "byte value";
x = byte{};
log += "std::byte value";
x = std::byte{};
return true;
}
......@@ -250,11 +250,11 @@ struct testee : deserializer {
return primitive_value(x);
}
bool value(span<byte> xs) override {
bool value(span<std::byte> xs) override {
new_line();
log += "caf::span<caf::byte> value";
log += "caf::span<caf::std::byte> value";
for (auto& x : xs)
x = byte{0};
x = std::byte{0};
return true;
}
};
......@@ -762,7 +762,7 @@ SCENARIO("load inspectors support std::byte") {
std::string baseline = R"_(
begin object anonymous
begin field v1
uint8_t value
std::byte value
end field
begin optional field v2
end field
......
......@@ -161,7 +161,7 @@ struct testee : serializer {
return true;
}
bool value(byte) override {
bool value(std::byte) override {
new_line();
log += "byte value";
return true;
......@@ -257,7 +257,7 @@ struct testee : serializer {
return true;
}
bool value(span<const byte>) override {
bool value(span<const std::byte>) override {
new_line();
log += "byte_span value";
return true;
......@@ -799,10 +799,10 @@ SCENARIO("save inspectors support std::byte") {
std::string baseline = R"_(
begin object anonymous
begin field v1
uint8_t value
byte value
end field
begin optional field v2
uint8_t value
byte value
end field
end object)_";
CHECK_EQ(f.log, baseline);
......
......@@ -28,7 +28,8 @@ uuid operator"" _uuid(const char* cstr, size_t cstr_len) {
for (size_t index = 0; index < 16; ++index) {
auto input_index = index * 2;
char buf[] = {str[input_index], str[input_index + 1], '\0'};
result.bytes().at(index) = static_cast<byte>(std::stoi(buf, nullptr, 16));
result.bytes().at(index)
= static_cast<std::byte>(std::stoi(buf, nullptr, 16));
}
return result;
}
......@@ -58,7 +59,7 @@ CAF_TEST_FIXTURE_SCOPE(uuid_tests, fixture)
CAF_TEST(default generated UUIDs have all 128 bits set to zero) {
uuid nil;
CAF_CHECK(!nil);
auto zero = [](byte x) { return to_integer<int>(x) == 0; };
auto zero = [](std::byte x) { return static_cast<int>(x) == 0; };
CAF_CHECK(std::all_of(nil.bytes().begin(), nil.bytes().end(), zero));
CAF_CHECK(nil == uuid::nil());
}
......
......@@ -38,7 +38,7 @@ class middleman;
///
/// Brokers do *not* operate on sockets or other platform-dependent
/// communication primitives. Instead, brokers use a `connection_handle`
/// to identify a reliable, end-to-end byte stream (e.g. a TCP connection)
/// to identify a reliable, end-to-end std::byte stream (e.g. a TCP connection)
/// and `accept_handle` to identify a communication endpoint others can
/// connect to via its port.
///
......@@ -145,7 +145,7 @@ public:
void write(connection_handle hdl, size_t bs, const void* buf);
/// Writes `buf` into the buffer for a given connection.
void write(connection_handle hdl, span<const byte> buf);
void write(connection_handle hdl, span<const std::byte> buf);
/// Sends the content of the buffer for a given connection.
void flush(connection_handle hdl);
......@@ -179,8 +179,8 @@ public:
/// Tries to connect to `host` on given `port` and creates
/// a new scribe describing the connection afterwards.
/// @returns The handle of the new `scribe` on success.
expected<connection_handle>
add_tcp_scribe(const std::string& host, uint16_t port);
expected<connection_handle> add_tcp_scribe(const std::string& host,
uint16_t port);
/// Moves the initialized `scribe` instance `ptr` from another broker to this
/// broker.
......@@ -207,8 +207,8 @@ public:
void add_datagram_servant(datagram_servant_ptr ptr);
/// Adds the `datagram_servant` under an additional `hdl`.
void
add_hdl_for_datagram_servant(datagram_servant_ptr ptr, datagram_handle hdl);
void add_hdl_for_datagram_servant(datagram_servant_ptr ptr,
datagram_handle hdl);
/// Creates and assigns a new `datagram_servant` from a given socket `fd`.
datagram_handle add_datagram_servant(network::native_socket fd);
......@@ -222,8 +222,8 @@ public:
/// Creates a new `datagram_servant` for the remote endpoint `host` and
/// `port`.
/// @returns The handle to the new `datagram_servant`.
expected<datagram_handle>
add_udp_datagram_servant(const std::string& host, uint16_t port);
expected<datagram_handle> add_udp_datagram_servant(const std::string& host,
uint16_t port);
/// Tries to open a local port and creates a `datagram_servant` managing it on
/// success. If `port == 0`, then the broker will ask the operating system to
......
......@@ -81,12 +81,12 @@ byte_buffer& abstract_broker::wr_buf(connection_handle hdl) {
void abstract_broker::write(connection_handle hdl, size_t bs, const void* buf) {
auto& out = wr_buf(hdl);
auto first = reinterpret_cast<const byte*>(buf);
auto first = reinterpret_cast<const std::byte*>(buf);
auto last = first + bs;
out.insert(out.end(), first, last);
}
void abstract_broker::write(connection_handle hdl, span<const byte> buf) {
void abstract_broker::write(connection_handle hdl, span<const std::byte> buf) {
write(hdl, buf.size(), buf.data());
}
......@@ -121,7 +121,7 @@ void abstract_broker::enqueue_datagram(datagram_handle hdl, byte_buffer buf) {
void abstract_broker::write(datagram_handle hdl, size_t bs, const void* buf) {
auto& out = wr_buf(hdl);
auto first = reinterpret_cast<const byte*>(buf);
auto first = reinterpret_cast<const std::byte*>(buf);
auto last = first + bs;
out.insert(out.end(), first, last);
}
......@@ -339,8 +339,8 @@ resumable::subtype_t abstract_broker::subtype() const {
return io_actor;
}
resumable::resume_result
abstract_broker::resume(execution_unit* ctx, size_t mt) {
resumable::resume_result abstract_broker::resume(execution_unit* ctx,
size_t mt) {
CAF_ASSERT(ctx != nullptr);
CAF_ASSERT(ctx == backend_);
return scheduled_actor::resume(ctx, mt);
......
......@@ -521,7 +521,7 @@ void instance::forward(execution_unit* ctx, const node_id& dest_node,
CAF_LOG_ERROR("unable to serialize BASP header:" << sink.get_error());
return;
}
sink.value(span<const byte>{payload.data(), payload.size()});
sink.value(span<const std::byte>{payload.data(), payload.size()});
flush(*path);
} else {
CAF_LOG_WARNING("cannot forward message, no route to destination");
......
......@@ -56,7 +56,7 @@ void datagram_handler::write(datagram_handle hdl, const void* buf,
size_t num_bytes) {
wr_offline_buf_.emplace_back();
wr_offline_buf_.back().first = hdl;
auto cbuf = reinterpret_cast<const byte*>(buf);
auto cbuf = reinterpret_cast<const std::byte*>(buf);
wr_offline_buf_.back().second.assign(
cbuf, cbuf + static_cast<ptrdiff_t>(num_bytes));
}
......
......@@ -46,7 +46,7 @@ void stream::configure_read(receive_policy::config config) {
void stream::write(const void* buf, size_t num_bytes) {
CAF_LOG_TRACE(CAF_ARG(num_bytes));
auto first = reinterpret_cast<const byte*>(buf);
auto first = reinterpret_cast<const std::byte*>(buf);
auto last = first + num_bytes;
wr_offline_buf_.insert(wr_offline_buf_.end(), first, last);
}
......
......@@ -119,8 +119,8 @@ scribe_ptr test_multiplexer::new_scribe(connection_handle hdl) {
return sptr;
}
expected<scribe_ptr>
test_multiplexer::new_tcp_scribe(const std::string& host, uint16_t port) {
expected<scribe_ptr> test_multiplexer::new_tcp_scribe(const std::string& host,
uint16_t port) {
CAF_LOG_TRACE(CAF_ARG(host) << CAF_ARG(port));
connection_handle hdl;
{ // lifetime scope of guard
......@@ -198,8 +198,8 @@ doorman_ptr test_multiplexer::new_doorman(accept_handle hdl, uint16_t port) {
return dptr;
}
expected<doorman_ptr>
test_multiplexer::new_tcp_doorman(uint16_t desired_port, const char*, bool) {
expected<doorman_ptr> test_multiplexer::new_tcp_doorman(uint16_t desired_port,
const char*, bool) {
CAF_LOG_TRACE(CAF_ARG(desired_port));
accept_handle hdl;
uint16_t port = 0;
......@@ -304,8 +304,8 @@ test_multiplexer::new_local_udp_endpoint(uint16_t desired_port, const char*,
return new_datagram_servant(hdl, port);
}
datagram_servant_ptr
test_multiplexer::new_datagram_servant(datagram_handle hdl, uint16_t port) {
datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
uint16_t port) {
CAF_LOG_TRACE(CAF_ARG(hdl));
class impl : public datagram_servant {
public:
......@@ -416,9 +416,9 @@ test_multiplexer::new_datagram_servant(datagram_handle hdl, uint16_t port) {
return dptr;
}
datagram_servant_ptr
test_multiplexer::new_datagram_servant(datagram_handle, const std::string&,
uint16_t) {
datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle,
const std::string&,
uint16_t) {
CAF_CRITICAL("This has no implementation in the test multiplexer");
}
......@@ -427,8 +427,9 @@ int64_t test_multiplexer::next_endpoint_id() {
}
bool test_multiplexer::is_known_port(uint16_t x) const {
auto pred1
= [&](const doorman_data_map::value_type& y) { return x == y.second.port; };
auto pred1 = [&](const doorman_data_map::value_type& y) {
return x == y.second.port;
};
auto pred2 = [&](const datagram_data_map::value_type& y) {
return x == y.second->port;
};
......@@ -438,8 +439,9 @@ bool test_multiplexer::is_known_port(uint16_t x) const {
}
bool test_multiplexer::is_known_handle(accept_handle x) const {
auto pred
= [&](const pending_doorman_map::value_type& y) { return x == y.second; };
auto pred = [&](const pending_doorman_map::value_type& y) {
return x == y.second;
};
return doorman_data_.count(x) > 0
|| std::any_of(doormen_.begin(), doormen_.end(), pred);
}
......@@ -887,7 +889,7 @@ bool test_multiplexer::read_data(datagram_handle hdl) {
CAF_ASSERT(to.second.capacity() > from.second.size());
to.second.resize(from.second.size());
std::transform(from.second.begin(), from.second.end(), to.second.begin(),
[](byte x) { return caf::to_integer<char>(x); });
[](std::byte x) { return static_cast<char>(x); });
data->vn_buf.pop_front();
auto sitr = datagram_data_.find(data->rd_buf.first);
if (sitr == datagram_data_.end()) {
......
......@@ -76,7 +76,7 @@ behavior peer_fun(broker* self, connection_handle hdl, const actor& buddy) {
self->configure_read(hdl, receive_policy::exactly(sizeof(type_id_t)));
auto write = [=](type_id_t type) {
auto& buf = self->wr_buf(hdl);
auto first = reinterpret_cast<byte*>(&type);
auto first = reinterpret_cast<std::byte*>(&type);
buf.insert(buf.end(), first, first + sizeof(type_id_t));
self->flush(hdl);
};
......
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