(&mut self)
| 101 | { |
| 102 | #[allow(clippy::collapsible_if)] |
| 103 | fn read_message_begin(&mut self) -> crate::Result<TMessageIdentifier> { |
| 104 | // TODO: Once specialization is stable, call the message size tracking here |
| 105 | let mut first_bytes = vec![0; 4]; |
| 106 | self.transport.read_exact(&mut first_bytes[..])?; |
| 107 | |
| 108 | // the thrift version header is intentionally negative |
| 109 | // so the first check we'll do is see if the sign bit is set |
| 110 | // and if so - assume it's the protocol-version header |
| 111 | if (first_bytes[0] & 0x80) != 0 { |
| 112 | // apparently we got a protocol-version header - check |
| 113 | // it, and if it matches, read the rest of the fields |
| 114 | if first_bytes[0..2] != [0x80, 0x01] { |
| 115 | Err(crate::Error::Protocol(ProtocolError { |
| 116 | kind: ProtocolErrorKind::BadVersion, |
| 117 | message: format!("received bad version: {:?}", &first_bytes[0..2]), |
| 118 | })) |
| 119 | } else { |
| 120 | let message_type: TMessageType = TryFrom::try_from(first_bytes[3])?; |
| 121 | let name = self.read_string()?; |
| 122 | let sequence_number = self.read_i32()?; |
| 123 | Ok(TMessageIdentifier::new(name, message_type, sequence_number)) |
| 124 | } |
| 125 | } else { |
| 126 | // apparently we didn't get a protocol-version header, |
| 127 | // which happens if the sender is not using the strict protocol |
| 128 | if self.strict { |
| 129 | // we're in strict mode however, and that always |
| 130 | // requires the protocol-version header to be written first |
| 131 | Err(crate::Error::Protocol(ProtocolError { |
| 132 | kind: ProtocolErrorKind::BadVersion, |
| 133 | message: format!("received bad version: {:?}", &first_bytes[0..2]), |
| 134 | })) |
| 135 | } else { |
| 136 | // in the non-strict version the first message field |
| 137 | // is the message name. strings (byte arrays) are length-prefixed, |
| 138 | // so we've just read the length in the first 4 bytes |
| 139 | let name_size = BigEndian::read_i32(&first_bytes) as usize; |
| 140 | let mut name_buf: Vec<u8> = vec![0; name_size]; |
| 141 | self.transport.read_exact(&mut name_buf)?; |
| 142 | let name = String::from_utf8(name_buf)?; |
| 143 | |
| 144 | // read the rest of the fields |
| 145 | let message_type: TMessageType = self.read_byte().and_then(TryFrom::try_from)?; |
| 146 | let sequence_number = self.read_i32()?; |
| 147 | Ok(TMessageIdentifier::new(name, message_type, sequence_number)) |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | fn read_message_end(&mut self) -> crate::Result<()> { |
| 153 | Ok(()) |
nothing calls this directly
no test coverage detected