Skip to content

Commit 7dba955

Browse files
committed
frame/response: document modules and items
1 parent b0d35ee commit 7dba955

File tree

7 files changed

+238
-14
lines changed

7 files changed

+238
-14
lines changed

scylla-cql/src/frame/response/authenticate.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
//! CQL protocol-level representation of an `AUTHENTICATE` response.
2+
13
use crate::frame::frame_errors::{
24
CqlAuthChallengeParseError, CqlAuthSuccessParseError, CqlAuthenticateParseError,
35
};
46
use crate::frame::types;
57

6-
// Implements Authenticate message.
8+
/// Represents AUTHENTICATE CQL response.
79
#[derive(Debug)]
810
pub struct Authenticate {
11+
/// The name of the authenticator requested by the server to use.
912
pub authenticator_name: String,
1013
}
1114

1215
impl Authenticate {
16+
/// Deserializes an `AUTHENTICATE` message from the provided buffer.
1317
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthenticateParseError> {
1418
let authenticator_name = types::read_string(buf)
1519
.map_err(CqlAuthenticateParseError::AuthNameParseError)?
@@ -19,12 +23,15 @@ impl Authenticate {
1923
}
2024
}
2125

26+
/// Represents AUTH_SUCCESS CQL response.
2227
#[derive(Debug)]
2328
pub struct AuthSuccess {
29+
/// Optional success message provided by the server.
2430
pub success_message: Option<Vec<u8>>,
2531
}
2632

2733
impl AuthSuccess {
34+
/// Deserializes an `AUTH_SUCCESS` message from the provided buffer.
2835
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthSuccessParseError> {
2936
let success_message = types::read_bytes_opt(buf)
3037
.map_err(CqlAuthSuccessParseError::SuccessMessageParseError)?
@@ -34,12 +41,20 @@ impl AuthSuccess {
3441
}
3542
}
3643

44+
/// Represents AUTH_CHALLENGE CQL response.
45+
///
46+
/// This message is sent by the server to challenge the client to provide
47+
/// authentication credentials. The client must respond with an `AUTH_RESPONSE`
48+
/// message containing the credentials.
3749
#[derive(Debug)]
3850
pub struct AuthChallenge {
51+
/// The challenge sent by the server, whose semantics depend on the
52+
/// authenticator being used.
3953
pub authenticate_message: Option<Vec<u8>>,
4054
}
4155

4256
impl AuthChallenge {
57+
/// Deserializes an `AUTH_CHALLENGE` message from the provided buffer.
4358
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthChallengeParseError> {
4459
let authenticate_message = types::read_bytes_opt(buf)
4560
.map_err(CqlAuthChallengeParseError::AuthMessageParseError)?

scylla-cql/src/frame/response/custom_type_parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Implementation of a parser for custom types in the CQL protocol.
2+
13
use super::result::CollectionType;
24
use super::result::NativeType;
35
use super::result::{ColumnType, UserDefinedType};

scylla-cql/src/frame/response/error.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL protocol-level representation of an `ERROR` response.
2+
13
use crate::frame::frame_errors::{CqlErrorParseError, LowLevelDeserializationError};
24
use crate::frame::protocol_features::ProtocolFeatures;
35
use crate::frame::types;
@@ -6,9 +8,14 @@ use byteorder::ReadBytesExt;
68
use bytes::Bytes;
79
use thiserror::Error;
810

11+
/// Represents a CQL protocol-level error that is sent by the database in response to a query
12+
/// that failed to execute successfully.
913
#[derive(Debug, Clone)]
1014
pub struct Error {
15+
/// Error code and other context of the error.
1116
pub error: DbError,
17+
18+
/// The reason for the error, typically a human-readable message.
1219
pub reason: String,
1320
}
1421

@@ -25,6 +32,7 @@ fn make_error_field_err(
2532
}
2633

2734
impl Error {
35+
/// Deserializes the error response from the provided buffer.
2836
pub fn deserialize(
2937
features: &ProtocolFeatures,
3038
buf: &mut &[u8],
@@ -327,6 +335,7 @@ pub enum DbError {
327335
}
328336

329337
impl DbError {
338+
/// Returns the error code for this error, as defined in the CQL protocol specification.
330339
pub fn code(&self, protocol_features: &ProtocolFeatures) -> i32 {
331340
match self {
332341
DbError::ServerError => 0x0000,
@@ -456,7 +465,7 @@ pub enum WriteType {
456465
Cas,
457466
/// Write involves VIEW update and failure to acquire local view(MV) lock for key within timeout
458467
View,
459-
/// Timeout occurred when a cdc_total_space_in_mb is exceeded when doing a write to data tracked by cdc
468+
/// Timeout occurred when a cdc_total_space_in_mb is exceeded when doing a write to data tracked by cdc
460469
Cdc,
461470
/// Other type not specified in the specification
462471
Other(String),
@@ -495,6 +504,7 @@ impl From<&str> for WriteType {
495504
}
496505

497506
impl WriteType {
507+
/// Returns the string representation of the write type as defined in the CQL protocol specification.
498508
pub fn as_str(&self) -> &str {
499509
match self {
500510
WriteType::Simple => "SIMPLE",

scylla-cql/src/frame/response/event.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,117 @@
1+
//! CQL protocol-level representation of an `EVENT` response.
2+
13
use crate::frame::frame_errors::{
24
ClusterChangeEventParseError, CqlEventParseError, SchemaChangeEventParseError,
35
};
46
use crate::frame::server_event_type::EventType;
57
use crate::frame::types;
68
use 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)]
1215
pub 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)]
1926
pub 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)]
2535
pub 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)]
3447
pub 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)]
6499
pub 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

71113
impl 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

90133
impl 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

190234
impl 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

207252
impl 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)?;

scylla-cql/src/frame/response/mod.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL responses sent by the server.
2+
13
pub mod authenticate;
24
pub mod custom_type_parser;
35
pub mod error;
@@ -47,6 +49,7 @@ impl std::fmt::Display for CqlResponseKind {
4749
}
4850
}
4951

52+
/// Opcode of a response, used to identify the response type in a CQL frame.
5053
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
5154
#[repr(u8)]
5255
pub enum ResponseOpcode {
@@ -81,19 +84,30 @@ impl TryFrom<u8> for ResponseOpcode {
8184
}
8285
}
8386

87+
/// A CQL response that has been received from the server.
8488
#[derive(Debug)]
8589
pub enum Response {
90+
/// ERROR response, returned by the server when an error occurs.
8691
Error(Error),
92+
/// READY response, indicating that the server is ready to process requests,
93+
/// typically after a connection is established.
8794
Ready,
95+
/// RESULT response, containing the result of a statement execution.
8896
Result(result::Result),
97+
/// AUTHENTICATE response, indicating that the server requires authentication.
8998
Authenticate(authenticate::Authenticate),
99+
/// AUTH_SUCCESS response, indicating that the authentication was successful.
90100
AuthSuccess(authenticate::AuthSuccess),
101+
/// AUTH_CHALLENGE response, indicating that the server requires further authentication.
91102
AuthChallenge(authenticate::AuthChallenge),
103+
/// SUPPORTED response, containing the features supported by the server.
92104
Supported(Supported),
105+
/// EVENT response, containing an event that occurred on the server.
93106
Event(event::Event),
94107
}
95108

96109
impl Response {
110+
/// Returns the kind of this response.
97111
pub fn to_response_kind(&self) -> CqlResponseKind {
98112
match self {
99113
Response::Error(_) => CqlResponseKind::Error,
@@ -107,6 +121,7 @@ impl Response {
107121
}
108122
}
109123

124+
/// Deserialize a response from the given bytes.
110125
pub fn deserialize(
111126
features: &ProtocolFeatures,
112127
opcode: ResponseOpcode,
@@ -136,6 +151,7 @@ impl Response {
136151
Ok(response)
137152
}
138153

154+
/// Converts this response into a `NonErrorResponse`, returning an error if it is an `Error` response.
139155
pub fn into_non_error_response(self) -> Result<NonErrorResponse, error::Error> {
140156
let non_error_response = match self {
141157
Response::Error(e) => return Err(e),
@@ -152,19 +168,29 @@ impl Response {
152168
}
153169
}
154170

155-
// A Response which can not be Response::Error
171+
/// A CQL response that has been received from the server, excluding error responses.
172+
/// This is used to handle responses that are not errors, allowing for easier processing
173+
/// of valid responses without need to handle error case any later.
156174
#[derive(Debug)]
157175
pub enum NonErrorResponse {
176+
/// See [`Response::Ready`].
158177
Ready,
178+
/// See [`Response::Result`].
159179
Result(result::Result),
180+
/// See [`Response::Authenticate`].
160181
Authenticate(authenticate::Authenticate),
182+
/// See [`Response::AuthSuccess`].
161183
AuthSuccess(authenticate::AuthSuccess),
184+
/// See [`Response::AuthChallenge`].
162185
AuthChallenge(authenticate::AuthChallenge),
186+
/// See [`Response::Supported`].
163187
Supported(Supported),
188+
/// See [`Response::Event`].
164189
Event(event::Event),
165190
}
166191

167192
impl NonErrorResponse {
193+
/// Returns the kind of this non-error response.
168194
pub fn to_response_kind(&self) -> CqlResponseKind {
169195
match self {
170196
NonErrorResponse::Ready => CqlResponseKind::Ready,

0 commit comments

Comments
 (0)