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

@@ -2,7 +2,7 @@ use std::io::Cursor;
use bytes::{Buf as _, Bytes};
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 Expire {
@@ -22,14 +22,7 @@ impl Expire {
}
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)?;
let seconds = bytes.try_get_u64()?;
Ok(Self { key, seconds })