Skip to main content

ocular_protocol/
handler.rs

1use crate::ProxyEvent;
2
3/// Trait that each protocol implements for parsing and display.
4pub trait ProtocolHandler: Send + Sync {
5    /// Parse request bytes → summary for event list
6    fn parse_request(&self, buf: &[u8]) -> Option<String>;
7
8    /// Extract full command from request (for Detail panel, copy, edit)
9    fn extract_full_command(&self, buf: &[u8]) -> Option<String> {
10        self.parse_request(buf)
11    }
12
13    /// Parse response bytes → short summary
14    fn parse_response(&self, buf: &[u8]) -> Option<String>;
15
16    /// Format response detail (for Detail panel)
17    fn format_response_detail(&self, buf: &[u8]) -> Option<String> {
18        self.parse_response(buf)
19    }
20
21    /// Generate a replayable command string (for yank/copy)
22    fn to_replay_command(&self, ev: &ProxyEvent) -> String {
23        ev.full_command.clone()
24    }
25
26    /// Does this protocol need request buffering across reads?
27    fn needs_request_buffering(&self) -> bool { false }
28
29    /// Does this protocol need response buffering across reads?
30    fn needs_response_buffering(&self) -> bool { false }
31
32    /// Is the request buffer complete?
33    fn request_complete(&self, _buf: &[u8]) -> bool { true }
34
35    /// Is the response buffer complete?
36    fn response_complete(&self, _buf: &[u8]) -> bool { true }
37
38    /// Is this a frame-based protocol with custom proxy logic? (AMQP)
39    fn is_frame_based(&self) -> bool { false }
40}