mod auth;
mod commit;
mod connect;
mod data_types;
mod eof;
mod execute;
mod fast_auth;
mod fetch;
mod lob_op;
mod logoff;
mod marker;
mod ping;
mod protocol;
mod rollback;
use crate::client::Client;
use crate::constants;
use crate::error::Error;
use crate::response::Response;
use crate::write_buffer::WriteBuffer;
pub(crate) trait Message {
fn deserialize(
&mut self,
client: &Client,
resp: &mut Response,
) -> Result<(), Error>
where
Self: Message,
{
loop {
let message_type = resp.read_u8()?;
self.deserialize_ttc_message(client, resp, message_type)?;
if self.is_final_ttc_message_type(client, message_type) {
break;
}
}
Ok(())
}
fn deserialize_describe_info(
&mut self,
_client: &Client,
_resp: &mut Response,
) -> Result<(), Error> {
let feature = "deserializing describe info".to_string();
Err(Error::not_implemented(feature))
}
fn deserialize_io_vector(
&mut self,
_client: &Client,
_resp: &mut Response,
) -> Result<(), Error> {
let feature = "deserializing IO vector".to_string();
Err(Error::not_implemented(feature))
}
fn deserialize_lob_data(
&mut self,
_client: &Client,
_resp: &mut Response,
) -> Result<(), Error> {
let feature = "deserializing LOB data".to_string();
Err(Error::not_implemented(feature))
}
fn deserialize_return_parameters(
&mut self,
_client: &Client,
_resp: &mut Response,
) -> Result<(), Error> {
let feature = "deserializing return parameters".to_string();
Err(Error::not_implemented(feature))
}
fn deserialize_row_data(
&mut self,
_client: &Client,
_resp: &mut Response,
) -> Result<(), Error> {
let feature = "deserializing row data".to_string();
Err(Error::not_implemented(feature))
}
fn deserialize_row_header(
&mut self,
_client: &Client,
resp: &mut Response,
) -> Result<(), Error> {
let _flags = resp.read_u8()?;
let _num_requests = resp.read_ub2()?;
let _iter_num = resp.read_ub4()?;
let _num_iters = resp.read_ub4()?;
let _buffer_len = resp.read_ub2()?;
resp.read_bit_vector()?;
let _rxhrid = resp.read_bytes_with_length()?;
Ok(())
}
fn deserialize_status(
&mut self,
_client: &Client,
resp: &mut Response,
) -> Result<(), Error> {
let _call_status = resp.read_ub4()?;
let _seq_num = resp.read_ub2()?;
Ok(())
}
fn deserialize_ttc_message(
&mut self,
client: &Client,
resp: &mut Response,
message_type: u8,
) -> Result<(), Error>
where
Self: Message,
{
match message_type {
constants::TTC_MSG_TYPE_BIT_VECTOR => {
resp.deserialize_bit_vector()
}
constants::TTC_MSG_TYPE_DESCRIBE_INFO => {
self.deserialize_describe_info(client, resp)
}
constants::TTC_MSG_TYPE_END_OF_RESPONSE => Ok(()),
constants::TTC_MSG_TYPE_ERROR => resp.read_error_info(client),
constants::TTC_MSG_TYPE_IO_VECTOR => {
self.deserialize_io_vector(client, resp)
}
constants::TTC_MSG_TYPE_LOB_DATA => {
self.deserialize_lob_data(client, resp)
}
constants::TTC_MSG_TYPE_PARAMETER => {
self.deserialize_return_parameters(client, resp)
}
constants::TTC_MSG_TYPE_ROW_DATA => {
self.deserialize_row_data(client, resp)
}
constants::TTC_MSG_TYPE_ROW_HEADER => {
self.deserialize_row_header(client, resp)
}
constants::TTC_MSG_TYPE_SERVER_SIDE_PIGGYBACK => {
resp.deserialize_server_side_piggyback()
}
constants::TTC_MSG_TYPE_STATUS => {
self.deserialize_status(client, resp)
}
constants::TTC_MSG_TYPE_WARNING => resp.deserialize_warning(),
_ => Err(Error::unknown_ttc_message_type(message_type)),
}
}
fn extended_data_needed(&self) -> bool {
false
}
fn get_data_flags(&self) -> u16 {
0
}
fn get_packet_type(&self) -> u8 {
constants::PACKET_TYPE_DATA
}
fn get_packet_flags(&self) -> u8 {
0
}
fn is_final_ttc_message_type(
&self,
client: &Client,
message_type: u8,
) -> bool {
if client.supports_end_of_response() {
message_type == constants::TTC_MSG_TYPE_END_OF_RESPONSE
} else {
message_type == constants::TTC_MSG_TYPE_ERROR
|| message_type == constants::TTC_MSG_TYPE_STATUS
}
}
fn post_deserialize(
&mut self,
_client: &mut Client,
resp: &mut Response,
) -> Result<(), Error> {
resp.check_for_error()
}
fn pre_process(&mut self, _client: &mut Client) {}
fn pre_deserialize(&mut self, _client: &mut Client, _resp: &mut Response) {
}
fn resend_needed(&self) -> bool {
false
}
fn serialize(&self, client: &Client, buf: &mut WriteBuffer);
fn serialize_extended_data(
&self,
_client: &Client,
_buf: &mut WriteBuffer,
) {
}
}
pub(crate) use auth::AuthMessage;
pub(crate) use commit::CommitMessage;
pub(crate) use connect::ConnectMessage;
pub(crate) use data_types::DataTypesMessage;
pub(crate) use eof::EofMessage;
pub(crate) use execute::ExecuteMessage;
pub(crate) use fast_auth::FastAuthMessage;
pub(crate) use fetch::FetchMessage;
pub(crate) use lob_op::{LobOp, LobOpMessage};
pub(crate) use logoff::LogoffMessage;
pub(crate) use marker::MarkerMessage;
pub(crate) use ping::PingMessage;
pub(crate) use protocol::ProtocolMessage;
pub(crate) use rollback::RollbackMessage;