Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaim committed Feb 8, 2024
1 parent c3e0bc8 commit 3411908
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 91 deletions.
102 changes: 102 additions & 0 deletions cpp/arcticdb/entity/types_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<arcticdb::proto::descriptors::TypeDescriptor_SizeBits>(
static_cast<std::uint8_t>(slice_bit_size(data_type))));
type_desc.set_value_type(
static_cast<arcticdb::proto::descriptors::TypeDescriptor_ValueType>(
static_cast<std::uint8_t>(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<std::uint32_t>(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<ValueType>(static_cast<uint8_t>(type_desc.value_type())),
static_cast<SizeBits>(static_cast<uint8_t>(type_desc.size_bits()))
);
}

TypeDescriptor type_desc_from_proto(const arcticdb::proto::descriptors::TypeDescriptor& type_desc) {
return {
combine_data_type(
static_cast<ValueType>(static_cast<uint8_t>(type_desc.value_type())),
static_cast<SizeBits>(static_cast<uint8_t>(type_desc.size_bits()))
),
static_cast<Dimension>(static_cast<uint8_t>(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<uint32_t>(dim));
output_desc->set_size_bits(static_cast<arcticdb::proto::descriptors::TypeDescriptor_SizeBits>(
static_cast<std::uint8_t>(slice_bit_size(dt))));

output_desc->set_value_type(
static_cast<arcticdb::proto::descriptors::TypeDescriptor_ValueType>(
static_cast<std::uint8_t>(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<decltype(arg)>;
if constexpr (std::is_same_v<IdType, NumericId>)
pb_desc.set_num_id(arg);
else if constexpr (std::is_same_v<IdType, StringId>)
pb_desc.set_str_id(arg);
else
util::raise_rte("Encoding unknown descriptor type");
}, id);
}

} // namespace arcticdb
100 changes: 9 additions & 91 deletions cpp/arcticdb/entity/types_proto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<arcticdb::proto::descriptors::TypeDescriptor_SizeBits>(
static_cast<std::uint8_t>(slice_bit_size(data_type))));
type_desc.set_value_type(
static_cast<arcticdb::proto::descriptors::TypeDescriptor_ValueType>(
static_cast<std::uint8_t>(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<std::uint32_t>(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<ValueType>(static_cast<uint8_t>(type_desc.value_type())),
static_cast<SizeBits>(static_cast<uint8_t>(type_desc.size_bits()))
);
}

inline TypeDescriptor type_desc_from_proto(const arcticdb::proto::descriptors::TypeDescriptor& type_desc) {
return {
combine_data_type(
static_cast<ValueType>(static_cast<uint8_t>(type_desc.value_type())),
static_cast<SizeBits>(static_cast<uint8_t>(type_desc.size_bits()))
),
static_cast<Dimension>(static_cast<uint8_t>(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<uint32_t>(dim));
output_desc->set_size_bits(static_cast<arcticdb::proto::descriptors::TypeDescriptor_SizeBits>(
static_cast<std::uint8_t>(slice_bit_size(dt))));

output_desc->set_value_type(
static_cast<arcticdb::proto::descriptors::TypeDescriptor_ValueType>(
static_cast<std::uint8_t>(slice_value_type(dt))));

return output;
}
arcticdb::proto::descriptors::StreamDescriptor_FieldDescriptor field_proto(DataType dt, Dimension dim, std::string_view name);



Expand Down Expand Up @@ -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();
}
};
Expand All @@ -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<decltype(arg)>;
if constexpr (std::is_same_v<IdType, NumericId>)
pb_desc.set_num_id(arg);
else if constexpr (std::is_same_v<IdType, StringId>)
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

Expand Down

0 comments on commit 3411908

Please sign in to comment.