refactor string / byte reads from buffer

This commit is contained in:
2025-07-01 15:44:21 +02:00
parent 51fdaa4120
commit 02aaef1560
11 changed files with 59 additions and 80 deletions

View File

@@ -1,8 +1,8 @@
use std::io::Cursor;
use bytes::{Buf as _, BufMut as _, BytesMut};
use bytes::{BufMut as _, BytesMut};
use crate::{Result, connection::Connection, database::Database, errors::AppError};
use crate::{Result, buffer::try_get_string, connection::Connection, database::Database};
#[derive(Debug, Clone)]
pub struct Delete {
@@ -29,13 +29,7 @@ impl Delete {
}
pub fn parse(bytes: &mut Cursor<&[u8]>) -> Result<Self> {
let key_length = bytes.try_get_u16()? as usize;
if bytes.remaining() < key_length {
return Err(AppError::IncompleteCommandBuffer);
}
let key = String::from_utf8(bytes.copy_to_bytes(key_length).to_vec())?;
let key = try_get_string(bytes)?;
Ok(Self { key })
}