Found some bugs
This commit is contained in:
1 parent
ec73c54276
commit
8b593939e5
3 files changed
+13
-6
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ use std::io::Read;
|
||||
use std::net::UdpSocket;
|
||||
use std::sync::mpsc::*;
|
||||
|
||||
const LISTEN: &str = "127.0.0.1:8080";
|
||||
const LISTEN: &str = "127.0.0.1:5555";
|
||||
|
||||
fn main() {
|
||||
let (cw, cr) = channel::<Command>();
|
||||
|
||||
@@ -3,11 +3,14 @@ use crate::server::{Command, NoteContext, StoredData};
|
||||
use litemap::LiteMap;
|
||||
use std::io::Write;
|
||||
use std::string::String;
|
||||
use log::info;
|
||||
|
||||
impl NoteContext {
|
||||
pub fn execute_command(&mut self, command: Command) {
|
||||
match command {
|
||||
Command::Unknown => {}
|
||||
Command::Unknown => {
|
||||
println!("Unknown command");
|
||||
}
|
||||
Command::Set(key, value) => self.set(key, value),
|
||||
Command::Define(key, schema) => self.define(key, schema),
|
||||
Command::Push(key, value) => self.push(key, value),
|
||||
|
||||
+8
-4
@@ -2,11 +2,11 @@ mod handling;
|
||||
mod testing;
|
||||
|
||||
use litemap::LiteMap;
|
||||
use minicbor::Decoder;
|
||||
use minicbor::data::Type;
|
||||
use minicbor::decode::Error;
|
||||
use minicbor::Decoder;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Formatter };
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::io::Write;
|
||||
|
||||
pub enum Command {
|
||||
@@ -73,7 +73,10 @@ impl Display for Line {
|
||||
|
||||
impl From<&[u8]> for Command {
|
||||
fn from(value: &[u8]) -> Self {
|
||||
parse_command(value).unwrap_or(Command::Unknown)
|
||||
parse_command(value).unwrap_or_else(|e| {
|
||||
println!("{}", e);
|
||||
Command::Unknown
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +90,7 @@ fn parse_command(data: &[u8]) -> Result<Command, Error> {
|
||||
return Ok(Command::Set(id, value));
|
||||
}
|
||||
if data.starts_with(b"PUSH:") {
|
||||
println!("{}", String::from_utf8_lossy(data));
|
||||
let payload = &data[b"PUSH:".len()..];
|
||||
let mut decoder = Decoder::new(&payload);
|
||||
decoder.array()?;
|
||||
@@ -152,7 +156,7 @@ pub struct NoteContext {
|
||||
|
||||
impl NoteContext {
|
||||
pub fn default() -> Self {
|
||||
Self{
|
||||
Self {
|
||||
entries: Default::default(),
|
||||
output: Box::new(std::io::stdout()),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user