33
33
)
34
34
35
35
36
- class Codec (int , IToPublic ):
36
+ class Codec (int , IToPublic , IFromPublic ):
37
37
CODEC_UNSPECIFIED = 0
38
38
CODEC_RAW = 1
39
39
CODEC_GZIP = 2
@@ -47,9 +47,13 @@ def from_proto_iterable(codecs: typing.Iterable[int]) -> List["Codec"]:
47
47
def to_public (self ) -> ydb_topic_public_types .PublicCodec :
48
48
return ydb_topic_public_types .PublicCodec (int (self ))
49
49
50
+ @staticmethod
51
+ def from_public (codec : Union [ydb_topic_public_types .PublicCodec , int ]) -> "Codec" :
52
+ return Codec (int (codec ))
53
+
50
54
51
55
@dataclass
52
- class SupportedCodecs (IToProto , IFromProto , IToPublic ):
56
+ class SupportedCodecs (IToProto , IFromProto , IToPublic , IFromPublic ):
53
57
codecs : List [Codec ]
54
58
55
59
def to_proto (self ) -> ydb_topic_pb2 .SupportedCodecs :
@@ -69,6 +73,13 @@ def from_proto(msg: Optional[ydb_topic_pb2.SupportedCodecs]) -> "SupportedCodecs
69
73
def to_public (self ) -> List [ydb_topic_public_types .PublicCodec ]:
70
74
return list (map (Codec .to_public , self .codecs ))
71
75
76
+ @staticmethod
77
+ def from_public (codecs : Optional [List [Union [ydb_topic_public_types .PublicCodec , int ]]]) -> Optional ["SupportedCodecs" ]:
78
+ if codecs is None :
79
+ return None
80
+
81
+ return SupportedCodecs (codecs = [Codec .from_public (codec ) for codec in codecs ])
82
+
72
83
73
84
@dataclass (order = True )
74
85
class OffsetsRange (IFromProto , IToProto ):
@@ -886,17 +897,21 @@ def from_proto(
886
897
@dataclass
887
898
class AlterConsumer (IToProto , IFromPublic ):
888
899
name : str
889
- set_important : bool
890
- set_read_from : datetime .datetime
891
- set_supported_codecs : SupportedCodecs
892
- alter_attributes : Dict [str , str ]
900
+ set_important : Optional [ bool ]
901
+ set_read_from : Optional [ datetime .datetime ]
902
+ set_supported_codecs : Optional [ SupportedCodecs ]
903
+ alter_attributes : Optional [ Dict [str , str ] ]
893
904
894
905
def to_proto (self ) -> ydb_topic_pb2 .AlterConsumer :
906
+ supported_codecs = None
907
+ if self .set_supported_codecs is not None :
908
+ supported_codecs = self .set_supported_codecs .to_proto ()
909
+
895
910
return ydb_topic_pb2 .AlterConsumer (
896
911
name = self .name ,
897
912
set_important = self .set_important ,
898
913
set_read_from = proto_timestamp_from_datetime (self .set_read_from ),
899
- set_supported_codecs = self . set_supported_codecs . to_proto () ,
914
+ set_supported_codecs = supported_codecs ,
900
915
alter_attributes = self .alter_attributes ,
901
916
)
902
917
@@ -905,13 +920,11 @@ def from_public(alter_consumer: ydb_topic_public_types.PublicAlterConsumer) -> A
905
920
if not alter_consumer :
906
921
return None
907
922
908
- supported_codecs = alter_consumer .set_supported_codecs if alter_consumer .set_supported_codecs else []
909
-
910
923
return AlterConsumer (
911
924
name = alter_consumer .name ,
912
925
set_important = alter_consumer .set_important ,
913
926
set_read_from = alter_consumer .set_read_from ,
914
- set_supported_codecs = SupportedCodecs ( codecs = supported_codecs ),
927
+ set_supported_codecs = SupportedCodecs . from_public ( alter_consumer . set_supported_codecs ),
915
928
alter_attributes = alter_consumer .alter_attributes ,
916
929
)
917
930
@@ -936,16 +949,9 @@ def to_proto(self) -> ydb_topic_pb2.PartitioningSettings:
936
949
937
950
938
951
@dataclass
939
- class AlterPartitioningSettings (IToProto , IFromProto ):
940
- set_min_active_partitions : int
941
- set_partition_count_limit : int
942
-
943
- @staticmethod
944
- def from_proto (msg : ydb_topic_pb2 .AlterPartitioningSettings ) -> "AlterPartitioningSettings" :
945
- return AlterPartitioningSettings (
946
- set_min_active_partitions = msg .set_min_active_partitions ,
947
- set_partition_count_limit = msg .set_partition_count_limit ,
948
- )
952
+ class AlterPartitioningSettings (IToProto ):
953
+ set_min_active_partitions : Optional [int ]
954
+ set_partition_count_limit : Optional [int ]
949
955
950
956
def to_proto (self ) -> ydb_topic_pb2 .AlterPartitioningSettings :
951
957
return ydb_topic_pb2 .AlterPartitioningSettings (
@@ -1050,20 +1056,22 @@ class CreateTopicResult:
1050
1056
@dataclass
1051
1057
class AlterTopicRequest (IToProto , IFromPublic ):
1052
1058
path : str
1053
- add_consumers : List ["Consumer" ]
1054
- alter_partitioning_settings : AlterPartitioningSettings
1055
- set_retention_period : datetime .timedelta
1056
- set_retention_storage_mb : int
1057
- set_supported_codecs : SupportedCodecs
1058
- set_partition_write_burst_bytes : typing . Optional [int ]
1059
- set_partition_write_speed_bytes_per_second : typing . Optional [int ]
1060
- alter_attributes : Dict [str , str ]
1061
- alter_consumers : List [AlterConsumer ]
1062
- drop_consumers : List [str ]
1063
- set_metering_mode : "MeteringMode"
1059
+ add_consumers : Optional [ List ["Consumer" ] ]
1060
+ alter_partitioning_settings : Optional [ AlterPartitioningSettings ]
1061
+ set_retention_period : Optional [ datetime .timedelta ]
1062
+ set_retention_storage_mb : Optional [ int ]
1063
+ set_supported_codecs : Optional [ SupportedCodecs ]
1064
+ set_partition_write_burst_bytes : Optional [int ]
1065
+ set_partition_write_speed_bytes_per_second : Optional [int ]
1066
+ alter_attributes : Optional [ Dict [str , str ] ]
1067
+ alter_consumers : Optional [ List [AlterConsumer ] ]
1068
+ drop_consumers : Optional [ List [str ] ]
1069
+ set_metering_mode : Optional [ "MeteringMode" ]
1064
1070
1065
1071
def to_proto (self ) -> ydb_topic_pb2 .AlterTopicRequest :
1066
- supported_codecs = self .set_supported_codecs .to_proto () if self .set_supported_codecs .codecs else None
1072
+ supported_codecs = None
1073
+ if self .set_supported_codecs is not None :
1074
+ supported_codecs = self .set_supported_codecs .to_proto ()
1067
1075
1068
1076
return ydb_topic_pb2 .AlterTopicRequest (
1069
1077
path = self .path ,
@@ -1098,8 +1106,6 @@ def from_public(req: ydb_topic_public_types.AlterTopicRequestParams) -> AlterTop
1098
1106
1099
1107
drop_consumers = req .drop_consumers if req .drop_consumers else []
1100
1108
1101
- supported_codecs = req .set_supported_codecs if req .set_supported_codecs else []
1102
-
1103
1109
return AlterTopicRequest (
1104
1110
path = req .path ,
1105
1111
alter_partitioning_settings = AlterPartitioningSettings (
@@ -1109,9 +1115,7 @@ def from_public(req: ydb_topic_public_types.AlterTopicRequestParams) -> AlterTop
1109
1115
add_consumers = add_consumers ,
1110
1116
set_retention_period = req .set_retention_period ,
1111
1117
set_retention_storage_mb = req .set_retention_storage_mb ,
1112
- set_supported_codecs = SupportedCodecs (
1113
- codecs = supported_codecs ,
1114
- ),
1118
+ set_supported_codecs = SupportedCodecs .from_public (req .set_supported_codecs ),
1115
1119
set_partition_write_burst_bytes = req .set_partition_write_burst_bytes ,
1116
1120
set_partition_write_speed_bytes_per_second = req .set_partition_write_speed_bytes_per_second ,
1117
1121
alter_attributes = req .alter_attributes ,
@@ -1121,11 +1125,6 @@ def from_public(req: ydb_topic_public_types.AlterTopicRequestParams) -> AlterTop
1121
1125
)
1122
1126
1123
1127
1124
- @dataclass
1125
- class AlterTopicResult :
1126
- pass
1127
-
1128
-
1129
1128
@dataclass
1130
1129
class DescribeTopicRequest :
1131
1130
path : str
0 commit comments