pub struct OvpnCodec { /* private fields */ }Expand description
Tokio codec for the OpenVPN management interface.
The encoder serializes typed OvpnCommand values into correct wire-format
bytes, including proper escaping and multi-line block framing. The decoder
uses command-tracking state to correctly distinguish single-line from
multi-line responses, and accumulates multi-line >CLIENT: notifications
into a single OvpnMessage before emitting them.
§Sequential usage
The OpenVPN management protocol is strictly sequential: each command
produces exactly one response, and the server processes commands one
at a time. This codec tracks which response type to expect from the
last encoded command. You must fully drain [decode()] (until it
returns Ok(None) or the expected response is received) before
calling [encode()] again. Encoding a new command while a
multi-line response or CLIENT notification is still being accumulated
will overwrite the tracking state and corrupt decoding.
In debug builds, encode() asserts that no accumulation is in
progress.
Implementations§
Source§impl OvpnCodec
impl OvpnCodec
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new codec with default state, ready to encode commands and decode responses.
Sourcepub fn with_max_multi_line_lines(self, limit: AccumulationLimit) -> Self
pub fn with_max_multi_line_lines(self, limit: AccumulationLimit) -> Self
Set the maximum number of lines accumulated in a multi-line response before the decoder returns an error.
Sourcepub fn with_max_client_env_entries(self, limit: AccumulationLimit) -> Self
pub fn with_max_client_env_entries(self, limit: AccumulationLimit) -> Self
Set the maximum number of ENV entries accumulated for
>CLIENT: notifications before the decoder returns an error.
Sourcepub fn with_encoder_mode(self, mode: EncoderMode) -> Self
pub fn with_encoder_mode(self, mode: EncoderMode) -> Self
Set the encoder mode for handling unsafe characters in user-supplied strings.
The default is EncoderMode::Sanitize, which silently strips
\n, \r, and \0. Use EncoderMode::Strict to reject inputs
containing those characters with an error instead.