pub struct NntpResponse {
pub status_code: u16,
pub is_multiline: bool,
pub data: Vec<u8>,
}Expand description
Represents a parsed NNTP response
Fields§
§status_code: u16Status code (e.g., 200, 381, 500)
is_multiline: boolWhether this is a multiline response
data: Vec<u8>Complete response data including status line
Implementations§
Source§impl NntpResponse
impl NntpResponse
Sourcepub fn parse_status_code(data: &[u8]) -> Option<u16>
pub fn parse_status_code(data: &[u8]) -> Option<u16>
Parse a status code from response data
Per RFC 3977 §3.2, responses begin with a 3-digit status code (ASCII digits ‘0’-‘9’).
Optimization: Direct byte-to-digit conversion without UTF-8 validation. Status codes are guaranteed to be ASCII digits per the RFC.
Sourcepub fn is_multiline_response(status_code: u16) -> bool
pub fn is_multiline_response(status_code: u16) -> bool
Check if a response indicates a multiline response
Per RFC 3977 §3.4.1, certain status codes indicate multiline data follows.
§Multiline Response Codes
- 1xx: All informational responses (100-199)
- 2xx: Specific codes - 215, 220, 221, 222, 224, 225, 230, 231, 282
Sourcepub fn has_terminator_at_end(data: &[u8]) -> bool
pub fn has_terminator_at_end(data: &[u8]) -> bool
Check if data ends with the NNTP multiline terminator
Per RFC 3977 §3.4.1:
Multiline blocks are terminated by a line containing only a period:
CRLF "." CRLF
Which appears in the data stream as: \r\n.\r\nOptimization: Single suffix check, no scanning.
Sourcepub fn find_terminator_end(data: &[u8]) -> Option<usize>
pub fn find_terminator_end(data: &[u8]) -> Option<usize>
Find the position of the NNTP multiline terminator in data
Returns the position AFTER the terminator (exclusive end), or None if not found. This handles the case where extra data appears after the terminator in the same chunk.
Per RFC 3977 §3.4.1, the terminator is exactly “\r\n.\r\n” (CRLF, dot, CRLF).
Optimization: Uses memchr::memchr_iter() to find ‘\r’ bytes (SIMD-accelerated),
then validates the full 5-byte pattern. This eliminates the need to create new slices
on each iteration (which the manual loop approach requires with &data[pos..]).
Benchmarks show this is 72% faster for small responses (37ns → 13ns) and 64% faster for medium responses (109ns → 40ns) compared to the manual loop that creates a new slice on each iteration.
Sourcepub fn has_spanning_terminator(
tail: &[u8],
tail_len: usize,
current: &[u8],
current_len: usize,
) -> bool
pub fn has_spanning_terminator( tail: &[u8], tail_len: usize, current: &[u8], current_len: usize, ) -> bool
Check if a terminator spans across a boundary between tail and current chunk
This handles the case where a multiline terminator is split across two read chunks. For example: previous chunk ends with “\r\n.” and current starts with “\r\n”
Per RFC 3977 §3.4.1, the terminator is exactly “\r\n.\r\n” (CRLF, dot, CRLF).
Sourcepub fn is_disconnect(data: &[u8]) -> bool
pub fn is_disconnect(data: &[u8]) -> bool
Check if response is a disconnect/goodbye (205)
Per RFC 3977 §5.4, code 205 indicates “Connection closing” / “Goodbye”.
Optimization: Direct byte prefix check, no parsing.
Sourcepub fn extract_message_id(command: &str) -> Option<MessageId<'_>>
pub fn extract_message_id(command: &str) -> Option<MessageId<'_>>
Extract message-ID from command arguments using fast byte searching
Per RFC 5536 §3.1.3,
message-IDs have the format <local-part@domain>.
Examples:
<article123@news.example.com><20231014.123456@server.domain>
Optimization: Uses memchr for fast ‘<’ and ‘>’ detection.
Sourcepub fn validate_message_id(msgid: &str) -> bool
pub fn validate_message_id(msgid: &str) -> bool
Validate message-ID format according to RFC 5536 §3.1.3
A valid message-ID must:
- Start with ‘<’ and end with ‘>’
- Contain exactly one ‘@’ character
- Have content before and after the ‘@’ (local-part and domain)
Per RFC 5536 §3.1.3:
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]Note: This is a basic validation - full RFC 5536 validation is more complex.
Sourcepub fn has_multiline_terminator(data: &[u8]) -> bool
pub fn has_multiline_terminator(data: &[u8]) -> bool
Check if data contains the end-of-multiline marker (legacy method)
Trait Implementations§
Source§impl Clone for NntpResponse
impl Clone for NntpResponse
Source§fn clone(&self) -> NntpResponse
fn clone(&self) -> NntpResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more