1+ from __future__ import annotations
2+
13import datetime
24import enum
35import typing
810
911from . import ydb_topic_public_types
1012from ... import scheme
13+ from ... import issues
1114
1215# Workaround for good IDE and universal for runtime
1316if typing .TYPE_CHECKING :
@@ -588,16 +591,32 @@ def from_proto(
588591 )
589592
590593 @dataclass
591- class PartitionSessionStatusRequest :
594+ class PartitionSessionStatusRequest ( IToProto ) :
592595 partition_session_id : int
593596
597+ def to_proto (self ) -> ydb_topic_pb2 .StreamReadMessage .PartitionSessionStatusRequest :
598+ return ydb_topic_pb2 .StreamReadMessage .PartitionSessionStatusRequest (
599+ partition_session_id = self .partition_session_id
600+ )
601+
594602 @dataclass
595- class PartitionSessionStatusResponse :
603+ class PartitionSessionStatusResponse ( IFromProto ) :
596604 partition_session_id : int
597605 partition_offsets : "OffsetsRange"
598606 committed_offset : int
599607 write_time_high_watermark : float
600608
609+ @staticmethod
610+ def from_proto (
611+ msg : ydb_topic_pb2 .StreamReadMessage .PartitionSessionStatusResponse ,
612+ ) -> "StreamReadMessage.PartitionSessionStatusResponse" :
613+ return StreamReadMessage .PartitionSessionStatusResponse (
614+ partition_session_id = msg .partition_session_id ,
615+ partition_offsets = OffsetsRange .from_proto (msg .partition_offsets ),
616+ committed_offset = msg .committed_offset ,
617+ write_time_high_watermark = msg .write_time_high_watermark ,
618+ )
619+
601620 @dataclass
602621 class StartPartitionSessionRequest (IFromProto ):
603622 partition_session : "StreamReadMessage.PartitionSession"
@@ -632,15 +651,30 @@ def to_proto(
632651 return res
633652
634653 @dataclass
635- class StopPartitionSessionRequest :
654+ class StopPartitionSessionRequest ( IFromProto ) :
636655 partition_session_id : int
637656 graceful : bool
638657 committed_offset : int
639658
659+ @staticmethod
660+ def from_proto (
661+ msg : ydb_topic_pb2 .StreamReadMessage .StopPartitionSessionRequest ,
662+ ) -> StreamReadMessage .StopPartitionSessionRequest :
663+ return StreamReadMessage .StopPartitionSessionRequest (
664+ partition_session_id = msg .partition_session_id ,
665+ graceful = msg .graceful ,
666+ committed_offset = msg .committed_offset ,
667+ )
668+
640669 @dataclass
641- class StopPartitionSessionResponse :
670+ class StopPartitionSessionResponse ( IToProto ) :
642671 partition_session_id : int
643672
673+ def to_proto (self ) -> ydb_topic_pb2 .StreamReadMessage .StopPartitionSessionResponse :
674+ return ydb_topic_pb2 .StreamReadMessage .StopPartitionSessionResponse (
675+ partition_session_id = self .partition_session_id ,
676+ )
677+
644678 @dataclass
645679 class FromClient (IToProto ):
646680 client_message : "ReaderMessagesFromClientToServer"
@@ -660,6 +694,10 @@ def to_proto(self) -> ydb_topic_pb2.StreamReadMessage.FromClient:
660694 res .update_token_request .CopyFrom (self .client_message .to_proto ())
661695 elif isinstance (self .client_message , StreamReadMessage .StartPartitionSessionResponse ):
662696 res .start_partition_session_response .CopyFrom (self .client_message .to_proto ())
697+ elif isinstance (self .client_message , StreamReadMessage .StopPartitionSessionResponse ):
698+ res .stop_partition_session_response .CopyFrom (self .client_message .to_proto ())
699+ elif isinstance (self .client_message , StreamReadMessage .PartitionSessionStatusRequest ):
700+ res .start_partition_session_response .CopyFrom (self .client_message .to_proto ())
663701 else :
664702 raise NotImplementedError ("Unknown message type: %s" % type (self .client_message ))
665703 return res
@@ -694,17 +732,32 @@ def from_proto(
694732 return StreamReadMessage .FromServer (
695733 server_status = server_status ,
696734 server_message = StreamReadMessage .StartPartitionSessionRequest .from_proto (
697- msg .start_partition_session_request
735+ msg .start_partition_session_request ,
736+ ),
737+ )
738+ elif mess_type == "stop_partition_session_request" :
739+ return StreamReadMessage .FromServer (
740+ server_status = server_status ,
741+ server_message = StreamReadMessage .StopPartitionSessionRequest .from_proto (
742+ msg .stop_partition_session_request
698743 ),
699744 )
700745 elif mess_type == "update_token_response" :
701746 return StreamReadMessage .FromServer (
702747 server_status = server_status ,
703748 server_message = UpdateTokenResponse .from_proto (msg .update_token_response ),
704749 )
705-
706- # todo replace exception to log
707- raise NotImplementedError ()
750+ elif mess_type == "partition_session_status_response" :
751+ return StreamReadMessage .FromServer (
752+ server_status = server_status ,
753+ server_message = StreamReadMessage .PartitionSessionStatusResponse .from_proto (
754+ msg .partition_session_status_response
755+ ),
756+ )
757+ else :
758+ raise issues .UnexpectedGrpcMessage (
759+ "Unexpected message while parse ReaderMessagesFromServerToClient: '%s'" % mess_type
760+ )
708761
709762
710763ReaderMessagesFromClientToServer = Union [
0 commit comments