diff --git a/include/ydb-cpp-sdk/client/table/table.h b/include/ydb-cpp-sdk/client/table/table.h index 5066619241..03832a2097 100644 --- a/include/ydb-cpp-sdk/client/table/table.h +++ b/include/ydb-cpp-sdk/client/table/table.h @@ -395,9 +395,13 @@ class TChangefeedDescription { const std::optional& GetInitialScanProgress() const; void SerializeTo(Ydb::Table::Changefeed& proto) const; + void SerializeTo(Ydb::Table::ChangefeedDescription& proto) const; std::string ToString() const; void Out(IOutputStream& o) const; + template + void SerializeCommonFields(TProto& proto) const; + private: explicit TChangefeedDescription(const Ydb::Table::Changefeed& proto); explicit TChangefeedDescription(const Ydb::Table::ChangefeedDescription& proto); diff --git a/src/client/table/table.cpp b/src/client/table/table.cpp index 7ca0df537a..8b2256200a 100644 --- a/src/client/table/table.cpp +++ b/src/client/table/table.cpp @@ -2817,10 +2817,10 @@ TChangefeedDescription TChangefeedDescription::FromProto(const TProto& proto) { return ret; } -void TChangefeedDescription::SerializeTo(Ydb::Table::Changefeed& proto) const { +template +void TChangefeedDescription::SerializeCommonFields(TProto& proto) const { proto.set_name(TStringType{Name_}); proto.set_virtual_timestamps(VirtualTimestamps_); - proto.set_initial_scan(InitialScan_); proto.set_aws_region(TStringType{AwsRegion_}); switch (Mode_) { @@ -2861,12 +2861,35 @@ void TChangefeedDescription::SerializeTo(Ydb::Table::Changefeed& proto) const { SetDuration(*ResolvedTimestamps_, *proto.mutable_resolved_timestamps_interval()); } + for (const auto& [key, value] : Attributes_) { + (*proto.mutable_attributes())[key] = value; + } +} + +void TChangefeedDescription::SerializeTo(Ydb::Table::Changefeed& proto) const { + SerializeCommonFields(proto); + proto.set_initial_scan(InitialScan_); + if (RetentionPeriod_) { SetDuration(*RetentionPeriod_, *proto.mutable_retention_period()); } +} - for (const auto& [key, value] : Attributes_) { - (*proto.mutable_attributes())[key] = value; +void TChangefeedDescription::SerializeTo(Ydb::Table::ChangefeedDescription& proto) const { + SerializeCommonFields(proto); + + switch (State_) { + case EChangefeedState::Enabled: + proto.set_state(Ydb::Table::ChangefeedDescription_State::ChangefeedDescription_State_STATE_ENABLED); + break; + case EChangefeedState::Disabled: + proto.set_state(Ydb::Table::ChangefeedDescription_State::ChangefeedDescription_State_STATE_DISABLED); + break; + case EChangefeedState::InitialScan: + proto.set_state(Ydb::Table::ChangefeedDescription_State::ChangefeedDescription_State_STATE_INITIAL_SCAN); + break; + case EChangefeedState::Unknown: + break; } }