Skip to main content

chess/formats/
chessbase.rs

1//! ChessBase database formats.
2
3// Format references:
4// - https://talkchess.com/viewtopic.php?t=29468
5// - https://github.com/foolnotion/scidb/tree/master/src/db/cbh
6
7use core::ffi::c_str::CStr;
8
9use encoding_rs::WINDOWS_1252;
10
11pub mod archive;
12pub mod database;
13pub mod game;
14pub mod huffman;
15pub mod index;
16pub mod player;
17pub mod table;
18pub mod tournament;
19
20fn cstr(input: &[u8]) -> String {
21    let value = CStr::from_bytes_until_nul(input).expect("valid string");
22    let (value, encoding, had_errors) = WINDOWS_1252.decode(value.to_bytes());
23    assert_eq!(encoding, WINDOWS_1252);
24    assert!(!had_errors);
25    value.to_string()
26}
27
28// Numbers where zero means missing or unknown.
29fn optional<T: Default + PartialEq>(value: T) -> Option<T> {
30    (value != T::default()).then_some(value)
31}