@@ -45,7 +45,7 @@ pub enum Message<'a> {
45
45
param_types : & ' a [ Oid ] ,
46
46
} ,
47
47
PasswordMessage {
48
- password : & ' a str ,
48
+ password : & ' a [ u8 ] ,
49
49
} ,
50
50
Query {
51
51
query : & ' a str ,
@@ -200,8 +200,8 @@ where
200
200
buf. push ( b'B' ) ;
201
201
202
202
write_body ( buf, |buf| {
203
- buf. write_cstr ( portal) ?;
204
- buf. write_cstr ( statement) ?;
203
+ buf. write_cstr ( portal. as_bytes ( ) ) ?;
204
+ buf. write_cstr ( statement. as_bytes ( ) ) ?;
205
205
write_counted ( formats, |f, buf| buf. write_i16 :: < BigEndian > ( f) , buf) ?;
206
206
write_counted (
207
207
values,
@@ -249,7 +249,7 @@ pub fn close(variant: u8, name: &str, buf: &mut Vec<u8>) -> io::Result<()> {
249
249
buf. push ( b'C' ) ;
250
250
write_body ( buf, |buf| {
251
251
buf. push ( variant) ;
252
- buf. write_cstr ( name)
252
+ buf. write_cstr ( name. as_bytes ( ) )
253
253
} )
254
254
}
255
255
@@ -272,23 +272,23 @@ pub fn copy_done(buf: &mut Vec<u8>) {
272
272
#[ inline]
273
273
pub fn copy_fail ( message : & str , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > {
274
274
buf. push ( b'f' ) ;
275
- write_body ( buf, |buf| buf. write_cstr ( message) )
275
+ write_body ( buf, |buf| buf. write_cstr ( message. as_bytes ( ) ) )
276
276
}
277
277
278
278
#[ inline]
279
279
pub fn describe ( variant : u8 , name : & str , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > {
280
280
buf. push ( b'D' ) ;
281
281
write_body ( buf, |buf| {
282
282
buf. push ( variant) ;
283
- buf. write_cstr ( name)
283
+ buf. write_cstr ( name. as_bytes ( ) )
284
284
} )
285
285
}
286
286
287
287
#[ inline]
288
288
pub fn execute ( portal : & str , max_rows : i32 , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > {
289
289
buf. push ( b'E' ) ;
290
290
write_body ( buf, |buf| {
291
- buf. write_cstr ( portal) ?;
291
+ buf. write_cstr ( portal. as_bytes ( ) ) ?;
292
292
buf. write_i32 :: < BigEndian > ( max_rows) . unwrap ( ) ;
293
293
Ok ( ( ) )
294
294
} )
@@ -301,30 +301,30 @@ where
301
301
{
302
302
buf. push ( b'P' ) ;
303
303
write_body ( buf, |buf| {
304
- buf. write_cstr ( name) ?;
305
- buf. write_cstr ( query) ?;
304
+ buf. write_cstr ( name. as_bytes ( ) ) ?;
305
+ buf. write_cstr ( query. as_bytes ( ) ) ?;
306
306
write_counted ( param_types, |t, buf| buf. write_u32 :: < BigEndian > ( t) , buf) ?;
307
307
Ok ( ( ) )
308
308
} )
309
309
}
310
310
311
311
#[ inline]
312
- pub fn password_message ( password : & str , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > {
312
+ pub fn password_message ( password : & [ u8 ] , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > {
313
313
buf. push ( b'p' ) ;
314
314
write_body ( buf, |buf| buf. write_cstr ( password) )
315
315
}
316
316
317
317
#[ inline]
318
318
pub fn query ( query : & str , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > {
319
319
buf. push ( b'Q' ) ;
320
- write_body ( buf, |buf| buf. write_cstr ( query) )
320
+ write_body ( buf, |buf| buf. write_cstr ( query. as_bytes ( ) ) )
321
321
}
322
322
323
323
#[ inline]
324
324
pub fn sasl_initial_response ( mechanism : & str , data : & [ u8 ] , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > {
325
325
buf. push ( b'p' ) ;
326
326
write_body ( buf, |buf| {
327
- buf. write_cstr ( mechanism) ?;
327
+ buf. write_cstr ( mechanism. as_bytes ( ) ) ?;
328
328
let len = i32:: from_usize ( data. len ( ) ) ?;
329
329
buf. write_i32 :: < BigEndian > ( len) ?;
330
330
buf. extend_from_slice ( data) ;
@@ -354,8 +354,8 @@ where
354
354
write_body ( buf, |buf| {
355
355
buf. write_i32 :: < BigEndian > ( 196_608 ) . unwrap ( ) ;
356
356
for ( key, value) in parameters {
357
- buf. write_cstr ( key) ?;
358
- buf. write_cstr ( value) ?;
357
+ buf. write_cstr ( key. as_bytes ( ) ) ?;
358
+ buf. write_cstr ( value. as_bytes ( ) ) ?;
359
359
}
360
360
buf. push ( 0 ) ;
361
361
Ok ( ( ) )
@@ -375,19 +375,19 @@ pub fn terminate(buf: &mut Vec<u8>) {
375
375
}
376
376
377
377
trait WriteCStr {
378
- fn write_cstr ( & mut self , s : & str ) -> Result < ( ) , io:: Error > ;
378
+ fn write_cstr ( & mut self , s : & [ u8 ] ) -> Result < ( ) , io:: Error > ;
379
379
}
380
380
381
381
impl WriteCStr for Vec < u8 > {
382
382
#[ inline]
383
- fn write_cstr ( & mut self , s : & str ) -> Result < ( ) , io:: Error > {
384
- if s. as_bytes ( ) . contains ( & 0 ) {
383
+ fn write_cstr ( & mut self , s : & [ u8 ] ) -> Result < ( ) , io:: Error > {
384
+ if s. contains ( & 0 ) {
385
385
return Err ( io:: Error :: new (
386
386
io:: ErrorKind :: InvalidInput ,
387
387
"string contains embedded null" ,
388
388
) ) ;
389
389
}
390
- self . extend_from_slice ( s. as_bytes ( ) ) ;
390
+ self . extend_from_slice ( s) ;
391
391
self . push ( 0 ) ;
392
392
Ok ( ( ) )
393
393
}
0 commit comments