mirror of
https://git.mentality.rip/numas13/xash3d-master.git
synced 2025-02-02 02:04:16 +00:00
protocol: Allow specifying hash len
This commit is contained in:
parent
e6ae885eb9
commit
8b857ad2a1
@ -44,15 +44,20 @@ impl<'a> AdminCommand<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode(src: &'a [u8]) -> Result<Self, Error> {
|
||||
pub fn decode_with_hash_len(hash_len: usize, src: &'a [u8]) -> Result<Self, Error> {
|
||||
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, Error> {
|
||||
Self::decode_with_hash_len(HASH_LEN, src)
|
||||
}
|
||||
|
||||
pub fn encode(&self, buf: &mut [u8]) -> Result<usize, Error> {
|
||||
Ok(CursorMut::new(buf)
|
||||
.put_bytes(Self::HEADER)?
|
||||
|
Loading…
x
Reference in New Issue
Block a user