Commit 077e7d46 authored by Matthias Vallentin's avatar Matthias Vallentin

Remove obsolete packing of error internals

parent 61a8ad5c
......@@ -32,18 +32,9 @@ namespace caf {
/// A serializable type for storing error codes with category and optional,
/// human-readable context information. Unlike error handling classes from
/// the C++ standard library, this type is serializable and
/// optimized for (on-the-wire) size. Note, error codes are limited to 255
/// and the string for storing context information is limited to
/// 8,388,608 characters.
///
/// # Design goals
///
/// The error type in CAF is meant to allow efficient packing of errors
/// on the wire. For this purpose, CAF limits the error code to 255 to allow
/// storing the context size along the code in a 32-bit integer (1 bit
/// invaldity flag, 23 bit context size, 8 bit code; if the validity flag is 1,
/// then the error is invalid and has no category).
/// the C++ standard library, this type is serializable. It consists of an
/// 8-bit code, a 64-bit atom constant, plus optionally a ::message to store
/// additional information.
///
/// # Why not `std::error_code` or `std::error_condition`?
///
......@@ -53,13 +44,15 @@ namespace caf {
/// same operating system and version of the C++ standard library.
///
/// Second, the standard library primitives, unlike exceptions, do not offer
/// an API for storing additional context to an error. The error handling API
/// offered by the standard is meant to wrap C system calls and defines
/// in a (source code) portable way. In a distributed setting, an error does
/// not occur locally. Error code and category often are simply not
/// satisfactory information when signalling errors back to end users.
/// an API for attaching additional context to an error. The error handling API
/// offered by the standard is meant to wrap C system calls in a (source code)
/// portable way. In a distributed setting, an error may not occur locally.
/// In this case, an error code and category alone is often not satisfactory
/// information when signalling errors back to end users. The additional
/// context also enables *composition* of errors by modifying the message
/// details as needed.
///
/// # Why is there no `message()` member function?
/// # Why is there no `string()` member function?
///
/// The C++ standard library uses category singletons and virtual dispatching
/// to correlate error codes to descriptive strings. However, singletons are
......
......@@ -56,41 +56,12 @@ void error::clear() {
code_ = 0;
}
uint32_t error::compress_code_and_size() const {
auto res = static_cast<uint32_t>(context_.size());
res <<= 8;
res |= static_cast<uint32_t>(code_);
return res;
}
void serialize(serializer& sink, error& x, const unsigned int) {
auto flag_size_and_code = x.compress_code_and_size();
if (x.category_ == atom("") || x.code_ == 0) {
flag_size_and_code |= 0x80000000;
sink << flag_size_and_code;
return;
}
sink << flag_size_and_code;
sink << x.category_;
if (! x.context_.empty())
sink << x.context_;
//sink.apply_raw(x.context_.size(), const_cast<char*>(x.context_.data()));
sink << x.code_ << x.category_ << x.context_;
}
void serialize(deserializer& source, error& x, const unsigned int) {
x.context_.reset();
uint32_t flag_size_and_code;
source >> flag_size_and_code;
if (flag_size_and_code & 0x80000000) {
x.category_ = atom("");
x.code_ = 0;
return;
}
source >> x.category_;
x.code_ = static_cast<uint8_t>(flag_size_and_code & 0xFF);
auto size = flag_size_and_code >> 8;
if (size > 0)
source >> x.context_;
source >> x.code_ >> x.category_ >> x.context_;
}
int error::compare(uint8_t x, atom_value y) const {
......
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