1+ //! CQL protocol-level representation of an `EVENT` response.
2+
13use crate :: frame:: frame_errors:: {
24 ClusterChangeEventParseError , CqlEventParseError , SchemaChangeEventParseError ,
35} ;
46use crate :: frame:: server_event_type:: EventType ;
57use crate :: frame:: types;
68use std:: net:: SocketAddr ;
79
10+ /// Event that the server notified the client about.
811#[ derive( Debug ) ]
912// Check triggers because all variants end with "Change".
1013// TODO(2.0): Remove the "Change" postfix from variants.
1114#[ expect( clippy:: enum_variant_names) ]
1215pub enum Event {
16+ /// Topology changed.
1317 TopologyChange ( TopologyChangeEvent ) ,
18+ /// Status of a node changed.
1419 StatusChange ( StatusChangeEvent ) ,
20+ /// Schema changed.
1521 SchemaChange ( SchemaChangeEvent ) ,
1622}
1723
24+ /// Event that notifies about changes in the cluster topology.
1825#[ derive( Debug ) ]
1926pub enum TopologyChangeEvent {
27+ /// A new node was added to the cluster.
2028 NewNode ( SocketAddr ) ,
29+ /// A node was removed from the cluster.
2130 RemovedNode ( SocketAddr ) ,
2231}
2332
33+ /// Event that notifies about changes in the nodes' status.
2434#[ derive( Debug ) ]
2535pub enum StatusChangeEvent {
36+ /// A node went up.
2637 Up ( SocketAddr ) ,
38+ /// A node went down.
2739 Down ( SocketAddr ) ,
2840}
2941
42+ /// Event that notifies about changes in the cluster topology.
3043#[ derive( Debug ) ]
3144// Check triggers because all variants end with "Change".
3245// TODO(2.0): Remove the "Change" postfix from variants.
3346#[ expect( clippy:: enum_variant_names) ]
3447pub enum SchemaChangeEvent {
48+ /// Keyspace was altered.
3549 KeyspaceChange {
50+ /// Type of change that was made to the keyspace.
3651 change_type : SchemaChangeType ,
52+ /// Name of the keyspace that was altered.
3753 keyspace_name : String ,
3854 } ,
55+ /// Table was altered.
3956 TableChange {
57+ /// Type of change that was made to the table.
4058 change_type : SchemaChangeType ,
59+ /// Name of the keyspace that contains the table.
4160 keyspace_name : String ,
61+ /// Name of the table that was altered.
4262 object_name : String ,
4363 } ,
64+ /// Type was altered.
4465 TypeChange {
66+ /// Type of change that was made to the type.
4567 change_type : SchemaChangeType ,
68+ /// Name of the keyspace that contains the type.
4669 keyspace_name : String ,
70+ /// Name of the type that was altered.
4771 type_name : String ,
4872 } ,
73+ /// Function was altered.
4974 FunctionChange {
75+ /// Type of change that was made to the function.
5076 change_type : SchemaChangeType ,
77+ /// Name of the keyspace that contains the function.
5178 keyspace_name : String ,
79+ /// Name of the function that was altered.
5280 function_name : String ,
81+ /// List of argument types of the function that was altered.
5382 arguments : Vec < String > ,
5483 } ,
84+ /// Aggregate was altered.
5585 AggregateChange {
86+ /// Type of change that was made to the aggregate.
5687 change_type : SchemaChangeType ,
88+ /// Name of the keyspace that contains the aggregate.
5789 keyspace_name : String ,
90+ /// Name of the aggregate that was altered.
5891 aggregate_name : String ,
92+ /// List of argument types of the aggregate that was altered.
5993 arguments : Vec < String > ,
6094 } ,
6195}
6296
97+ /// Type of change that was made to the schema.
6398#[ derive( Debug ) ]
6499pub enum SchemaChangeType {
100+ /// The affected schema item was created.
65101 Created ,
102+
103+ /// The affected schema item was updated.
66104 Updated ,
105+
106+ /// The affected schema item was dropped.
67107 Dropped ,
108+
109+ /// A placeholder for an invalid schema change type.
68110 Invalid ,
69111}
70112
71113impl Event {
114+ /// Deserialize an event from the provided buffer.
72115 pub fn deserialize ( buf : & mut & [ u8 ] ) -> Result < Self , CqlEventParseError > {
73116 let event_type: EventType = types:: read_string ( buf)
74117 . map_err ( CqlEventParseError :: EventTypeParseError ) ?
@@ -88,6 +131,7 @@ impl Event {
88131}
89132
90133impl SchemaChangeEvent {
134+ /// Deserialize a schema change event from the provided buffer.
91135 pub fn deserialize ( buf : & mut & [ u8 ] ) -> Result < Self , SchemaChangeEventParseError > {
92136 let type_of_change_string =
93137 types:: read_string ( buf) . map_err ( SchemaChangeEventParseError :: TypeOfChangeParseError ) ?;
@@ -188,6 +232,7 @@ impl SchemaChangeEvent {
188232}
189233
190234impl TopologyChangeEvent {
235+ /// Deserialize a topology change event from the provided buffer.
191236 pub fn deserialize ( buf : & mut & [ u8 ] ) -> Result < Self , ClusterChangeEventParseError > {
192237 let type_of_change = types:: read_string ( buf)
193238 . map_err ( ClusterChangeEventParseError :: TypeOfChangeParseError ) ?;
@@ -205,6 +250,7 @@ impl TopologyChangeEvent {
205250}
206251
207252impl StatusChangeEvent {
253+ /// Deserialize a status change event from the provided buffer.
208254 pub fn deserialize ( buf : & mut & [ u8 ] ) -> Result < Self , ClusterChangeEventParseError > {
209255 let type_of_change = types:: read_string ( buf)
210256 . map_err ( ClusterChangeEventParseError :: TypeOfChangeParseError ) ?;
0 commit comments