From 8b857ad2a1972e58e7c324dc4ef64f96e8fa2ef9 Mon Sep 17 00:00:00 2001 From: Denis Drakhnia Date: Tue, 17 Oct 2023 15:50:36 +0300 Subject: [PATCH] protocol: Allow specifying hash len --- protocol/src/admin.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/protocol/src/admin.rs b/protocol/src/admin.rs index a1c162e..8e96c07 100644 --- a/protocol/src/admin.rs +++ b/protocol/src/admin.rs @@ -44,15 +44,20 @@ impl<'a> AdminCommand<'a> { } } - pub fn decode(src: &'a [u8]) -> Result { + pub fn decode_with_hash_len(hash_len: usize, src: &'a [u8]) -> Result { let mut cur = Cursor::new(src); cur.expect(Self::HEADER)?; - let hash = cur.get_bytes(HASH_LEN)?; + let hash = cur.get_bytes(hash_len)?; let command = Str(cur.get_bytes(cur.remaining())?); cur.expect_empty()?; Ok(Self { hash, command }) } + #[inline] + pub fn decode(src: &'a [u8]) -> Result { + Self::decode_with_hash_len(HASH_LEN, src) + } + pub fn encode(&self, buf: &mut [u8]) -> Result { Ok(CursorMut::new(buf) .put_bytes(Self::HEADER)?