MCPcopy Index your code
hub / github.com/Firstyear/opensuse-proxy-cache / decode_cmd

Method decode_cmd

redis-server/src/codec.rs:63–139  ·  view source on GitHub ↗
(&mut self, buf: &mut BytesMut)

Source from the content-addressed store, hash-verified

61 }
62
63 fn decode_cmd(&mut self, buf: &mut BytesMut) -> Result<Option<RedisClientMsg>, io::Error> {
64 trace!("cap: {}: len: {}", buf.capacity(), buf.len());
65 // trace!("buf_raw: {:?}", String::from_utf8(buf.to_vec()))
66
67 let (_rem, (cmd, sz)) = match cmd_parser(buf.as_ref()) {
68 Ok(r) => r,
69 Err(Incomplete(_)) => {
70 if buf.len() >= MAX_CMD_LEN {
71 return Err(io::Error::new(io::ErrorKind::Other, "Command too long"));
72 } else {
73 debug!("Need more data");
74 return Ok(None);
75 }
76 }
77 Err(e) => {
78 error!(?e, "Malformed input");
79 return Err(io::Error::new(io::ErrorKind::Other, "Malformed Input"));
80 }
81 };
82
83 trace!(?cmd);
84
85 let r = match cmd {
86 Cmd::Wait => {
87 buf.clear();
88 trace!("WAIT cap: {}: len: {}", buf.capacity(), buf.len());
89 None
90 }
91 Cmd::Auth(pw) => Some(RedisClientMsg::Auth(pw.to_vec())),
92 Cmd::Get(key) => Some(RedisClientMsg::Get(key.to_vec())),
93 Cmd::Set(key, dsz) => {
94 // Okay, this is the fun one. We basicly need to setup for the next iter.
95 let fh = self.cache.new_tempfile().ok_or_else(|| {
96 error!("Unable to allocate temp file");
97 io::Error::new(io::ErrorKind::Other, "Server Error")
98 })?;
99 self.d_state = DecodeState::Set {
100 fh,
101 key: key.to_vec(),
102 dsz: dsz as usize,
103 rem: dsz as usize,
104 };
105 buf.advance(sz);
106 return self.process_set(buf);
107 }
108 Cmd::ConfigGet(key) => {
109 let skey = String::from_utf8(key.to_vec())
110 .map_err(|_| io::Error::new(io::ErrorKind::Other, "Invalid UTF8"))?;
111 Some(RedisClientMsg::ConfigGet(skey))
112 }
113
114 Cmd::ClientSetInfo(name, None) => {
115 let name = String::from_utf8(name.to_vec())
116 .map_err(|_| io::Error::new(io::ErrorKind::Other, "Invalid UTF8"))?;
117 Some(RedisClientMsg::ClientSetInfo(name, None))
118 }
119 Cmd::ClientSetInfo(name, Some(version)) => {
120 let name = String::from_utf8(name.to_vec())

Callers 1

decodeMethod · 0.80

Calls 3

cmd_parserFunction · 0.85
new_tempfileMethod · 0.80
process_setMethod · 0.80

Tested by

no test coverage detected