refactor string / byte reads from buffer
This commit is contained in:
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user