From 6532e4f4a94ada35c958cf53e1f98aaf175188c6 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 5 Oct 2024 10:00:45 +0200 Subject: Split log_reader into reverse_log_reader and forward_log_reader --- src/common.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/common.rs') diff --git a/src/common.rs b/src/common.rs index 9ea43aa..ea179ab 100644 --- a/src/common.rs +++ b/src/common.rs @@ -39,6 +39,22 @@ pub const SEQ_LIT_FIELD_SEP: &[u8] = &[ ESCAPE_CHARACTER, ]; +/// There are three special sequences that need to be handled: +/// Here: SC = escape char, FS = field separator. +/// - SC FS FS SC -> actual record separator +/// - SC SC FS SC -> literal FS +/// - SC SC SC SC -> literal SC +/// +/// Returns SpecialSequence or None if not valid. +pub fn validate_special(buf: &[u8]) -> Option { + match buf { + SEQ_RECORD_SEP => Some(SpecialSequence::RecordSeparator), + SEQ_LIT_FIELD_SEP => Some(SpecialSequence::LiteralFieldSeparator), + SEQ_LIT_ESCAPE => Some(SpecialSequence::LiteralEscape), + _ => None, + } +} + #[derive(Debug, Eq, PartialEq)] pub enum SpecialSequence { RecordSeparator, -- cgit v1.3