diff --git a/cpp/arcticdb/entity/types_proto.cpp b/cpp/arcticdb/entity/types_proto.cpp index 10a385892a9..5fd69d7e8ad 100644 --- a/cpp/arcticdb/entity/types_proto.cpp +++ b/cpp/arcticdb/entity/types_proto.cpp @@ -21,4 +21,106 @@ namespace arcticdb::entity { } + + arcticdb::proto::descriptors::SortedValue sorted_value_to_proto(SortedValue sorted) { + switch (sorted) { + case SortedValue::UNSORTED: + return arcticdb::proto::descriptors::SortedValue::UNSORTED; + case SortedValue::DESCENDING: + return arcticdb::proto::descriptors::SortedValue::DESCENDING; + case SortedValue::ASCENDING: + return arcticdb::proto::descriptors::SortedValue::ASCENDING; + default: + return arcticdb::proto::descriptors::SortedValue::UNKNOWN; + } + } + + SortedValue sorted_value_from_proto(arcticdb::proto::descriptors::SortedValue sorted_proto) { + switch (sorted_proto) { + case arcticdb::proto::descriptors::SortedValue::UNSORTED: + return SortedValue::UNSORTED; + case arcticdb::proto::descriptors::SortedValue::DESCENDING: + return SortedValue::DESCENDING; + case arcticdb::proto::descriptors::SortedValue::ASCENDING: + return SortedValue::ASCENDING; + default: + return SortedValue::UNKNOWN; + } + } + + + void set_data_type(DataType data_type, arcticdb::proto::descriptors::TypeDescriptor& type_desc) { + type_desc.set_size_bits( + static_cast( + static_cast(slice_bit_size(data_type)))); + type_desc.set_value_type( + static_cast( + static_cast(slice_value_type(data_type)))); + } + + + [[nodiscard]] + auto to_proto(const TypeDescriptor& desc) + -> arcticdb::proto::descriptors::TypeDescriptor + { + arcticdb::proto::descriptors::TypeDescriptor output; + output.set_dimension(static_cast(desc.dimension_)); + set_data_type(desc.data_type_, output); + + return output; + } + + + + DataType get_data_type(const arcticdb::proto::descriptors::TypeDescriptor& type_desc) { + return combine_data_type( + static_cast(static_cast(type_desc.value_type())), + static_cast(static_cast(type_desc.size_bits())) + ); + } + + TypeDescriptor type_desc_from_proto(const arcticdb::proto::descriptors::TypeDescriptor& type_desc) { + return { + combine_data_type( + static_cast(static_cast(type_desc.value_type())), + static_cast(static_cast(type_desc.size_bits())) + ), + static_cast(static_cast(type_desc.dimension())) + }; + } + + DataType data_type_from_proto(const arcticdb::proto::descriptors::TypeDescriptor& type_desc) { + return type_desc_from_proto(type_desc).data_type(); + } + + + arcticdb::proto::descriptors::StreamDescriptor_FieldDescriptor field_proto(DataType dt, Dimension dim, std::string_view name) { + arcticdb::proto::descriptors::StreamDescriptor_FieldDescriptor output; + if (!name.empty()) + output.set_name(name.data(), name.size()); + + auto output_desc = output.mutable_type_desc(); + output_desc->set_dimension(static_cast(dim)); + output_desc->set_size_bits(static_cast( + static_cast(slice_bit_size(dt)))); + + output_desc->set_value_type( + static_cast( + static_cast(slice_value_type(dt)))); + + return output; + } + + void set_id(arcticdb::proto::descriptors::StreamDescriptor& pb_desc, StreamId id) { + std::visit([&pb_desc](auto&& arg) { + using IdType = std::decay_t; + if constexpr (std::is_same_v) + pb_desc.set_num_id(arg); + else if constexpr (std::is_same_v) + pb_desc.set_str_id(arg); + else + util::raise_rte("Encoding unknown descriptor type"); + }, id); + } + } // namespace arcticdb diff --git a/cpp/arcticdb/entity/types_proto.hpp b/cpp/arcticdb/entity/types_proto.hpp index 62a36132635..fe993be9a4f 100644 --- a/cpp/arcticdb/entity/types_proto.hpp +++ b/cpp/arcticdb/entity/types_proto.hpp @@ -24,94 +24,22 @@ namespace arcticdb::entity { - inline arcticdb::proto::descriptors::SortedValue sorted_value_to_proto(SortedValue sorted) { - switch (sorted) { - case SortedValue::UNSORTED: - return arcticdb::proto::descriptors::SortedValue::UNSORTED; - case SortedValue::DESCENDING: - return arcticdb::proto::descriptors::SortedValue::DESCENDING; - case SortedValue::ASCENDING: - return arcticdb::proto::descriptors::SortedValue::ASCENDING; - default: - return arcticdb::proto::descriptors::SortedValue::UNKNOWN; - } - } - - inline SortedValue sorted_value_from_proto(arcticdb::proto::descriptors::SortedValue sorted_proto) { - switch (sorted_proto) { - case arcticdb::proto::descriptors::SortedValue::UNSORTED: - return SortedValue::UNSORTED; - case arcticdb::proto::descriptors::SortedValue::DESCENDING: - return SortedValue::DESCENDING; - case arcticdb::proto::descriptors::SortedValue::ASCENDING: - return SortedValue::ASCENDING; - default: - return SortedValue::UNKNOWN; - } - } + arcticdb::proto::descriptors::SortedValue sorted_value_to_proto(SortedValue sorted); + SortedValue sorted_value_from_proto(arcticdb::proto::descriptors::SortedValue sorted_proto); - inline void set_data_type(DataType data_type, arcticdb::proto::descriptors::TypeDescriptor& type_desc) { - type_desc.set_size_bits( - static_cast( - static_cast(slice_bit_size(data_type)))); - type_desc.set_value_type( - static_cast( - static_cast(slice_value_type(data_type)))); - } + void set_data_type(DataType data_type, arcticdb::proto::descriptors::TypeDescriptor& type_desc); - [[nodiscard]] - inline auto to_proto(const TypeDescriptor& desc) - -> arcticdb::proto::descriptors::TypeDescriptor - { - arcticdb::proto::descriptors::TypeDescriptor output; - output.set_dimension(static_cast(desc.dimension_)); - set_data_type(desc.data_type_, output); - return output; - } + DataType get_data_type(const arcticdb::proto::descriptors::TypeDescriptor& type_desc); + TypeDescriptor type_desc_from_proto(const arcticdb::proto::descriptors::TypeDescriptor& type_desc); + DataType data_type_from_proto(const arcticdb::proto::descriptors::TypeDescriptor& type_desc); - inline DataType get_data_type(const arcticdb::proto::descriptors::TypeDescriptor& type_desc) { - return combine_data_type( - static_cast(static_cast(type_desc.value_type())), - static_cast(static_cast(type_desc.size_bits())) - ); - } - inline TypeDescriptor type_desc_from_proto(const arcticdb::proto::descriptors::TypeDescriptor& type_desc) { - return { - combine_data_type( - static_cast(static_cast(type_desc.value_type())), - static_cast(static_cast(type_desc.size_bits())) - ), - static_cast(static_cast(type_desc.dimension())) - }; - } - - inline DataType data_type_from_proto(const arcticdb::proto::descriptors::TypeDescriptor& type_desc) { - return type_desc_from_proto(type_desc).data_type(); - } - - - inline arcticdb::proto::descriptors::StreamDescriptor_FieldDescriptor field_proto(DataType dt, Dimension dim, std::string_view name) { - arcticdb::proto::descriptors::StreamDescriptor_FieldDescriptor output; - if (!name.empty()) - output.set_name(name.data(), name.size()); - - auto output_desc = output.mutable_type_desc(); - output_desc->set_dimension(static_cast(dim)); - output_desc->set_size_bits(static_cast( - static_cast(slice_bit_size(dt)))); - - output_desc->set_value_type( - static_cast( - static_cast(slice_value_type(dt)))); - - return output; - } + arcticdb::proto::descriptors::StreamDescriptor_FieldDescriptor field_proto(DataType dt, Dimension dim, std::string_view name); @@ -160,7 +88,7 @@ namespace arcticdb::entity { ARCTICDB_MOVE_COPY_DEFAULT(IndexDescriptor) - friend bool operator==(const IndexDescriptor& left, const IndexDescriptor& right) { + friend bool operator==(const IndexDescriptor& left, const IndexDescriptor& right) { return left.type() == right.type(); } }; @@ -185,17 +113,7 @@ namespace arcticdb::entity { } } - inline void set_id(arcticdb::proto::descriptors::StreamDescriptor& pb_desc, StreamId id) { - std::visit([&pb_desc](auto&& arg) { - using IdType = std::decay_t; - if constexpr (std::is_same_v) - pb_desc.set_num_id(arg); - else if constexpr (std::is_same_v) - pb_desc.set_str_id(arg); - else - util::raise_rte("Encoding unknown descriptor type"); - }, id); - } + void set_id(arcticdb::proto::descriptors::StreamDescriptor& pb_desc, StreamId id); } // namespace arcticdb::entity