From f81c700a48ce6aa34a1846983cd30eea3b3dc1f6 Mon Sep 17 00:00:00 2001 From: CodeSteak Date: Fri, 19 Apr 2019 18:44:44 +0200 Subject: [PATCH] vim server_architektur.rs // add many things --- doc/feindesign/server_architektur.rs | 241 ++++++++++++++++----------- 1 file changed, 142 insertions(+), 99 deletions(-) diff --git a/doc/feindesign/server_architektur.rs b/doc/feindesign/server_architektur.rs index 25572a8..572b161 100644 --- a/doc/feindesign/server_architektur.rs +++ b/doc/feindesign/server_architektur.rs @@ -1,170 +1,213 @@ // main author: Robin Willmann // date : see git. - - // WIP, changes welcome -mod model { - pub struct Sha256(pub [64;u8]); - +extern crate image; + +pub mod model { + pub struct Sha256(pub [u8; 64]); + pub struct Texture { - pub id : String, - pub name : String, - pub tags : Vec, - pub format : TextureFormat, - pub resolution : (usize, usize), - pub texture_hash : Sha256 + pub id: String, + pub name: String, + pub tags: Vec, + pub format: TextureFormat, + pub resolution: (usize, usize), + pub texture_hash: Sha256, } - + pub enum TextureFormat { PNG, - JPG + JPG, } } -mod protocol { +pub mod protocol { + use crate::model::*; - + + use std::io; + pub enum ReplaceTextureStatus { // Call Again With Texture Binary NeedTextureData, // Done. Ok, } - - pub type ProtocolResult = Result; + + pub type ProtocolResult = Result; pub enum ProtocolError { - BadRequest(pub String), - FileNotFound(pub String), - Conflict(pub String), - InternalServerError(pub std::io::Error), + BadRequest(String), + FileNotFound(String), + Conflict(String), + InternalServerError(std::io::Error), NotImplemented, } - - pub trait ProtocolHandler : Send + Sync { - fn query(mut self, &[String]) -> - ProtocolError>; - - fn get_texture_by_id(mut self, id : String) -> - ProtocolError>; - - fn get_texture_by_name(mut self, id : String) -> - ProtocolError>; - - fn get_texture_file(mut self, hash : Sha256) -> - ProtocolError>; - - fn get_texture_preview(mut self, hash : Sha256) -> - ProtocolError>; - - fn replace_texture(mut self, - delete : Option, - insert : Option, - insert_texture_data : Option> - ) -> ProtocolError; + + pub trait ProtocolHandler: Send + Sync { + fn query(&mut self, query: &[String]) -> ProtocolResult>; + + fn get_texture_by_id(&mut self, id: String) -> ProtocolResult>; + + fn get_texture_by_name(&mut self, id: String) -> ProtocolResult>; + + fn get_texture_file(&mut self, hash: Sha256) -> ProtocolResult>; + + fn get_texture_preview(&mut self, hash: Sha256) -> ProtocolResult>; + + fn replace_texture( + &mut self, + delete: Option, + insert: Option, + insert_texture_data: Option>, + ) -> ProtocolResult; } - + pub struct ProtocolConfig { - pub port : u16, + pub port: u16, } - - pub fn listen_forever(handler : &ProtocolHandler) -> { - unimplemend!() + + pub fn listen_forever(handler: &ProtocolHandler) -> io::Result<()> { + unimplemented!() } } -mod persistency { +pub mod persistency { + use crate::model::*; + + use std::collections::HashMap; use std::io; - + use std::path::{Path, PathBuf}; + use std::sync::Arc; + pub struct DataStore { // private attributes + // may change + data_dir: PathBuf, + texture: Vec, + preview_cache: HashMap<(TextureFormat, Sha256), Arc>>, } - + impl DataStore { - pub fn new(path : Path) -> io::Result { - unimplemend!() + pub fn new(path: &Path) -> io::Result { + unimplemented!() } - - pub fn garbage_collect() -> io::Result<()> { - unimplemend!() + + pub fn garbage_collect(&mut self) -> io::Result<()> { + unimplemented!() } - + // TODO: think - } - - mod search { - use crate::model::*; - - pub struct Query { - filters : Vec, + + pub fn search(&mut self, query: &self::search::Query) -> Vec { + unimplemented!(); + // calls self::search::search(... ) } - - pub type QueryParserResult = Result; + } + + pub use self::search::Query; + + mod search { + + use crate::model::*; + + pub struct Query { + filters: Vec, + } + + pub type QueryParserResult = Result; pub enum QuerySyntaxError { UnknownFilter, } - + impl Query { - pub fn parse(input : &[String]) -> QueryParserResult{ - unimplemend!() + pub fn parse(input: &[String]) -> QueryParserResult { + unimplemented!() } } - - pub fn search(input : &[Texture], query : &Query) -> Vec { - + + pub fn search(input: &[Texture], query: &Query) -> Vec { + unimplemented!() } - + //private - enum QueryFilterModifier{ + enum QueryFilterModifier { None(QueryFilter), Not(QueryFilter), } - + //private enum QueryFilter { TagName(String), InName(String), MinResolution(usize), - BeforeDate { - year : u16, - month : u16, - day : u16, - } + BeforeDate { year: u16, month: u16, day: u16 }, } } - + } -mod image_convert { +pub mod image_convert { use crate::model::*; - + pub struct ConvertConfig { - pub desired_size : (usize, usize), + pub desired_size: (usize, usize), } - - pub generate_preview( - input : Vec, - format : Format - config : ConvertConfig, - ) -> ::image::ImageResult>; + + pub fn generate_preview( + input: &[u8], + format: TextureFormat, + config: &ConvertConfig, + ) -> ::image::ImageResult> { + unimplemented!() + } + } +pub mod main { -mod main { + use crate::model::*; + use crate::protocol::*; + + use std::sync::Arc; struct ServerState { // private attributes } - + impl ProtocolHandler for ServerState { - // .... + fn query(&mut self, query: &[String]) -> ProtocolResult> { + unimplemented!() + } + + fn get_texture_by_id(&mut self, id: String) -> ProtocolResult> { + unimplemented!() + } + + fn get_texture_by_name(&mut self, id: String) -> ProtocolResult> { + unimplemented!() + } + + fn get_texture_file(&mut self, hash: Sha256) -> ProtocolResult>> { + unimplemented!() + } + + fn get_texture_preview(&mut self, hash: Sha256) -> ProtocolResult>> { + unimplemented!() + } + + fn replace_texture( + &mut self, + delete: Option, + insert: Option, + insert_texture_data: Option>, + ) -> ProtocolResult { + unimplemented!() + } } - - - pub fn main(){ - unimplemend!() + + pub fn main() { + unimplemented!() } - - }