Skip to main content

crabka_protocol/borrowed/
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/OffsetCommitRequest.borrowed.rs"
23));
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use crate::{DecodeBorrow, Encode};
29    use assert2::assert;
30    use bytes::BytesMut;
31
32    fn check(msg_bytes: &bytes::Bytes, v: i16) {
33        let mut cur: &[u8] = msg_bytes;
34        let decoded = OffsetCommitRequest::decode_borrow(&mut cur, v).unwrap();
35        assert!(cur.is_empty());
36        assert!(decoded.encoded_len(v) == msg_bytes.len());
37        let mut reencoded = BytesMut::new();
38        decoded.encode(&mut reencoded, v).unwrap();
39        assert!(&reencoded[..] == &msg_bytes[..]);
40        // Exercise the zero-copy -> owned conversion, then confirm the owned
41        // value still encodes to the same bytes.
42        let owned = decoded.to_owned();
43        let mut owned_buf = BytesMut::new();
44        owned.encode(&mut owned_buf, v).unwrap();
45        assert!(&owned_buf[..] == &msg_bytes[..]);
46    }
47
48    #[test]
49    fn default_roundtrips_all_versions() {
50        for v in MIN_VERSION..=MAX_VERSION {
51            let msg = OffsetCommitRequest::default();
52            let mut buf = BytesMut::new();
53            msg.encode(&mut buf, v).unwrap();
54            check(&buf.freeze(), v);
55        }
56    }
57
58    #[test]
59    fn populated_roundtrips_all_versions() {
60        for v in MIN_VERSION..=MAX_VERSION {
61            let msg = OffsetCommitRequest::populated(v);
62            let mut buf = BytesMut::new();
63            msg.encode(&mut buf, v).unwrap();
64            check(&buf.freeze(), v);
65        }
66    }
67}