PaiGack/ftp/debug does not have a README file

    DebugDirection

    pub(all) enum DebugDirection {
    Command
    Reply
    }

    One direction of the traffic log.

    DebugLog

    pub(all) struct DebugLog {
    sink : &
    Writer

    prefix : Bool
    redact_pass : Bool
    }

    The traffic log: a direction tagged, CRLF terminated line sink.

    This is the MoonBit equivalent of upstream debug.go's TeeReader / MultiWriter pair, assembled into one object because a single transcript is the point -- two untagged writers produce exactly the log you cannot debug with. Upstream derives the direction implicitly, by teeing the socket's read side and fanning out its write side; here the direction is an explicit tag, so the record stays self describing even if a caller routes the two directions into different sinks.

    The two directions get one record path each, write_path and read_path; Control routes both of its directions through them, so the transcript and the protocol see the same bytes. They are functions rather than the MultiWriter / TeeReader decorators upstream uses because a decorator needs impl @io.Writer for <new type>, and MoonBit lets only the defining package write that -- a decorator living here could never wrap the socket Control holds.

    DebugLog::new

    fn DebugLog::new(sink : &
    Writer
    , prefix? : Bool, redact_pass? : Bool) -> DebugLog

    Build a traffic log over sink, tagging each line with its direction.

    DebugLog::read_path

    async fn DebugLog::read_path(self : DebugLog, inner : &
    Reader
    , delimiter : StringView) -> String?

    Read one line through the log: inner.read_until frames it, the bytes that were actually produced are recorded before the framed line is returned.

    This used to be the TeeLogReader decorator, moved to a function for the same ownership reason as write_path. It records what it read including false reads -- a zero length read is not an error, there was simply no line.

    DebugLog::record

    async fn DebugLog::record(self : DebugLog, bytes : BytesView) -> Unit

    Record one already CRLF terminated record, byte for byte.

    This is the entry point the control channel uses: it hands over exactly the bytes it is about to write (or has just read), so the transcript cannot disagree with the wire even when the payload is not valid UTF-8. A sink that raises loses the record, never the caller -- see write_path and read_path below.

    DebugLog::render

    fn DebugLog::render(self : DebugLog, direction : DebugDirection, line : String) -> String

    Render one log record as it goes onto the wire.

    DebugLog::write_line

    async fn DebugLog::write_line(self : DebugLog, direction : DebugDirection, line : String) -> Unit

    Append one captured line, tagged with its direction.

    Writer::write already loops over short writes and a BytesView is one of its @io.Data payloads, so the record goes out whole or the sink raises.

    DebugLog::write_path

    async fn DebugLog::write_path(self : DebugLog, inner : &
    Writer
    , bytes : BytesView) -> Unit

    One write through the log: the bytes go to inner first, then the bytes that inner actually accepted are recorded.

    The order is the point. A write that raises still records what was attempted (the command never reached the wire, and that is the single most useful line in a desynchronised session), but a short write records only what the socket took -- logging the offered buffer would put bytes in the transcript that never left the client.

    This used to be the MirrorWriter decorator. It is a function now because the type lived in this package while Control did not, and MoonBit does not let another package impl @io.Writer for a type it does not own.

    Source Files