Skip to main content

crabka_protocol/borrowed/
txn_offset_commit_request.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2// Clippy lints that fire on generated code patterns are suppressed here so
3// that regenerating the file does not require manual allow annotations.
4#![allow(
5    clippy::absurd_extreme_comparisons,
6    clippy::cast_possible_truncation,
7    clippy::cast_possible_wrap,
8    clippy::cast_sign_loss,
9    clippy::default_trait_access,
10    clippy::must_use_candidate,
11    clippy::new_without_default,
12    clippy::nonminimal_bool,
13    clippy::too_many_lines,
14    clippy::unnecessary_wraps,
15    clippy::unreadable_literal,
16    unused_mut,
17    unused_variables
18)]
19
20include!(concat!(
21    env!("CARGO_MANIFEST_DIR"),
22    "/generated/TxnOffsetCommitRequest.borrowed.rs"
23));
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use crate::{DecodeBorrow, Encode};
28    use assert2::assert;
29    use bytes::BytesMut;
30    fn check(msg_bytes: &bytes::Bytes, v: i16) {
31        let mut cur: &[u8] = msg_bytes;
32        let decoded = TxnOffsetCommitRequest::decode_borrow(&mut cur, v).unwrap();
33        assert!(cur.is_empty());
34        assert!(decoded.encoded_len(v) == msg_bytes.len());
35        let mut reencoded = BytesMut::new();
36        decoded.encode(&mut reencoded, v).unwrap();
37        assert!(&reencoded[..] == &msg_bytes[..]);
38        let owned = decoded.to_owned();
39        let mut owned_buf = BytesMut::new();
40        owned.encode(&mut owned_buf, v).unwrap();
41        assert!(&owned_buf[..] == &msg_bytes[..]);
42    }
43    #[test]
44    fn default_roundtrips_all_versions() {
45        for v in MIN_VERSION..=MAX_VERSION {
46            let msg = TxnOffsetCommitRequest::default();
47            let mut buf = BytesMut::new();
48            msg.encode(&mut buf, v).unwrap();
49            check(&buf.freeze(), v);
50        }
51    }
52    #[test]
53    fn populated_roundtrips_all_versions() {
54        for v in MIN_VERSION..=MAX_VERSION {
55            let msg = TxnOffsetCommitRequest::populated(v);
56            let mut buf = BytesMut::new();
57            msg.encode(&mut buf, v).unwrap();
58            check(&buf.freeze(), v);
59        }
60    }
61}