MCPcopy Create free account
hub / github.com/HFQR/xitca-web / decode

Method decode

http-ws/src/codec.rs:178–226  ·  view source on GitHub ↗
(&mut self, src: &mut BytesMut)

Source from the content-addressed store, hash-verified

176 }
177
178 pub fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Message>, ProtocolError> {
179 if self.recv_closed() {
180 return Err(ProtocolError::RecvClosed);
181 }
182
183 match Parser::parse(src, self.flags.contains(Flags::SERVER), self.max_size)? {
184 Some((finished, opcode, payload)) => match opcode {
185 OpCode::Continue if !self.flags.contains(Flags::CONTINUATION) => {
186 Err(ProtocolError::ContinuationNotStarted)
187 }
188 OpCode::Continue => {
189 if finished {
190 self.flags.remove(Flags::CONTINUATION);
191 }
192 Ok(Some(Message::Continuation(Item::Continue(
193 payload.unwrap_or_else(Bytes::new),
194 ))))
195 }
196 OpCode::Binary if !finished => {
197 self.try_start_continue()?;
198 Ok(Some(Message::Continuation(Item::FirstBinary(
199 payload.unwrap_or_else(Bytes::new),
200 ))))
201 }
202 OpCode::Text if !finished => {
203 self.try_start_continue()?;
204 Ok(Some(Message::Continuation(Item::FirstText(
205 payload.unwrap_or_else(Bytes::new),
206 ))))
207 }
208 OpCode::Close if !finished => {
209 error!("Unfinished fragment {:?}", opcode);
210 Err(ProtocolError::ContinuationFragment(opcode))
211 }
212 OpCode::Binary => Ok(Some(Message::Binary(payload.unwrap_or_else(Bytes::new)))),
213 OpCode::Text => Ok(Some(Message::Text(payload.unwrap_or_else(Bytes::new)))),
214 OpCode::Close => {
215 self.set_recv_closed();
216 Ok(Some(Message::Close(
217 payload.as_deref().and_then(Parser::parse_close_payload),
218 )))
219 }
220 OpCode::Ping => Ok(Some(Message::Ping(payload.unwrap_or_else(Bytes::new)))),
221 OpCode::Pong => Ok(Some(Message::Pong(payload.unwrap_or_else(Bytes::new)))),
222 OpCode::Bad => Err(ProtocolError::BadOpCode),
223 },
224 None => Ok(None),
225 }
226 }
227
228 fn try_start_continue(&mut self) -> Result<(), ProtocolError> {
229 if !self.flags.contains(Flags::CONTINUATION) {

Callers 3

grpcMethod · 0.45
poll_frameMethod · 0.45
poll_nextMethod · 0.45

Calls 10

ContinuationClass · 0.85
TextClass · 0.85
CloseClass · 0.85
PingClass · 0.85
recv_closedMethod · 0.80
try_start_continueMethod · 0.80
set_recv_closedMethod · 0.80
and_thenMethod · 0.80
containsMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected