Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ endif()

include(GNUInstallDirs)

install(TARGETS scale buffer EXPORT scaleConfig
install(TARGETS scale buffer scale_encode_append EXPORT scaleConfig
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ It allows encoding and decoding following data types:
* bool values
* pairs of types represented by ```std::pair<T1, T2>```
* compact integers represented by CompactInteger type
* optional values represented by ```boost::optional<T>```
* as special case of optional values ```boost::optional<bool>``` is encoded using one byte following specification.
* optional values represented by ```std::optional<T>```
* as special case of optional values ```std::optional<bool>``` is encoded using one byte following specification.
* collections of items represented by ```std::vector<T>```
* variants represented by ```boost::variant<T...>```

Expand All @@ -26,8 +26,8 @@ auto * raw_str = "zxczxczx";
bool b = true;
CompactInteger ci = 123456789;
boost::variant<uint8_t, uint32_t, CompactInteger> vint = CompactInteger(12345);
boost::optional<std::string> opt_str = "asdfghjkl";
boost::optional<bool> opt_bool = false;
std::optional<std::string> opt_str = "asdfghjkl";
std::optional<bool> opt_bool = false;
std::pair<uint8_t, uint32_t> pair{1u, 2u};
std::vector<uint32_t> coll_ui32 = {1u, 2u, 3u, 4u};
std::vector<std::string> coll_str = {"asd", "fgh", "jkl"};
Expand Down Expand Up @@ -58,8 +58,8 @@ std::string str;
bool b = true;
CompactInteger ci;
boost::variant<uint8_t, uint32_t, CompactInteger> vint;
boost::optional<std::string> opt_str;
boost::optional<bool> opt_bool;
std::optional<std::string> opt_str;
std::optional<bool> opt_bool;
std::pair<uint8_t, uint32_t> pair{};
std::vector<uint32_t> coll_ui32;
std::vector<std::string> coll_str;
Expand Down
16 changes: 8 additions & 8 deletions include/scale/encode_append.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ namespace scale {
}

/**
* Adds to scale encoded vector of EncodeOpaqueValue another
* EncodeOpaqueValue. If current vector is empty, then it is replaced by new
* Adds an EncodeOpaqueValue to a scale encoded vector of EncodeOpaqueValue's.
* If the current vector is empty, then it is replaced by a new
* EncodeOpaqueValue
* In other words what actually happens could be implemented like that:
* In other words, what actually happens could be implemented like that:
* @code{.cpp}
* auto vec = scale::decode<vector<EncodeOpaqueValue>>(self_encoded);
* vec.push_back(scale::encode(EncodeOpaqueValue(input));
* self_encoded = scale::encode(vec);
* @endcode
* but actual implementation a bit more optimal
* @param self_encoded Current encoded vector of EncodeOpaqueValue
* @param input is a vector, that is encoded as EncodeOpaqueValue and added to
* @param self_encoded
* @return success input was appended to self_encoded, failure otherwise
* but the actual implementation is a bit more optimal
* @param self_encoded - An encoded vector of EncodeOpaqueValue
* @param input - A vector encoded as an EncodeOpaqueValue and added to
* \param self_encoded
* @return success if input was appended to self_encoded, failure otherwise
*/
outcome::result<void> append_or_new_vec(std::vector<uint8_t> &self_encoded,
gsl::span<const uint8_t> input);
Expand Down
10 changes: 5 additions & 5 deletions include/scale/outcome/outcome-register.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define OUTCOME_USE_STD_IN_PLACE_TYPE 1

namespace __outcome_detail {
namespace scale::__outcome_detail {

template <typename T> class Category : public std::error_category {
public:
Expand Down Expand Up @@ -52,11 +52,11 @@ template <typename T> class Category : public std::error_category {
Category() = default;
}; /* end of class */

} // namespace __outcome_detail
} // namespace scale::__outcome_detail

#define __OUTCOME_DEFINE_MAKE_ERROR_CODE(Enum) \
extern std::error_code make_error_code(Enum e) { \
return {static_cast<int>(e), __outcome_detail::Category<Enum>::get()}; \
return {static_cast<int>(e), scale::__outcome_detail::Category<Enum>::get()}; \
}

#define __OUTCOME_DECLARE_MAKE_ERROR_CODE(Enum) \
Expand Down Expand Up @@ -87,14 +87,14 @@ template <typename T> class Category : public std::error_category {
__OUTCOME_DEFINE_MAKE_ERROR_CODE(Enum) \
}; \
template <> \
std::string __outcome_detail::Category<ns::Enum>::toString(ns::Enum Name)
std::string scale::__outcome_detail::Category<ns::Enum>::toString(ns::Enum Name)

/// MUST BE EXECUTED AT FILE LEVEL(global namespace) IN CPP
// Enum - enum name. Example: EncodeError
// Name - variable name. Example: e
#define OUTCOME_CPP_DEFINE_CATEGORY_2(Enum, Name) \
__OUTCOME_DEFINE_MAKE_ERROR_CODE(Enum) \
template <> std::string __outcome_detail::Category<Enum>::toString(Enum Name)
template <> std::string scale::__outcome_detail::Category<Enum>::toString(Enum Name)

// kind of "macro overloading"
#define __GET_MACRO_3(_1, _2, _3, NAME, ...) NAME
Expand Down
4 changes: 2 additions & 2 deletions include/scale/outcome/outcome.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

#include "outcome-register.hpp"

namespace outcome {
namespace scale::outcome {

using namespace BOOST_OUTCOME_V2_NAMESPACE;

template <class R, class S = std::error_code,
class NoValuePolicy = policy::default_policy<R, S, void>>
using result = basic_result<R, S, NoValuePolicy>;

} // namespace outcome
} // namespace scale::outcome

#define OUTCOME_TRY(...) BOOST_OUTCOME_TRY(__VA_ARGS__)

Expand Down
2 changes: 1 addition & 1 deletion include/scale/outcome/outcome_throw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace scale {
* @param t error value
*/
template <typename T, typename = std::enable_if_t<std::is_enum_v<T>>>
[[noreturn]] void raise (T t) {
[[noreturn]] void raise(T t) {
std::error_code ec = make_error_code(t);
boost::throw_exception(std::system_error(ec));
}
Expand Down
Loading