use thiserror::Error;
use crate::kairos::DecodeError as KairosDecodeError;
use crate::metis::HaveSetDecodeError;
#[non_exhaustive]
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum SnapshotDecodeError {
#[error("unknown rhapsody snapshot version: {0:#04x}")]
UnknownVersion(u8),
#[error("unexpected snapshot frame length: expected at least {expected}, found {found}")]
UnexpectedLength {
expected: usize,
found: usize,
},
#[error("snapshot frame carries {count} loci, past the plane's {capacity} ceiling")]
TooManyLoci {
count: u64,
capacity: u64,
},
#[error("non-canonical snapshot: zero index for station {station}")]
ZeroDot {
station: u32,
},
#[error(
"non-canonical snapshot: run of fewer than two elements at station {station}, base {base}"
)]
RunTooShort {
station: u32,
base: u64,
},
#[error("snapshot run overflow: station {station}, base {base}, len {len}")]
RunOverflow {
station: u32,
base: u64,
len: u64,
},
#[error("unknown snapshot anchor tag: {tag:#04x}")]
BadAnchorTag {
tag: u8,
},
#[error("non-canonical snapshot: padded origin anchor at station {station}, index {index}")]
NonCanonicalOriginAnchor {
station: u32,
index: u64,
},
#[error("snapshot rank step overflow at station {station}, index {index}")]
RankOverflow {
station: u32,
index: u64,
},
#[error("non-canonical snapshot rank step at station {station}, index {index}")]
NonCanonicalRankStep {
station: u32,
index: u64,
},
#[error(
"non-canonical snapshot: locus ({found_station}, {found_index}) does not ascend past ({previous_station}, {previous_index})"
)]
NonAscendingLoci {
previous_station: u32,
previous_index: u64,
found_station: u32,
found_index: u64,
},
#[error("non-canonical snapshot: split chain at station {station}, index {index}")]
SplitChain {
station: u32,
index: u64,
},
#[error("snapshot rank frame: {0}")]
Rank(#[source] KairosDecodeError),
#[error("snapshot visible suffix: {0}")]
Visible(#[source] HaveSetDecodeError),
#[error("snapshot visible dot without locus: station {station}, index {index}")]
VisibleWithoutLocus {
station: u32,
index: u64,
},
}