Skip to main content

ydb/grpc_wrapper/raw_topic_service/common/
codecs.rs

1use itertools::Itertools;
2use ydb_grpc::ydb_proto::topic::{Codec, SupportedCodecs};
3
4#[derive(serde::Serialize, Clone, Debug)]
5pub(crate) struct RawCodec {
6    pub code: i32,
7}
8
9impl RawCodec {
10    fn is_raw(&self) -> bool {
11        self.code == i32::from(Codec::Raw)
12    }
13}
14
15#[derive(serde::Serialize, Clone, Default, Debug)]
16pub(crate) struct RawSupportedCodecs {
17    pub codecs: Vec<RawCodec>,
18}
19
20impl From<RawSupportedCodecs> for SupportedCodecs {
21    fn from(value: RawSupportedCodecs) -> Self {
22        Self {
23            codecs: value.codecs.into_iter().map(|x| x.code).collect_vec(),
24        }
25    }
26}
27
28impl From<SupportedCodecs> for RawSupportedCodecs {
29    fn from(value: SupportedCodecs) -> Self {
30        Self {
31            codecs: value
32                .codecs
33                .into_iter()
34                .map(|x| RawCodec { code: x })
35                .collect_vec(),
36        }
37    }
38}