surrealcs 0.4.4

The SurrealCS client code for SurrealDB
Documentation
//! Sending the Ping over TCP to the server.
use super::utils::send_message_over_tcp;
use nanoservices_utils::errors::NanoServiceError;
use surrealcs_kernel::messages::server::{interface::ServerMessage, wrapper::WrappedServerMessage};
use tokio::net::tcp::OwnedWriteHalf;

/// Sends a ping message to the server.
///
/// # Arguments
/// * `client_id`: The id of the client
/// * `con_id`: The id of the connection
/// * `writer`: The writer to the TCP stream
///
/// # Returns
/// * `Result<(), NanoServiceError>`: The result of the sending over TCP
pub async fn ping(
	client_id: usize,
	con_id: String,
	mut writer: &mut OwnedWriteHalf,
) -> Result<(), NanoServiceError> {
	let wrapped_message =
		WrappedServerMessage::new(client_id, ServerMessage::Ping(client_id), con_id);
	// put in the interface to send the message on an error
	send_message_over_tcp(&mut writer, &wrapped_message).await
}