bc_ur/
multipart_encoder.rs

1use ur::Encoder;
2use anyhow::Result;
3
4use crate::UR;
5
6pub struct MultipartEncoder<'a> {
7    encoder: Encoder<'a>,
8}
9
10impl<'a> MultipartEncoder<'a> {
11    pub fn new(ur: &'a UR, max_fragment_len: usize) -> Result<Self> {
12        Ok(Self {
13            encoder: Encoder::new(&ur.cbor().to_cbor_data(), max_fragment_len, ur.ur_type_str())
14                .map_err(|e| anyhow::Error::msg(e.to_string()))?,
15        })
16    }
17
18    pub fn next_part(&mut self) -> Result<String> {
19        self.encoder.next_part()
20            .map_err(|e| anyhow::Error::msg(e.to_string()))
21    }
22
23    pub fn current_index(&self) -> usize {
24        self.encoder.current_index()
25    }
26
27    pub fn parts_count(&self) -> usize {
28        self.encoder.fragment_count()
29    }
30}