create skeleton for server from design
This commit is contained in:
52
server/texture-sync-server/src/protocol/mod.rs
Normal file
52
server/texture-sync-server/src/protocol/mod.rs
Normal 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!()
|
||||
}
|
Reference in New Issue
Block a user