Skip to main content

Crate rsshogi_csa

Crate rsshogi_csa 

Source
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.
GameSummary
A parsed BEGIN Game_Summary block.
GameSummaryReader
Assembles a GameSummary from the lines of one BEGIN Game_Summary block.
InfoLine
A ##[TAG] ... informational line from the server.
MoveLine
A move line, optionally annotated with consumed time and a comment.
ParseError
A CSA protocol line could not be parsed.
ParseErrorSite
Where in the offending line the problem was detected.
TimeConfig
The time control of one side, as declared in a BEGIN Time block.
TimeUnit
A Time_Unit value such as 1sec or 1min.

Enums§

Color
Which side of the board a CSA + / - marker refers to.
CsaCommand
One line of the CSA server protocol.
CsaCommandDirection
Which way a command travels.
EndMarker
A #-prefixed terminal marker.
EndMarkerKind
How a #-prefixed end marker classifies.
MetaCommand
A %%-prefixed administrative command.
ParseErrorKind
What kind of problem crate::parse_line ran into.
SpecialMove
A %-prefixed special move.
TimeScale
The scale part of a Time_Unit value.
TurnPreference
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.