Skip to content

Commit f9028e7

Browse files
committed
fix: remove unnecessary breaking change in iproto code
We don't want to introduce breaking changes for no reason
1 parent 4484a9d commit f9028e7

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- `network::protocol::SyncIndex::get` method
1212
- `network::protocol::codec::{LegacyCall, Nop, Prepare, Begin, Commit, Rollback}` variants
1313
- `network::protocol::codec::Header::encode_from_parts` function
14+
- `network::protocol::codec::Header::{encode, decode}` functions
1415
- `network::protocol::codec::iproto_key::SQL_INFO` constant
1516
- Added optional field `connect_timeout` to `network::protocol::Config`.
1617
Used in `network::client::Client::connect_with_config` for
@@ -37,8 +38,6 @@ restricting time connection establishment.
3738
- tlua::LuaTable::get_or_create_metatable is deprecated now in favor of tlua::LuaTable::metatable.
3839

3940
### Breaking changes
40-
- Replace `network::protocol::codec::{encode_header, decode_header}` functions
41-
with `network::protocol::codec::Header::{encode, decode}` methods.
4241
- Use `extern "C-unwind"` instead of `extern "C"` for all trampolines which take `*mut ffi::lua_State`
4342
(checked with `rg 'extern "C".*lua_State'`). `tlua::error!` throws an exception to unwind the stack,
4443
hence we need to use a proper ABI to fix UB in picodata.

tarantool/src/network/protocol/codec.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ crate::define_enum_with_introspection! {
8787
}
8888
}
8989

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+
90108
pub fn chap_sha1_auth_data(password: &str, salt: &[u8]) -> Vec<u8> {
91109
// prepare 'chap-sha1' scramble:
92110
// salt = base64_decode(encoded_salt);
@@ -380,6 +398,10 @@ pub struct Header {
380398
}
381399

382400
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.
383405
pub fn encode(&self, stream: &mut impl Write) -> Result<(), Error> {
384406
rmp::encode::write_map_len(stream, 2)?;
385407
rmp::encode::write_pfix(stream, REQUEST_TYPE)?;
@@ -389,19 +411,20 @@ impl Header {
389411
Ok(())
390412
}
391413

414+
/// This function doesn't need to exist
415+
#[inline(always)]
392416
pub fn encode_from_parts(
393417
stream: &mut impl Write,
394418
sync: SyncIndex,
395419
request_type: IProtoType,
396420
) -> 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)
403422
}
404423

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.
405428
pub fn decode(stream: &mut (impl Read + Seek)) -> Result<Header, Error> {
406429
let mut sync: Option<u64> = None;
407430
let mut iproto_type: Option<u32> = None;
@@ -447,6 +470,12 @@ pub struct Response<T> {
447470
pub payload: T,
448471
}
449472

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+
450479
////////////////////////////////////////////////////////////////////////////////
451480
// error decoding
452481
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)