Fleshed out Request and ResponseHeader
This commit is contained in:
parent
44d186664a
commit
dbd0340434
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -329,7 +329,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hpk-package"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package#9cf9d469f644c43ee2c2d9ca3b16e669c2def944"
|
||||
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package#723d697e9085a575c1f6d59baf1e79819452d747"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"deku",
|
||||
@ -348,6 +348,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"hpk-package",
|
||||
"rayon",
|
||||
"serde",
|
||||
"url",
|
||||
]
|
||||
|
||||
|
@ -12,4 +12,5 @@ server = []
|
||||
[dependencies]
|
||||
hpk-package = { git = "https://git.hitchhiker-linux.org/jeang3nie/hpk-package" }
|
||||
rayon = "1.7"
|
||||
serde = { version = "1.0.159", features = ["derive"] }
|
||||
url = "2.3.1"
|
||||
|
@ -1,20 +1,9 @@
|
||||
pub trait Client {
|
||||
type Error;
|
||||
type Response;
|
||||
use crate::Request;
|
||||
|
||||
fn get() -> Result<Self, Self::Error> where Self: Sized;
|
||||
fn request(&self) -> Result<Self::Response, Self::Error>;
|
||||
pub fn make_request(request: Request) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
impl Client for super::Update {
|
||||
type Error = Box<dyn std::error::Error>;
|
||||
type Response = ();
|
||||
|
||||
fn get() -> Result<Self, Self::Error> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn request(&self) -> Result<Self::Response, Self::Error> {
|
||||
unimplemented!();
|
||||
}
|
||||
pub fn handle_response() {
|
||||
unimplemented!();
|
||||
}
|
||||
|
87
src/lib.rs
87
src/lib.rs
@ -1,20 +1,89 @@
|
||||
use std::path::PathBuf;
|
||||
use hpk_package::{Arch, Package, Version};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{fmt, path::PathBuf};
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
mod client;
|
||||
#[cfg(feature = "client")]
|
||||
pub use client::Client;
|
||||
pub mod client;
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
pub mod server;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct PackageSpec {
|
||||
name: String,
|
||||
version: Version,
|
||||
arch: Arch,
|
||||
release: u8,
|
||||
}
|
||||
|
||||
impl fmt::Display for PackageSpec {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}-{}_{}_{}",
|
||||
self.name, self.version, self.arch, self.release
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Package> for PackageSpec {
|
||||
fn from(value: Package) -> Self {
|
||||
Self {
|
||||
name: value.name,
|
||||
version: value.version,
|
||||
arch: value.arch,
|
||||
release: value.release,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Package> for PackageSpec {
|
||||
fn from(value: &Package) -> Self {
|
||||
Self {
|
||||
name: value.name.to_string(),
|
||||
version: value.version.clone(),
|
||||
arch: value.arch,
|
||||
release: value.release,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Item {
|
||||
pub package: String,
|
||||
pub pspec: PackageSpec,
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Update {
|
||||
pub items: Vec<Item>,
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub enum Request {
|
||||
Catalog,
|
||||
Packages(Vec<PackageSpec>),
|
||||
Updates(Vec<Item>),
|
||||
}
|
||||
|
||||
impl From<Vec<PackageSpec>> for Request {
|
||||
fn from(value: Vec<PackageSpec>) -> Self {
|
||||
Self::Packages(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<Item>> for Request {
|
||||
fn from(value: Vec<Item>) -> Self {
|
||||
Self::Updates(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub enum ResponseHeader {
|
||||
/// The server is sending it's catalog
|
||||
Catalog,
|
||||
/// The server is sending a package, captured value is it's length. A new header will be sent
|
||||
/// for each subsequent file.
|
||||
Package(usize),
|
||||
/// The server is sending an archive of updated files
|
||||
Updates,
|
||||
/// One or more requested packages are not on the server
|
||||
PackageNotFound(Vec<PackageSpec>),
|
||||
/// One or more requested update files are not on the server
|
||||
FileNotFound(Vec<Item>),
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
|
Loading…
Reference in New Issue
Block a user