rseip/client/ab_eip/
interceptor.rs1use super::HasMore;
2use rseip_cip::{
3 codec::decode::message_reply::decode_service_and_status, error::cip_error_status, MessageReply,
4 MessageReplyInterface, Status,
5};
6use rseip_core::codec::{Decode, Decoder};
7
8#[derive(Debug)]
9pub(crate) struct HasMoreInterceptor<T>(pub MessageReply<T>);
10
11impl<T> MessageReplyInterface for HasMoreInterceptor<T> {
12 type Value = T;
13
14 fn reply_service(&self) -> u8 {
15 self.0.reply_service
16 }
17
18 fn status(&self) -> &Status {
19 &self.0.status
20 }
21
22 fn value(&self) -> &Self::Value {
23 &self.0.data
24 }
25
26 fn into_value(self) -> Self::Value {
27 self.0.data
28 }
29}
30
31impl<'de, T> Decode<'de> for HasMoreInterceptor<T>
32where
33 T: Decode<'de>,
34{
35 #[inline]
36 fn decode<D>(mut decoder: D) -> Result<Self, D::Error>
37 where
38 D: Decoder<'de>,
39 {
40 let (reply_service, status) = decode_service_and_status(&mut decoder)?;
41 if status.is_err() && !status.has_more() {
42 return Err(cip_error_status(status));
43 }
44 let data = decoder.decode_any()?;
45 Ok(Self(MessageReply::new(reply_service, status, data)))
46 }
47}