create skeleton for server from design

This commit is contained in:
2019-04-20 01:24:19 +02:00
parent 6f86302e06
commit 88fae2cba4
10 changed files with 277 additions and 245 deletions

View File

@ -0,0 +1,52 @@
// TODO: remove on implementation
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use crate::model::*;
use std::sync::Arc;
use std::io;
pub enum ReplaceTextureStatus {
// Call Again With Texture Binary
NeedTextureData,
// Done.
Ok,
}
pub type ProtocolResult<T> = Result<T, ProtocolError>;
pub enum ProtocolError {
BadRequest(String),
FileNotFound(String),
Conflict(String),
InternalServerError(std::io::Error),
NotImplemented,
}
pub trait ProtocolHandler: Send + Sync {
fn query(&mut self, query: &[String]) -> ProtocolResult<Vec<Texture>>;
fn get_texture_by_id(&mut self, id: String) -> ProtocolResult<Option<Texture>>;
fn get_texture_by_name(&mut self, id: String) -> ProtocolResult<Option<Texture>>;
fn get_texture_file(&mut self, hash: Sha256) -> ProtocolResult<Arc<Vec<u8>>>;
fn get_texture_preview(&mut self, hash: Sha256) -> ProtocolResult<Arc<Vec<u8>>>;
fn replace_texture(
&mut self,
delete: Option<Texture>,
insert: Option<Texture>,
insert_texture_data: Option<Vec<u8>>,
) -> ProtocolResult<ReplaceTextureStatus>;
}
pub struct ProtocolConfig {
pub port: u16,
}
pub fn listen_forever(handler: &ProtocolHandler) -> io::Result<()> {
unimplemented!()
}