vim server_architektur; first draft of pseudo rust.
This commit is contained in:
		
							
								
								
									
										170
									
								
								doc/feindesign/server_architektur.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										170
									
								
								doc/feindesign/server_architektur.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,170 @@
 | 
			
		||||
// main author: Robin Willmann
 | 
			
		||||
// date : see git.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// WIP, changes welcome
 | 
			
		||||
 | 
			
		||||
mod model {
 | 
			
		||||
    pub struct Sha256(pub [64;u8]);
 | 
			
		||||
    
 | 
			
		||||
    pub struct Texture {
 | 
			
		||||
        pub id : String,
 | 
			
		||||
        pub name : String,
 | 
			
		||||
        pub tags : Vec<String>,
 | 
			
		||||
        pub format : TextureFormat,
 | 
			
		||||
        pub resolution : (usize, usize),
 | 
			
		||||
        pub texture_hash : Sha256
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    pub enum TextureFormat {
 | 
			
		||||
        PNG,
 | 
			
		||||
        JPG
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mod protocol {
 | 
			
		||||
    use crate::model::*;
 | 
			
		||||
    
 | 
			
		||||
    pub enum ReplaceTextureStatus {
 | 
			
		||||
        // Call Again With Texture Binary
 | 
			
		||||
        NeedTextureData,
 | 
			
		||||
        // Done.
 | 
			
		||||
        Ok,
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    pub type ProtocolResult<T> = Result<T, NetworkError>;
 | 
			
		||||
    pub enum ProtocolError {
 | 
			
		||||
        BadRequest(pub String),
 | 
			
		||||
        FileNotFound(pub String),
 | 
			
		||||
        Conflict(pub String),
 | 
			
		||||
        InternalServerError(pub std::io::Error),
 | 
			
		||||
        NotImplemented,
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    pub trait ProtocolHandler : Send + Sync {
 | 
			
		||||
        fn query(mut self, &[String]) ->  
 | 
			
		||||
            ProtocolError<Vec<Texture>>;
 | 
			
		||||
        
 | 
			
		||||
        fn get_texture_by_id(mut self, id : String) ->          
 | 
			
		||||
            ProtocolError<Option<Texture>>;
 | 
			
		||||
            
 | 
			
		||||
        fn get_texture_by_name(mut self, id : String) -> 
 | 
			
		||||
            ProtocolError<Option<Texture>>;
 | 
			
		||||
            
 | 
			
		||||
        fn get_texture_file(mut self, hash : Sha256) -> 
 | 
			
		||||
            ProtocolError<Vec<u8>>;
 | 
			
		||||
        
 | 
			
		||||
        fn get_texture_preview(mut self, hash : Sha256) -> 
 | 
			
		||||
            ProtocolError<Vec<u8>>;
 | 
			
		||||
        
 | 
			
		||||
        fn replace_texture(mut self, 
 | 
			
		||||
                delete : Option<Texture>, 
 | 
			
		||||
                insert : Option<Texture>,
 | 
			
		||||
                insert_texture_data : Option<Vec<u8>>
 | 
			
		||||
            )  -> ProtocolError<ReplaceTextureStatus>;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    pub struct ProtocolConfig {
 | 
			
		||||
        pub port : u16,
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    pub fn listen_forever(handler : &ProtocolHandler) -> {
 | 
			
		||||
        unimplemend!()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mod persistency {
 | 
			
		||||
 | 
			
		||||
    use std::io;
 | 
			
		||||
    
 | 
			
		||||
    pub struct DataStore {
 | 
			
		||||
        // private attributes
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    impl DataStore {
 | 
			
		||||
        pub fn new(path : Path) -> io::Result<DataStore> {
 | 
			
		||||
            unimplemend!()
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        pub fn garbage_collect() -> io::Result<()> {
 | 
			
		||||
            unimplemend!()
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // TODO: think
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    mod search {
 | 
			
		||||
        use crate::model::*;
 | 
			
		||||
        
 | 
			
		||||
        pub struct Query {
 | 
			
		||||
            filters : Vec<QueryFilterModifier>,
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        pub type QueryParserResult<T> =  Result<Query, QuerySyntaxError>;
 | 
			
		||||
        pub enum QuerySyntaxError {
 | 
			
		||||
            UnknownFilter,
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        impl Query {
 | 
			
		||||
            pub fn parse(input : &[String]) -> QueryParserResult{
 | 
			
		||||
                unimplemend!()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        pub fn search(input : &[Texture], query : &Query) -> Vec<Texture> {
 | 
			
		||||
        
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        //private
 | 
			
		||||
        enum QueryFilterModifier{
 | 
			
		||||
            None(QueryFilter),
 | 
			
		||||
            Not(QueryFilter),
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        //private
 | 
			
		||||
        enum QueryFilter {
 | 
			
		||||
            TagName(String),
 | 
			
		||||
            InName(String),
 | 
			
		||||
            MinResolution(usize),
 | 
			
		||||
            BeforeDate {
 | 
			
		||||
                year : u16,
 | 
			
		||||
                month : u16,
 | 
			
		||||
                day   : u16,
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
   
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mod image_convert {
 | 
			
		||||
    use crate::model::*;
 | 
			
		||||
    
 | 
			
		||||
    pub struct ConvertConfig {
 | 
			
		||||
        pub desired_size : (usize, usize),
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    pub generate_preview(
 | 
			
		||||
        input  : Vec<u8>,
 | 
			
		||||
        format : Format
 | 
			
		||||
        config : ConvertConfig,
 | 
			
		||||
    ) -> ::image::ImageResult<Vec<u8>>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
mod main {
 | 
			
		||||
 | 
			
		||||
    struct ServerState {
 | 
			
		||||
        // private attributes
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    impl ProtocolHandler for ServerState {
 | 
			
		||||
        // ....
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    pub fn main(){
 | 
			
		||||
         unimplemend!()
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user