pub fn from_bytes(cmd_name: &[u8], buf: &[u8]) -> Result<Self, CommandError> {
        match cmd_name {
            ServerInfo::CMD_NAME => op_from_cmd!(buf, ServerInfo::try_parse, Op::INFO),
            ConnectCommand::CMD_NAME => op_from_cmd!(buf, ConnectCommand::try_parse, Op::CONNECT),
            Message::CMD_NAME => op_from_cmd!(buf, Message::try_parse, Op::MSG),
            PubCommand::CMD_NAME => op_from_cmd!(buf, PubCommand::try_parse, Op::PUB),
            SubCommand::CMD_NAME => op_from_cmd!(buf, SubCommand::try_parse, Op::SUB),
            UnsubCommand::CMD_NAME => op_from_cmd!(buf, UnsubCommand::try_parse, Op::UNSUB),
            b"PING" => {
                if buf == b"PING\r\n" {
                    Ok(Op::PING)
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
            b"PONG" => {
                if buf == b"PONG\r\n" {
                    Ok(Op::PONG)
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
            b"+OK" => {
                if buf == b"+OK\r\n" {
                    Ok(Op::OK)
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
            b"-ERR" => {
                if &buf[buf.len() - 2..] == b"\r\n" {
                    Ok(Op::ERR(ServerError::from(String::from_utf8(buf[1..].to_vec())?)))
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
            _ => {
                if buf.len() > 7 {
                    Err(CommandError::CommandNotFoundOrSupported)
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
        }
    }
/// Tries to parse from a pair of command name and whole buffer
Tries to parse from a pair of command name and whole buffer
Tries to parse from a pair of command name and whole buffer
pub fn from_bytes(cmd_name: &[u8], buf: &[u8]) -> Result<Self, CommandError> {
        match cmd_name {
            ServerInfo::CMD_NAME => op_from_cmd!(buf, ServerInfo::try_parse, Op::INFO),
            ConnectCommand::CMD_NAME => op_from_cmd!(buf, ConnectCommand::try_parse, Op::CONNECT),
            Message::CMD_NAME => op_from_cmd!(buf, Message::try_parse, Op::MSG),
            PubCommand::CMD_NAME => op_from_cmd!(buf, PubCommand::try_parse, Op::PUB),
            SubCommand::CMD_NAME => op_from_cmd!(buf, SubCommand::try_parse, Op::SUB),
            UnsubCommand::CMD_NAME => op_from_cmd!(buf, UnsubCommand::try_parse, Op::UNSUB),
            b"PING" => {
                if buf == b"PING\r\n" {
                    Ok(Op::PING)
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
            b"PONG" => {
                if buf == b"PONG\r\n" {
                    Ok(Op::PONG)
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
            b"+OK" => {
                if buf == b"+OK\r\n" {
                    Ok(Op::OK)
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
            b"-ERR" => {
                if &buf[buf.len() - 2..] == b"\r\n" {
                    Ok(Op::ERR(ServerError::from(String::from_utf8(buf[1..].to_vec())?)))
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
            _ => {
                if buf.len() > 7 {
                    Err(CommandError::CommandNotFoundOrSupported)
                } else {
                    Err(CommandError::IncompleteCommandError)
                }
            }
        }
    }
pub fn from_bytes ( cmd_name : & [ u8 ] , buf : & [ u8 ] ) -> Result < Self , CommandError > { match cmd_name { ServerInfo :: CMD_NAME => op_from_cmd ! ( buf ServerInfo try_parse Op INFO ) , ConnectCommand :: CMD_NAME => op_from_cmd ! ( buf ConnectCommand try_parse Op CONNECT ) , Message :: CMD_NAME => op_from_cmd ! ( buf Message try_parse Op MSG ) , PubCommand :: CMD_NAME => op_from_cmd ! ( buf PubCommand try_parse Op PUB ) , SubCommand :: CMD_NAME => op_from_cmd ! ( buf SubCommand try_parse Op SUB ) , UnsubCommand :: CMD_NAME => op_from_cmd ! ( buf UnsubCommand try_parse Op UNSUB ) , b" " => { if buf == b" \r \n " { Ok ( Op :: PING ) } else { Err ( CommandError :: IncompleteCommandError ) } } b" " => { if buf == b" \r \n " { Ok ( Op :: PONG ) } else { Err ( CommandError :: IncompleteCommandError ) } } b" " => { if buf == b" \r \n " { Ok ( Op :: OK ) } else { Err ( CommandError :: IncompleteCommandError ) } } b" " => { if & buf [ buf . len ( ) - 2 .. ] == b" \r \n " { Ok ( Op :: ERR ( ServerError :: from ( String :: from_utf8 ( buf [ 1 .. ] . to_vec ( ) ) ? ) ) ) } else { Err ( CommandError :: IncompleteCommandError ) } } _ => { if buf . len ( ) > 7 { Err ( CommandError :: CommandNotFoundOrSupported ) } else { Err ( CommandError :: IncompleteCommandError ) } } } }
Tries to parse from a pair of command name and whole buffer
Tries to parse from a pair of command name and whole buffer
cmd_name
&[u8]
buf
&[u8]
cmd_name
&[u8]
buf
&[u8]