|
1 | 1 | #![allow(missing_docs)]
|
2 | 2 |
|
3 |
| -use byteorder::{ReadBytesExt, BigEndian}; |
| 3 | +use byteorder::{BigEndian, ReadBytesExt}; |
4 | 4 | use bytes::{Bytes, BytesMut};
|
5 | 5 | use fallible_iterator::FallibleIterator;
|
6 | 6 | use memchr::memchr;
|
@@ -148,45 +148,41 @@ impl Message {
|
148 | 148 | let storage = buf.read_all();
|
149 | 149 | Message::NoticeResponse(NoticeResponseBody { storage: storage })
|
150 | 150 | }
|
151 |
| - b'R' => { |
152 |
| - match buf.read_i32::<BigEndian>()? { |
153 |
| - 0 => Message::AuthenticationOk, |
154 |
| - 2 => Message::AuthenticationKerberosV5, |
155 |
| - 3 => Message::AuthenticationCleartextPassword, |
156 |
| - 5 => { |
157 |
| - let mut salt = [0; 4]; |
158 |
| - buf.read_exact(&mut salt)?; |
159 |
| - Message::AuthenticationMd5Password( |
160 |
| - AuthenticationMd5PasswordBody { salt: salt }, |
161 |
| - ) |
162 |
| - } |
163 |
| - 6 => Message::AuthenticationScmCredential, |
164 |
| - 7 => Message::AuthenticationGss, |
165 |
| - 8 => { |
166 |
| - let storage = buf.read_all(); |
167 |
| - Message::AuthenticationGssContinue(AuthenticationGssContinueBody(storage)) |
168 |
| - } |
169 |
| - 9 => Message::AuthenticationSspi, |
170 |
| - 10 => { |
171 |
| - let storage = buf.read_all(); |
172 |
| - Message::AuthenticationSasl(AuthenticationSaslBody(storage)) |
173 |
| - } |
174 |
| - 11 => { |
175 |
| - let storage = buf.read_all(); |
176 |
| - Message::AuthenticationSaslContinue(AuthenticationSaslContinueBody(storage)) |
177 |
| - } |
178 |
| - 12 => { |
179 |
| - let storage = buf.read_all(); |
180 |
| - Message::AuthenticationSaslFinal(AuthenticationSaslFinalBody(storage)) |
181 |
| - } |
182 |
| - tag => { |
183 |
| - return Err(io::Error::new( |
184 |
| - io::ErrorKind::InvalidInput, |
185 |
| - format!("unknown authentication tag `{}`", tag), |
186 |
| - )); |
187 |
| - } |
| 151 | + b'R' => match buf.read_i32::<BigEndian>()? { |
| 152 | + 0 => Message::AuthenticationOk, |
| 153 | + 2 => Message::AuthenticationKerberosV5, |
| 154 | + 3 => Message::AuthenticationCleartextPassword, |
| 155 | + 5 => { |
| 156 | + let mut salt = [0; 4]; |
| 157 | + buf.read_exact(&mut salt)?; |
| 158 | + Message::AuthenticationMd5Password(AuthenticationMd5PasswordBody { salt: salt }) |
188 | 159 | }
|
189 |
| - } |
| 160 | + 6 => Message::AuthenticationScmCredential, |
| 161 | + 7 => Message::AuthenticationGss, |
| 162 | + 8 => { |
| 163 | + let storage = buf.read_all(); |
| 164 | + Message::AuthenticationGssContinue(AuthenticationGssContinueBody(storage)) |
| 165 | + } |
| 166 | + 9 => Message::AuthenticationSspi, |
| 167 | + 10 => { |
| 168 | + let storage = buf.read_all(); |
| 169 | + Message::AuthenticationSasl(AuthenticationSaslBody(storage)) |
| 170 | + } |
| 171 | + 11 => { |
| 172 | + let storage = buf.read_all(); |
| 173 | + Message::AuthenticationSaslContinue(AuthenticationSaslContinueBody(storage)) |
| 174 | + } |
| 175 | + 12 => { |
| 176 | + let storage = buf.read_all(); |
| 177 | + Message::AuthenticationSaslFinal(AuthenticationSaslFinalBody(storage)) |
| 178 | + } |
| 179 | + tag => { |
| 180 | + return Err(io::Error::new( |
| 181 | + io::ErrorKind::InvalidInput, |
| 182 | + format!("unknown authentication tag `{}`", tag), |
| 183 | + )); |
| 184 | + } |
| 185 | + }, |
190 | 186 | b's' => Message::PortalSuspended,
|
191 | 187 | b'S' => {
|
192 | 188 | let name = buf.read_cstr()?;
|
@@ -394,6 +390,11 @@ impl CopyDataBody {
|
394 | 390 | pub fn data(&self) -> &[u8] {
|
395 | 391 | &self.storage
|
396 | 392 | }
|
| 393 | + |
| 394 | + #[inline] |
| 395 | + pub fn into_bytes(self) -> Bytes { |
| 396 | + self.storage |
| 397 | + } |
397 | 398 | }
|
398 | 399 |
|
399 | 400 | pub struct CopyInResponseBody {
|
|
0 commit comments