@@ -87,6 +87,24 @@ crate::define_enum_with_introspection! {
87
87
}
88
88
}
89
89
90
+ /// Encode an IPROTO request header.
91
+ #[ inline( always) ]
92
+ pub fn encode_header (
93
+ stream : & mut impl Write ,
94
+ sync : SyncIndex ,
95
+ request_type : IProtoType ,
96
+ ) -> Result < ( ) , Error > {
97
+ let helper = Header {
98
+ sync,
99
+ iproto_type : request_type as _ ,
100
+ // Not used when encoding a request
101
+ error_code : 0 ,
102
+ // Not used when encoding a request
103
+ schema_version : 0 ,
104
+ } ;
105
+ helper. encode ( stream)
106
+ }
107
+
90
108
pub fn chap_sha1_auth_data ( password : & str , salt : & [ u8 ] ) -> Vec < u8 > {
91
109
// prepare 'chap-sha1' scramble:
92
110
// salt = base64_decode(encoded_salt);
@@ -380,6 +398,10 @@ pub struct Header {
380
398
}
381
399
382
400
impl Header {
401
+ /// Encode an IPROTO request header.
402
+ ///
403
+ // FIXME: bad name, this encodes a request header, hence error_code & schema_version are ignored.
404
+ // This code will not work if we want to implement the server side of the protocol.
383
405
pub fn encode ( & self , stream : & mut impl Write ) -> Result < ( ) , Error > {
384
406
rmp:: encode:: write_map_len ( stream, 2 ) ?;
385
407
rmp:: encode:: write_pfix ( stream, REQUEST_TYPE ) ?;
@@ -389,19 +411,20 @@ impl Header {
389
411
Ok ( ( ) )
390
412
}
391
413
414
+ /// This function doesn't need to exist
415
+ #[ inline( always) ]
392
416
pub fn encode_from_parts (
393
417
stream : & mut impl Write ,
394
418
sync : SyncIndex ,
395
419
request_type : IProtoType ,
396
420
) -> Result < ( ) , Error > {
397
- rmp:: encode:: write_map_len ( stream, 2 ) ?;
398
- rmp:: encode:: write_pfix ( stream, REQUEST_TYPE ) ?;
399
- rmp:: encode:: write_pfix ( stream, request_type as u8 ) ?;
400
- rmp:: encode:: write_pfix ( stream, SYNC ) ?;
401
- rmp:: encode:: write_uint ( stream, sync. 0 ) ?;
402
- Ok ( ( ) )
421
+ encode_header ( stream, sync, request_type)
403
422
}
404
423
424
+ /// Decode an IPROTO response header.
425
+ ///
426
+ // FIXME: bad name, this decodes only response headers.
427
+ // This code will not work if we want to implement the server side of the protocol.
405
428
pub fn decode ( stream : & mut ( impl Read + Seek ) ) -> Result < Header , Error > {
406
429
let mut sync: Option < u64 > = None ;
407
430
let mut iproto_type: Option < u32 > = None ;
@@ -447,6 +470,12 @@ pub struct Response<T> {
447
470
pub payload : T ,
448
471
}
449
472
473
+ /// Decode an IPROTO response header.
474
+ #[ inline( always) ]
475
+ pub fn decode_header ( stream : & mut ( impl Read + Seek ) ) -> Result < Header , Error > {
476
+ Header :: decode ( stream)
477
+ }
478
+
450
479
////////////////////////////////////////////////////////////////////////////////
451
480
// error decoding
452
481
////////////////////////////////////////////////////////////////////////////////
0 commit comments