Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #213

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions wtx-fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

[[bin]]
name = "web-socket"
path = "web_socket.rs"
Expand All @@ -11,7 +9,7 @@ tokio = { default-features = false, features = ["rt"], version = "1.0" }
wtx = { default-features = false, features = ["arbitrary", "web-socket"], path = "../wtx" }

[package]
edition = "2024"
edition = "2021"
name = "wtx-fuzz"
publish = false
version = "0.0.0"
Expand Down
4 changes: 1 addition & 3 deletions wtx-instances/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

# Examples

[[example]]
Expand Down Expand Up @@ -90,7 +88,7 @@ wtx-macros = { default-features = false, path = "../wtx-macros" }
_tracing-tree = ["wtx/_tracing-tree"]

[package]
edition = "2024"
edition = "2021"
name = "wtx-instances"
publish = false
version = "0.0.0"
6 changes: 3 additions & 3 deletions wtx-instances/examples/grpc-server-tokio-rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate wtx_instances;
use std::borrow::Cow;
use wtx::{
data_transformation::dnsn::QuickProtobuf,
grpc::{Server, ServerData},
grpc::{GrpcStatusCode, Server, ServerData},
http::{
server_framework::{post, Router},
ReqResBuffer, Request, Response, StatusCode,
Expand All @@ -33,7 +33,7 @@ async fn main() -> wtx::Result<()> {

async fn wtx_generic_service_generic_method(
(mut sd, mut req): (ServerData<QuickProtobuf>, Request<ReqResBuffer>),
) -> wtx::Result<Response<ReqResBuffer>> {
) -> wtx::Result<(GrpcStatusCode, Response<ReqResBuffer>)> {
let _generic_request: GenericRequest = sd.des_from_req_bytes(&req.rrd.data)?;
req.rrd.clear();
sd.ser_to_res_bytes(
Expand All @@ -43,5 +43,5 @@ async fn wtx_generic_service_generic_method(
generic_response_field1: 321,
},
)?;
Ok(req.into_response(StatusCode::Ok))
Ok((GrpcStatusCode::Ok, req.into_response(StatusCode::Ok)))
}
4 changes: 1 addition & 3 deletions wtx-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

[dependencies]
proc-macro2 = { default-features = false, version = "1.0" }
quote = { default-features = false, features = ["proc-macro"], version = "1.0" }
Expand All @@ -18,7 +16,7 @@ proc-macro = true
[package]
categories = ["asynchronous", "data-structures", "network-programming"]
description = "Procedural macros for wtx"
edition = "2024"
edition = "2021"
exclude = ["tests"]
keywords = ["api", "client", "io", "network"]
license = "MIT"
Expand Down
4 changes: 1 addition & 3 deletions wtx-ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

[dependencies]
clap = { default-features = false, features = ["derive", "help", "std", "usage"], optional = true, version = "4.0" }
dotenv = { default-features = false, optional = true, version = "0.15" }
Expand All @@ -21,7 +19,7 @@ authors = ["Caio Fernandes <[email protected]>"]
categories = ["asynchronous", "command-line-interface", "gui"]
description = "Different user interfaces for WTX"
documentation = "https://docs.rs/wtx-ui"
edition = "2024"
edition = "2021"
keywords = ["io", "network", "websocket"]
license = "Apache-2.0"
name = "wtx-ui"
Expand Down
6 changes: 2 additions & 4 deletions wtx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

[dependencies]
ahash = { default-features = false, features = ["no-rng"], optional = true, version = "0.8" }
arbitrary = { default-features = false, features = ["derive_arbitrary"], optional = true, version = "1.0" }
Expand Down Expand Up @@ -50,7 +48,7 @@ base64 = ["dep:base64"]
borsh = ["dep:borsh", "std"]
chrono = ["dep:chrono"]
cl-aux = ["dep:cl-aux"]
client-api-framework = ["cl-aux", "data-transformation"]
client-api-framework = ["data-transformation"]
crypto-common = ["dep:crypto-common"]
data-transformation = []
database = []
Expand Down Expand Up @@ -105,7 +103,7 @@ authors = ["Caio Fernandes <[email protected]>"]
categories = ["asynchronous", "database", "network-programming", "no-std", "web-programming"]
description = "A collection of different transport implementations and related tools focused primarily on web technologies."
documentation = "https://docs.rs/wtx"
edition = "2024"
edition = "2021"
exclude = ["tests"]
homepage = "https://c410-f3r.github.io/wtx"
keywords = ["api", "database", "http", "network", "websocket"]
Expand Down
2 changes: 1 addition & 1 deletion wtx/src/client_api_framework/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::fmt::Display;
use core::{fmt::Display, future::Future};

/// Api definitions group different packages into a common namespace and define custom additional
/// logical through hooks.
Expand Down
57 changes: 25 additions & 32 deletions wtx/src/client_api_framework/network/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ use crate::{
pkg::{BatchElems, BatchPkg, Package, PkgsAux},
Api,
},
data_transformation::{
dnsn::{Deserialize, Serialize},
Id,
},
data_transformation::dnsn::{Deserialize, Serialize},
misc::Lease,
};
pub use bi_transport::*;
use cl_aux::DynContigColl;
use core::ops::Range;
use core::{future::Future, ops::Range};
pub use mock::*;
pub use transport_params::*;

Expand Down Expand Up @@ -71,31 +67,28 @@ pub trait Transport<DRSR> {
///
/// All the expected data must be available in a single response.
#[inline]
fn send_recv_decode_batch<A, E, P, RESS>(
fn send_recv_decode_batch<'pkgs, 'pkgs_aux, A, P>(
&mut self,
pkgs: &mut [P],
pkgs_aux: &mut PkgsAux<A, DRSR, Self::Params>,
ress: &mut RESS,
) -> impl Future<Output = Result<(), A::Error>>
pkgs: &'pkgs mut [P],
pkgs_aux: &'pkgs_aux mut PkgsAux<A, DRSR, Self::Params>,
) -> impl Future<
Output = Result<
impl Iterator<Item = crate::Result<P::ExternalResponseContent<'pkgs_aux>>>,
A::Error,
>,
>
where
A: Api,
A::Error: From<E>,
P: Package<A, DRSR, Self::Params>,
P::ExternalRequestContent: Lease<Id> + Ord,
for<'de> P::ExternalResponseContent<'de>: Lease<Id> + Ord,
RESS: for<'de> DynContigColl<E, P::ExternalResponseContent<'de>>,
for<'any> BatchElems<'any, A, DRSR, P, Self::Params>: Serialize<DRSR>,
BatchElems<'pkgs, A, DRSR, P, Self::Params>: Serialize<DRSR>,
{
async {
let batch_package = &mut BatchPkg::new(pkgs);
let range = self.send_recv(batch_package, pkgs_aux).await?;
let range = self.send_recv(&mut BatchPkg::new(pkgs), pkgs_aux).await?;
log_res(pkgs_aux.byte_buffer.lease());
batch_package.decode_and_push_from_bytes(
ress,
Ok(P::ExternalResponseContent::seq_from_bytes(
pkgs_aux.byte_buffer.get(range).unwrap_or_default(),
&mut pkgs_aux.drsr,
)?;
Ok(())
))
}
}

Expand Down Expand Up @@ -181,18 +174,22 @@ mod tests {
type ExternalResponseContent<'de> = _Pong;
type PackageParams = ();

#[inline]
fn ext_req_content(&self) -> &Self::ExternalRequestContent {
&self.0
}

#[inline]
fn ext_req_content_mut(&mut self) -> &mut Self::ExternalRequestContent {
&mut self.0
}

#[inline]
fn pkg_params(&self) -> &Self::PackageParams {
&self.1
}

#[inline]
fn pkg_params_mut(&mut self) -> &mut Self::PackageParams {
&mut self.1
}
Expand All @@ -202,6 +199,7 @@ mod tests {
pub(crate) struct _Ping;

impl<DRSR> Serialize<DRSR> for _Ping {
#[inline]
fn to_bytes(&mut self, bytes: &mut Vector<u8>, _: &mut DRSR) -> crate::Result<()> {
bytes.extend_from_slice(b"ping")?;
Ok(())
Expand All @@ -211,21 +209,16 @@ mod tests {
#[derive(Debug, Eq, PartialEq)]
pub(crate) struct _Pong(pub(crate) &'static str);

impl<DRSR> Deserialize<'_, DRSR> for _Pong {
impl<'de, DRSR> Deserialize<'de, DRSR> for _Pong {
#[inline]
fn from_bytes(bytes: &[u8], _: &mut DRSR) -> crate::Result<Self> {
assert_eq!(bytes, b"ping");
Ok(Self("pong"))
}

fn seq_from_bytes<E>(
_: &[u8],
_: &mut DRSR,
_: impl FnMut(Self) -> Result<(), E>,
) -> Result<(), E>
where
E: From<crate::Error>,
{
Ok(())
#[inline]
fn seq_from_bytes(_: &'de [u8], _: &mut DRSR) -> impl Iterator<Item = crate::Result<Self>> {
[].into_iter()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
data_transformation::dnsn::Deserialize,
misc::Lease,
};
use core::ops::Range;
use core::{future::Future, ops::Range};

/// Bidirectional Transport
///
Expand Down
1 change: 1 addition & 0 deletions wtx/src/client_api_framework/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
data_transformation::dnsn::{Deserialize, Serialize},
};
pub use batch_pkg::{BatchElems, BatchPkg};
use core::future::Future;
pub use pkg_with_helper::*;
pub use pkgs_aux::*;

Expand Down
86 changes: 2 additions & 84 deletions wtx/src/client_api_framework/pkg/batch_pkg.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
use crate::{
client_api_framework::{
network::transport::TransportParams, pkg::Package, Api, ClientApiFrameworkError,
},
data_transformation::{
dnsn::{Deserialize, Serialize},
Id,
},
misc::Lease,
client_api_framework::{network::transport::TransportParams, pkg::Package, Api},
data_transformation::dnsn::Serialize,
};
use cl_aux::DynContigColl;
use core::marker::PhantomData;

/// Used to perform batch requests with multiple packages.
Expand All @@ -23,81 +16,6 @@ impl<'slice, A, DRSR, P, TP> BatchPkg<'slice, A, DRSR, P, TP> {
}
}

impl<A, DRSR, P, TP> BatchPkg<'_, A, DRSR, P, TP>
where
A: Api,
P: Package<A, DRSR, TP>,
P::ExternalRequestContent: Lease<Id> + Ord,
for<'de> P::ExternalResponseContent<'de>: Lease<Id> + Ord,
TP: TransportParams,
{
/// Deserializes a sequence of bytes and then pushes them to the provided buffer.
#[inline]
pub fn decode_and_push_from_bytes<B, E>(
&mut self,
buffer: &mut B,
bytes: &[u8],
drsr: &mut DRSR,
) -> Result<(), A::Error>
where
A::Error: From<E>,
B: for<'de> DynContigColl<E, P::ExternalResponseContent<'de>>,
{
if self.0 .0.is_empty() {
return Ok(());
}
Self::is_sorted(self.0 .0.iter().map(|elem| elem.ext_req_content().lease()))?;
let mut pkgs_idx = 0;
let mut responses_are_not_sorted = false;
P::ExternalResponseContent::seq_from_bytes(bytes, drsr, |eresc| {
let eresc_id = *eresc.lease();
let found_pkgs_idx = Self::search_slice(pkgs_idx, eresc_id, self.0 .0)?;
if pkgs_idx != found_pkgs_idx {
responses_are_not_sorted = true;
}
buffer.push(eresc).map_err(Into::into)?;
pkgs_idx = pkgs_idx.wrapping_add(1);
Ok::<_, A::Error>(())
})?;
if responses_are_not_sorted {
buffer.sort_unstable();
}
Ok(())
}

fn is_sorted<T>(mut iter: impl Iterator<Item = T>) -> crate::Result<()>
where
T: PartialOrd,
{
let mut is_sorted = true;
let Some(mut previous) = iter.next() else {
return Ok(());
};
for curr in iter {
if previous > curr {
is_sorted = false;
break;
}
previous = curr;
}
if is_sorted {
Ok(())
} else {
Err(ClientApiFrameworkError::BatchPackagesAreNotSorted.into())
}
}

// First try indexing and then falls back to binary search
fn search_slice(idx: usize, eresc_id: Id, pkgs: &[P]) -> crate::Result<usize> {
if pkgs.get(idx).map(|pkg| *pkg.ext_req_content().lease() == eresc_id).unwrap_or_default() {
return Ok(idx);
}
pkgs.binary_search_by(|req| req.ext_req_content().lease().cmp(&&eresc_id)).ok().ok_or(
ClientApiFrameworkError::ResponseIdIsNotPresentInTheOfSentBatchPackages(eresc_id).into(),
)
}
}

impl<'slice, A, DRSR, P, TP> Package<A, DRSR, TP> for BatchPkg<'slice, A, DRSR, P, TP>
where
A: Api,
Expand Down
1 change: 0 additions & 1 deletion wtx/src/data_transformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod macros;
mod data_transformation_error;
pub mod dnsn;
pub mod format;
mod seq_visitor;

pub use data_transformation_error::DataTransformationError;

Expand Down
Loading
Loading