gmsol_decode/decode/
visitor.rs

1use anchor_lang::solana_program::pubkey::Pubkey;
2
3use crate::{
4    decoder::{account_access::AccountAccess, cpi_event_access::AnchorCPIEventsAccess},
5    error::DecodeError,
6};
7
8/// Type that walks through a [`Decoder`](crate::Decoder).
9pub trait Visitor: Sized {
10    /// Value Type.
11    type Value;
12
13    /// Visit an account.
14    fn visit_account(self, account: impl AccountAccess) -> Result<Self::Value, DecodeError> {
15        _ = account;
16        Err(DecodeError::InvalidType(
17            "Unexpected type `Account`".to_string(),
18        ))
19    }
20
21    /// Visit Anchor CPI events.
22    fn visit_anchor_cpi_events<'a>(
23        self,
24        events: impl AnchorCPIEventsAccess<'a>,
25    ) -> Result<Self::Value, DecodeError> {
26        _ = events;
27        Err(DecodeError::InvalidType(
28            "Unexpected type `AnchorCPIEvents`".to_string(),
29        ))
30    }
31
32    /// Visit data owned by a program.
33    ///
34    /// It can be the data of an `Event`, an `Account` or an `Instruction`.
35    fn visit_owned_data(
36        self,
37        program_id: &Pubkey,
38        data: &[u8],
39    ) -> Result<Self::Value, DecodeError> {
40        _ = program_id;
41        _ = data;
42        Err(DecodeError::InvalidType(
43            "Unexpected type `OwnedData`".to_string(),
44        ))
45    }
46
47    /// Visit bytes.
48    fn visit_bytes(self, data: &[u8]) -> Result<Self::Value, DecodeError> {
49        _ = data;
50        Err(DecodeError::InvalidType(
51            "Unexpected type `Bytes`".to_string(),
52        ))
53    }
54}