From 30e6b478d7cd286b68da21d7a5aa5426c588cd02 Mon Sep 17 00:00:00 2001 From: omagdy Date: Thu, 24 Jul 2025 06:04:32 +0300 Subject: refactor: Refactor how I model the state and config and cache of the server with sepraration of concerns --- src/rdb.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/rdb.rs') diff --git a/src/rdb.rs b/src/rdb.rs index 0195cb9..272d168 100644 --- a/src/rdb.rs +++ b/src/rdb.rs @@ -600,6 +600,20 @@ impl FromBytes for RDBFile { let mut total_consumed = 0; let mut databases = HashMap::new(); + // special case when rdb file is sent by the master to replicas in the following format + // $/r/n + if bytes[0] == '$' as u8 { + // consume up to the CRLF + let (consumed, rest) = bytes + .windows(2) + .position(|window| window == b"\r\n") + .map(|pos| (&bytes[..pos], &bytes[pos + 2..])) + .ok_or(ParseError::UnexpectedEof)?; + println!("Consumed {:?}", consumed); + remaining = rest; + total_consumed += consumed.len(); + } + // 1. Parse the RDB header ("REDIS" + version) let (header, consumed) = RDBHeader::from_bytes(remaining)?; total_consumed += consumed; -- cgit v1.2.3