Found some bugs

This commit is contained in:
micialware committed 2026-09-16 11:03:43 +03:00
1 parent ec73c54276
commit 8b593939e5
3 files changed
+11 -4

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@ use std::io::Read;
use std::net::UdpSocket; use std::net::UdpSocket;
use std::sync::mpsc::*; use std::sync::mpsc::*;
const LISTEN: &str = "127.0.0.1:8080"; const LISTEN: &str = "127.0.0.1:5555";
fn main() { fn main() {
let (cw, cr) = channel::<Command>(); let (cw, cr) = channel::<Command>();
+4 -1
View File
@@ -3,11 +3,14 @@ use crate::server::{Command, NoteContext, StoredData};
use litemap::LiteMap; use litemap::LiteMap;
use std::io::Write; use std::io::Write;
use std::string::String; use std::string::String;
use log::info;
impl NoteContext { impl NoteContext {
pub fn execute_command(&mut self, command: Command) { pub fn execute_command(&mut self, command: Command) {
match command { match command {
Command::Unknown => {} Command::Unknown => {
println!("Unknown command");
}
Command::Set(key, value) => self.set(key, value), Command::Set(key, value) => self.set(key, value),
Command::Define(key, schema) => self.define(key, schema), Command::Define(key, schema) => self.define(key, schema),
Command::Push(key, value) => self.push(key, value), Command::Push(key, value) => self.push(key, value),
+6 -2
View File
@@ -2,9 +2,9 @@ mod handling;
mod testing; mod testing;
use litemap::LiteMap; use litemap::LiteMap;
use minicbor::Decoder;
use minicbor::data::Type; use minicbor::data::Type;
use minicbor::decode::Error; use minicbor::decode::Error;
use minicbor::Decoder;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::io::Write; use std::io::Write;
@@ -73,7 +73,10 @@ impl Display for Line {
impl From<&[u8]> for Command { impl From<&[u8]> for Command {
fn from(value: &[u8]) -> Self { 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)); return Ok(Command::Set(id, value));
} }
if data.starts_with(b"PUSH:") { if data.starts_with(b"PUSH:") {
println!("{}", String::from_utf8_lossy(data));
let payload = &data[b"PUSH:".len()..]; let payload = &data[b"PUSH:".len()..];
let mut decoder = Decoder::new(&payload); let mut decoder = Decoder::new(&payload);
decoder.array()?; decoder.array()?;