willow_data_model/
lengthy_entry.rs

1use crate::{AuthorisedEntry, Entry};
2
3/// An [`Entry`] together with information about how much of its payload a given [`crate::Store`] holds.
4///
5/// [Definition](https://willowprotocol.org/specs/3d-range-based-set-reconciliation/index.html#LengthyEntry)
6#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct LengthyEntry<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD> {
8    /// The Entry in question.
9    entry: Entry<MCL, MCC, MPL, N, S, PD>,
10    /// The number of consecutive bytes from the start of the entry’s payload that the peer holds.
11    available: u64,
12}
13
14impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD>
15    LengthyEntry<MCL, MCC, MPL, N, S, PD>
16{
17    /// Returns a new lengthy entry from a given [`Entry`] and the number of consecutive bytes from the start of the entry’s payload that are held.
18    pub fn new(entry: Entry<MCL, MCC, MPL, N, S, PD>, available: u64) -> Self {
19        Self { entry, available }
20    }
21
22    /// Returns the entry in question.
23    pub fn entry(&self) -> &Entry<MCL, MCC, MPL, N, S, PD> {
24        &self.entry
25    }
26
27    /// Returns the number of consecutive bytes from the start of the entry’s Payload that the peer holds.
28    pub fn available(&self) -> u64 {
29        self.available
30    }
31
32    /// Turns this into a regular [`Entry`].
33    pub fn into_entry(self) -> Entry<MCL, MCC, MPL, N, S, PD> {
34        self.entry
35    }
36}
37
38impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD>
39    AsRef<Entry<MCL, MCC, MPL, N, S, PD>> for LengthyEntry<MCL, MCC, MPL, N, S, PD>
40{
41    fn as_ref(&self) -> &Entry<MCL, MCC, MPL, N, S, PD> {
42        &self.entry
43    }
44}
45
46/// An [`AuthorisedEntry`] together with information about how much of its payload a given [`crate::Store`] holds.
47#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
48pub struct LengthyAuthorisedEntry<
49    const MCL: usize,
50    const MCC: usize,
51    const MPL: usize,
52    N,
53    S,
54    PD,
55    AT,
56> {
57    /// The Entry in question.
58    entry: AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>,
59    /// The number of consecutive bytes from the start of the entry’s payload that the peer holds.
60    available: u64,
61}
62
63impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD, AT>
64    LengthyAuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>
65{
66    /// Returns a new lengthy entry from a given [`AuthorisedEntry`] and the number of consecutive bytes from the start of the entry’s payload that are held.
67    pub fn new(entry: AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>, available: u64) -> Self {
68        Self { entry, available }
69    }
70
71    /// Returns the authorised entry in question.
72    pub fn entry(&self) -> &AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT> {
73        &self.entry
74    }
75
76    /// Returns the number of consecutive bytes from the start of the entry’s Payload that the peer holds.
77    pub fn available(&self) -> u64 {
78        self.available
79    }
80
81    /// Turns this into a [`AuthorisedEntry`].
82    pub fn into_authorised_entry(self) -> AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT> {
83        self.entry
84    }
85}
86
87impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD, AT>
88    AsRef<AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>>
89    for LengthyAuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>
90{
91    fn as_ref(&self) -> &AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT> {
92        &self.entry
93    }
94}