Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/common/owned/
Status.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i8, put_i8};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13#[derive(Debug, Clone, PartialEq, Eq, Default)]
14pub struct Status {
15    pub status_code: i8,
16    pub status_detail: String,
17    pub unknown_tagged_fields: UnknownTaggedFields,
18}
19
20impl Encode for Status {
21    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
22        let flex = version >= 0;
23        if version >= 0 { put_i8(buf, self.status_code) }
24        if version >= 0 { if flex { put_compact_string(buf, &self.status_detail) } else { put_string(buf, &self.status_detail) } }
25        if flex {
26            let tagged = WriteTaggedFields::new();
27            tagged.write(buf, &self.unknown_tagged_fields);
28        }
29        Ok(())
30    }
31    fn encoded_len(&self, version: i16) -> usize {
32        let flex = version >= 0;
33        let mut n: usize = 0;
34        if version >= 0 { n += 1; }
35        if version >= 0 { n += if flex { compact_string_len(&self.status_detail) } else { string_len(&self.status_detail) }; }
36        if flex {
37            let known_pairs: Vec<(u32, usize)> = Vec::new();
38            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
39        }
40        n
41    }
42}
43
44impl<'de> Decode<'de> for Status {
45    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
46        let flex = version >= 0;
47        let mut out = Self::default();
48        if version >= 0 { out.status_code = get_i8(buf)?; }
49        if version >= 0 { out.status_detail = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
50        if flex {
51            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
52                Ok(false)
53            })?;
54        }
55        Ok(out)
56    }
57}