Expand description
Engine-agnostic CSA server protocol surface.
This crate turns one line of the CSA server protocol into a typed
CsaCommand and back. It has no dependencies, no I/O, and no board
representation: sockets, clocks, and legality belong to the layer above.
use rsshogi_csa::{format_command, parse_line, CsaCommand, EndMarker};
let command = parse_line("+7776FU,T12")?;
assert_eq!(format_command(&command), "+7776FU,T12");
let CsaCommand::Move(line) = command else { unreachable!() };
assert_eq!(line.csa.as_str(), "+7776FU");
assert_eq!(line.elapsed, Some(12));
assert_eq!(parse_line("#RESIGN")?, CsaCommand::End(EndMarker::Resign));The BEGIN Game_Summary proposal spans many lines and is assembled by
GameSummaryReader instead, which keeps the BEGIN Position body verbatim.
§Scope
CSA has two things that share a name. The record format — .csa files with
a V2.2 header and $EVENT metadata — is handled by the records feature of
the rsshogi crate. The server protocol
— LOGIN, BEGIN Game_Summary, +7776FU,T12, #WIN — is what this crate
handles.
Structs§
- CsaMove
- A syntactically valid CSA move such as
+7776FU. - Game
Summary - A parsed
BEGIN Game_Summaryblock. - Game
Summary Reader - Assembles a
GameSummaryfrom the lines of oneBEGIN Game_Summaryblock. - Info
Line - A
##[TAG] ...informational line from the server. - Move
Line - A move line, optionally annotated with consumed time and a comment.
- Parse
Error - A CSA protocol line could not be parsed.
- Parse
Error Site - Where in the offending line the problem was detected.
- Time
Config - The time control of one side, as declared in a
BEGIN Timeblock. - Time
Unit - A
Time_Unitvalue such as1secor1min.
Enums§
- Color
- Which side of the board a CSA
+/-marker refers to. - CsaCommand
- One line of the CSA server protocol.
- CsaCommand
Direction - Which way a command travels.
- EndMarker
- A
#-prefixed terminal marker. - EndMarker
Kind - How a
#-prefixed end marker classifies. - Meta
Command - A
%%-prefixed administrative command. - Parse
Error Kind - What kind of problem
crate::parse_lineran into. - Special
Move - A
%-prefixed special move. - Time
Scale - The scale part of a
Time_Unitvalue. - Turn
Preference - The turn a client asks for in
%%GAME/%%CHALLENGE.
Functions§
- format_
command - Formats one command as its canonical protocol line, without a trailing newline.
- parse_
line - Parses one protocol line.
- parse_
line_ strict - Parses one protocol line and requires it to already be canonical.