gmsol_decode/decoder/
mod.rs

1use crate::{decode::visitor::Visitor, error::DecodeError};
2
3/// Account Access.
4pub mod account_access;
5
6/// CPI Event Access.
7pub mod cpi_event_access;
8
9/// Decoder implementations.
10pub mod decoder_impl;
11
12pub use decoder_impl::*;
13
14/// Decoder for received program data.
15pub trait Decoder {
16    /// Hint that the visitor is expecting an `AccountInfo`.
17    fn decode_account<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
18    where
19        V: Visitor;
20
21    /// Hint that the visitor is expecting a `Transaction`.
22    fn decode_transaction<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
23    where
24        V: Visitor;
25
26    /// Hint that the visitor is expecting `AnchorCPIEvent` list.
27    fn decode_anchor_cpi_events<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
28    where
29        V: Visitor;
30
31    /// Hint that the visitor is expecting a `OwnedData`.
32    ///
33    /// It can be the data of an `Event` of an `Instruction`.
34    fn decode_owned_data<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
35    where
36        V: Visitor;
37
38    /// Hint that the visitor is expecting a `Data`.
39    ///
40    /// It can be the data of an `Event` of an `Instruction`.
41    fn decode_bytes<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
42    where
43        V: Visitor;
44}
45
46impl<D: Decoder> Decoder for &D {
47    fn decode_account<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
48    where
49        V: Visitor,
50    {
51        (**self).decode_account(visitor)
52    }
53
54    fn decode_transaction<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
55    where
56        V: Visitor,
57    {
58        (**self).decode_transaction(visitor)
59    }
60
61    fn decode_anchor_cpi_events<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
62    where
63        V: Visitor,
64    {
65        (**self).decode_anchor_cpi_events(visitor)
66    }
67
68    fn decode_owned_data<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
69    where
70        V: Visitor,
71    {
72        (**self).decode_owned_data(visitor)
73    }
74
75    fn decode_bytes<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
76    where
77        V: Visitor,
78    {
79        (**self).decode_bytes(visitor)
80    }
81}