krabka_protocol/opt/rustwide/workdir/generated/
NoOpRecord.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
8};
9pub const MIN_VERSION: i16 = 0;
10pub const MAX_VERSION: i16 = 0;
11pub const FLEXIBLE_MIN: i16 = 0;
12#[inline]
13#[must_use]
14pub fn is_flexible(version: i16) -> bool {
15 version >= FLEXIBLE_MIN
16}
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct NoOpRecord {
19 pub unknown_tagged_fields: UnknownTaggedFields,
20}
21impl Encode for NoOpRecord {
22 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
23 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
24 return Err(ProtocolError::SchemaMismatch(
25 "NoOpRecord version out of range",
26 ));
27 }
28 let flex = is_flexible(version);
29 if flex {
30 let tagged = WriteTaggedFields::new();
31 tagged.write(buf, &self.unknown_tagged_fields);
32 }
33 Ok(())
34 }
35 fn encoded_len(&self, version: i16) -> usize {
36 let flex = is_flexible(version);
37 let mut n: usize = 0;
38 if flex {
39 let known_pairs: Vec<(u32, usize)> = Vec::new();
40 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
41 }
42 n
43 }
44}
45impl Decode<'_> for NoOpRecord {
46 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
47 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
48 return Err(ProtocolError::SchemaMismatch(
49 "NoOpRecord version out of range",
50 ));
51 }
52 let flex = is_flexible(version);
53 let mut out = Self::default();
54 if flex {
55 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
56 }
57 Ok(out)
58 }
59}
60#[cfg(test)]
61impl NoOpRecord {
62 #[must_use]
63 pub fn populated(_version: i16) -> Self {
64 Self::default()
65 }
66}
67#[must_use]
70#[allow(unused_comparisons)]
71pub fn default_json(_version: i16) -> ::serde_json::Value {
72 let obj = ::serde_json::Map::new();
73 ::serde_json::Value::Object(obj)
74}