Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshalling cleanup #246 #247

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ namespace nil {
/// @brief endian_type used for serialization.
using endian_type = typename base_impl_type::endian_type;

/// @brief Version type
using version_type = typename base_impl_type::version_type;

/// @brief All the options provided to this class bundled into struct.
using parsed_options_type = ::nil::crypto3::marshalling::types::detail::options_parser<TOptions...>;

Expand Down Expand Up @@ -175,23 +172,6 @@ namespace nil {
base_impl_type::write_no_status(iter);
}

/// @brief Compile time check if this class is version dependent
static constexpr bool is_version_dependent() {
return parsed_options_type::has_custom_version_update || base_impl_type::is_version_dependent();
}

/// @brief Get version of the field.
/// @details Exists only if @ref nil::crypto3::marshalling::option::version_storage option has been provided.
version_type get_version() const {
return base_impl_type::get_version();
}

/// @brief Default implementation of version update.
/// @return @b true in case the field contents have changed, @b false otherwise
bool set_version(version_type version) {
return base_impl_type::set_version(version);
}

protected:
using base_impl_type::read_data;
using base_impl_type::write_data;
Expand All @@ -208,12 +188,6 @@ namespace nil {
static_assert(!parsed_options_type::has_fixed_size_storage,
"nil::crypto3::marshalling::option::fixed_size_storage option is not applicable to "
"crypto3::curve_element type");
static_assert(!parsed_options_type::has_custom_storage_type,
"nil::crypto3::marshalling::option::custom_storage_type option is not applicable to "
"crypto3::curve_element type");
static_assert(!parsed_options_type::has_orig_data_view,
"nil::crypto3::marshalling::option::orig_data_view option is not applicable to "
"crypto3::curve_element type");
};

/// @brief Equality comparison operator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ namespace nil {
/// @brief endian_type used for serialization.
using endian_type = typename base_impl_type::endian_type;

/// @brief Version type
using version_type = typename base_impl_type::version_type;

/// @brief All the options provided to this class bundled into struct.
using parsed_options_type = ::nil::crypto3::marshalling::types::detail::options_parser<TOptions...>;

Expand Down Expand Up @@ -243,23 +240,6 @@ namespace nil {
base_impl_type::write_no_status(iter);
}

/// @brief Compile time check if this class is version dependent
static constexpr bool is_version_dependent() {
return parsed_options_type::has_custom_version_update || base_impl_type::is_version_dependent();
}

/// @brief Get version of the field.
/// @details Exists only if @ref nil::crypto3::marshalling::option::version_storage option has been provided.
version_type get_version() const {
return base_impl_type::get_version();
}

/// @brief Default implementation of version update.
/// @return @b true in case the field contents have changed, @b false otherwise
bool set_version(version_type version) {
return base_impl_type::set_version(version);
}

protected:
using base_impl_type::read_data;
using base_impl_type::write_data;
Expand Down Expand Up @@ -297,9 +277,6 @@ namespace nil {
/// @brief endian_type used for serialization.
using endian_type = typename base_impl_type::endian_type;

/// @brief Version type
using version_type = typename base_impl_type::version_type;

/// @brief All the options provided to this class bundled into struct.
using parsed_options_type = ::nil::crypto3::marshalling::types::detail::options_parser<TOptions...>;

Expand Down Expand Up @@ -429,23 +406,6 @@ namespace nil {
base_impl_type::write_no_status(iter);
}

/// @brief Compile time check if this class is version dependent
static constexpr bool is_version_dependent() {
return parsed_options_type::has_custom_version_update || base_impl_type::is_version_dependent();
}

/// @brief Get version of the field.
/// @details Exists only if @ref nil::crypto3::marshalling::option::version_storage option has been provided.
version_type get_version() const {
return base_impl_type::get_version();
}

/// @brief Default implementation of version update.
/// @return @b true in case the field contents have changed, @b false otherwise
bool set_version(version_type version) {
return base_impl_type::set_version(version);
}

protected:
using base_impl_type::read_data;
using base_impl_type::write_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
// SOFTWARE.
//---------------------------------------------------------------------------//

#ifndef MARSHALLING_REPACK_NEW_HPP
#define MARSHALLING_REPACK_NEW_HPP
#ifndef MARSHALLING_PACK_HPP
#define MARSHALLING_PACK_HPP

#include <nil/marshalling/detail/repack_value.hpp>

Expand Down Expand Up @@ -287,4 +287,4 @@ namespace nil::crypto3 {
} // namespace marshalling
} // namespace nil

#endif // MARSHALLING_REPACK_NEW_HPP
#endif // MARSHALLING_PACK_HPP

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ namespace nil::crypto3 {
protected:
// Use big endian by default
using endian_type = nil::crypto3::marshalling::endian::big_endian;

// Use unsigned type by default for versioning
using version_type = unsigned;
};

template<typename TEndian, typename... TOptions>
Expand All @@ -52,12 +49,6 @@ namespace nil::crypto3 {
using endian_type = TEndian;
};

template<typename T, typename... TOptions>
class field_base<nil::crypto3::marshalling::option::version_type<T>, TOptions...> : public field_base<TOptions...> {
protected:
using version_type = T;
};

template<typename... TTuple, typename... TOptions>
class field_base<std::tuple<TTuple...>, TOptions...> : public field_base<TTuple..., TOptions...> { };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ namespace nil::crypto3 {
/// @ref nil::crypto3::marshalling::endian::little_endian
using endian_type = typename base_impl_type::endian_type;

/// @brief Version type
using version_type = typename base_impl_type::version_type;

/// @brief Default validity check
/// @details Always returns true, can be overriden by the derived class
/// @return Always @b true
Expand All @@ -70,20 +67,6 @@ namespace nil::crypto3 {
return false;
}

/// @brief Default check of whether the field is version dependent.
/// @return Always @b false.
static constexpr bool is_version_dependent() {
return false;
}

/// @brief Default version update functionality
/// @details Does nothing and returns false, can be overriden by the
/// derived class
/// @return Always @b false
static constexpr bool set_version(version_type) {
return false;
}

protected:
/// @brief Write data into the output buffer.
/// @details Use this function to write data to the the buffer
Expand Down
63 changes: 0 additions & 63 deletions crypto3/libs/marshalling/core/include/nil/marshalling/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <tuple>
#include <type_traits>
#include <limits>
#include <ratio>
#include <cstdint>
#include <cstddef>

Expand All @@ -49,25 +48,6 @@ namespace nil::crypto3 {
}

namespace option {
namespace detail {

template<typename T>
struct is_ratio_t {
static const bool value = false;
};

template<std::intmax_t TNum, std::intmax_t TDen>
struct is_ratio_t<std::ratio<TNum, TDen>> {
static const bool value = true;
};

template<typename T>
constexpr bool is_ratio() {
return is_ratio_t<T>::value;
}

} // namespace detail

// message/field_t common options

/// @brief options to specify endian.
Expand Down Expand Up @@ -101,23 +81,6 @@ namespace nil::crypto3 {
template<std::size_t TSize>
struct fixed_size_storage { };

/// @brief Set custom storage type for fields like nil::crypto3::marshalling::types::string or
/// nil::crypto3::marshalling::types::array_list.
/// @details By default nil::crypto3::marshalling::types::string uses
/// <a href="http://en.cppreference.com/w/cpp/string/basic_string">std::string</a>
/// and nil::crypto3::marshalling::types::array_list uses
/// <a href="http://en.cppreference.com/w/cpp/container/vector">std::vector</a> as
/// their internal storage types. The @ref fixed_size_storage option forces
/// them to use nil::crypto3::marshalling::container::static_string and
/// nil::crypto3::marshalling::container::static_vector instead. This option can be used to provide any other
/// third party type. Such type must define the same public interface as @b std::string (when used with
/// nil::crypto3::marshalling::types::string) or @b std::vector (when used with
/// nil::crypto3::marshalling::types::array_list).
/// @tparam TType Custom storage type
/// @headerfile nil/marshalling/options.hpp
template<typename TType>
struct custom_storage_type { };

/// @brief Option that modifies the default behaviour of collection fields to
/// prepend the serialized data with number of @b elements information.
/// @details Quite often when collection of fields is serialized it must be
Expand Down Expand Up @@ -156,32 +119,6 @@ namespace nil::crypto3 {
/// @headerfile nil/marshalling/options.hpp
struct sequence_fixed_size_use_fixed_size_storage { };

/// @brief Use "view" on original raw data instead of copying it.
/// @details Can be used with @ref nil::crypto3::marshalling::types::string and raw data @ref
/// nil::crypto3::marshalling::types::array_list,
/// will force usage of @ref nil::crypto3::marshalling::container::string_view and
/// nil::crypto3::marshalling::container::array_view respectively as data storage type.
/// @note The original data must be preserved until destruction of the field
/// that uses the "view".
/// @note Incompatible with other options that contol data storage type,
/// such as @ref nil::crypto3::marshalling::option::custom_storage_type or @ref
/// nil::crypto3::marshalling::option::fixed_size_storage
/// @headerfile nil/marshalling/options.hpp
struct orig_data_view { };

/// @brief Provide type to be used for versioning
/// @tparam T Type of the version value. Expected to be unsigned integral one.
template<typename T>
struct version_type {
static_assert(std::is_integral<T>::value, "Only unsigned integral types are supported for versions");
static_assert(std::is_unsigned<T>::value, "Only unsigned integral types are supported for versions");
};

/// @brief Mark this class to have custom
/// implementation of version update functionality.
/// @headerfile nil/marshalling/options.hpp
struct has_custom_version_update { };

} // namespace option
} // namespace marshalling
} // namespace nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ namespace nil::crypto3 {
using base_impl_type = TBase;
using size_field_type = TSizeField;

static_assert(!size_field_type::is_version_dependent(),
"Prefix fields must not be version dependent");

public:
using value_type = typename base_impl_type::value_type;
using element_type = typename base_impl_type::element_type;
Expand Down
Loading
Loading