|
| 1 | +use crate::coding::{Decode, DecodeError, Encode, EncodeError, Params, Tuple}; |
| 2 | +use crate::message::GroupOrder; |
| 3 | + |
| 4 | +/// Sent by the subscriber to request to request a range |
| 5 | +/// of already published objects within a track. |
| 6 | +#[derive(Clone, Debug)] |
| 7 | +pub struct Fetch { |
| 8 | + /// The subscription ID |
| 9 | + pub id: u64, |
| 10 | + |
| 11 | + /// Track properties |
| 12 | + pub track_namespace: Tuple, |
| 13 | + pub track_name: String, |
| 14 | + |
| 15 | + /// Subscriber Priority |
| 16 | + pub subscriber_priority: u8, |
| 17 | + |
| 18 | + pub group_order: GroupOrder, |
| 19 | + |
| 20 | + /// The start/end group/object. |
| 21 | + pub start_group: u64, |
| 22 | + pub start_object: u64, |
| 23 | + pub end_group: u64, |
| 24 | + pub end_object: u64, |
| 25 | + |
| 26 | + /// Optional parameters |
| 27 | + pub params: Params, |
| 28 | +} |
| 29 | + |
| 30 | +impl Decode for Fetch { |
| 31 | + fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> { |
| 32 | + let id = u64::decode(r)?; |
| 33 | + |
| 34 | + let track_namespace = Tuple::decode(r)?; |
| 35 | + let track_name = String::decode(r)?; |
| 36 | + |
| 37 | + let subscriber_priority = u8::decode(r)?; |
| 38 | + |
| 39 | + let group_order = GroupOrder::decode(r)?; |
| 40 | + |
| 41 | + let start_group = u64::decode(r)?; |
| 42 | + let start_object = u64::decode(r)?; |
| 43 | + let end_group = u64::decode(r)?; |
| 44 | + let end_object = u64::decode(r)?; |
| 45 | + |
| 46 | + let params = Params::decode(r)?; |
| 47 | + |
| 48 | + Ok(Self { |
| 49 | + id, |
| 50 | + track_namespace, |
| 51 | + track_name, |
| 52 | + subscriber_priority, |
| 53 | + group_order, |
| 54 | + start_group, |
| 55 | + start_object, |
| 56 | + end_group, |
| 57 | + end_object, |
| 58 | + params, |
| 59 | + }) |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +impl Encode for Fetch { |
| 64 | + fn encode<W: bytes::BufMut>(&self, w: &mut W) -> Result<(), EncodeError> { |
| 65 | + self.id.encode(w)?; |
| 66 | + |
| 67 | + self.track_namespace.encode(w)?; |
| 68 | + self.track_name.encode(w)?; |
| 69 | + |
| 70 | + self.subscriber_priority.encode(w)?; |
| 71 | + |
| 72 | + self.group_order.encode(w)?; |
| 73 | + |
| 74 | + self.start_group.encode(w)?; |
| 75 | + self.start_object.encode(w)?; |
| 76 | + self.end_group.encode(w)?; |
| 77 | + self.end_object.encode(w)?; |
| 78 | + |
| 79 | + self.params.encode(w)?; |
| 80 | + |
| 81 | + Ok(()) |
| 82 | + } |
| 83 | +} |
0 commit comments