1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
//! Artifact format and capability profile types.
use core::fmt;
use pleiades_types::CelestialBody;
use crate::channels::ChannelKind;
use crate::codec::{
validate_artifact_profile, validate_canonical_body_order, validate_unique_values,
};
use crate::error::{CompressionError, CompressionErrorKind};
/// Describes the byte-order policy encoded by a compressed artifact.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum EndianPolicy {
/// The artifact stores its numeric fields in little-endian byte order.
LittleEndian,
}
impl EndianPolicy {
/// Returns the compact label used in release-facing summaries.
pub const fn label(self) -> &'static str {
match self {
Self::LittleEndian => "little-endian",
}
}
}
impl fmt::Display for EndianPolicy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label())
}
}
/// Artifact-level output semantics for fields that are not raw segment channels.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum ArtifactOutput {
/// Ecliptic coordinates assembled from longitude, latitude, and distance channels.
EclipticCoordinates,
/// Equatorial coordinates reconstructed from ecliptic coordinates and obliquity policy.
EquatorialCoordinates,
/// Apparent longitude/latitude corrections such as light-time, aberration, or nutation.
ApparentCorrections,
/// Topocentric coordinates reconstructed for a terrestrial observer.
TopocentricCoordinates,
/// Sidereal coordinates derived from tropical coordinates and ayanamsa policy.
SiderealCoordinates,
/// Longitude/latitude/radial speed values.
Motion,
}
impl ArtifactOutput {
/// Returns all built-in artifact outputs in a stable declaration order.
pub const fn all() -> [Self; 6] {
[
Self::EclipticCoordinates,
Self::EquatorialCoordinates,
Self::ApparentCorrections,
Self::TopocentricCoordinates,
Self::SiderealCoordinates,
Self::Motion,
]
}
pub(crate) const fn ordinal(self) -> u8 {
match self {
Self::EclipticCoordinates => 0,
Self::EquatorialCoordinates => 1,
Self::ApparentCorrections => 2,
Self::TopocentricCoordinates => 3,
Self::SiderealCoordinates => 4,
Self::Motion => 5,
}
}
/// Returns the compact label used in release-facing summaries.
pub const fn label(self) -> &'static str {
match self {
Self::EclipticCoordinates => "EclipticCoordinates",
Self::EquatorialCoordinates => "EquatorialCoordinates",
Self::ApparentCorrections => "ApparentCorrections",
Self::TopocentricCoordinates => "TopocentricCoordinates",
Self::SiderealCoordinates => "SiderealCoordinates",
Self::Motion => "Motion",
}
}
}
impl fmt::Display for ArtifactOutput {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label())
}
}
/// Describes how a high-level artifact output is represented by the profile.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum ArtifactOutputSupport {
/// The output is stored directly in the artifact payload.
Stored,
/// The output is reconstructed deterministically from stored data.
Derived,
/// The output is approximated numerically from neighboring decoded data.
Approximated,
/// The output is explicitly unsupported by the profile.
Unsupported,
/// The output is neither stored nor explicitly declared by the profile.
Unlisted,
}
impl ArtifactOutputSupport {
/// Returns the compact label used in release-facing summaries.
pub const fn label(self) -> &'static str {
match self {
Self::Stored => "stored",
Self::Derived => "derived",
Self::Approximated => "approximated",
Self::Unsupported => "unsupported",
Self::Unlisted => "unlisted",
}
}
}
impl fmt::Display for ArtifactOutputSupport {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label())
}
}
/// Declares how motion/speed values are represented by an artifact.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum SpeedPolicy {
/// The artifact does not provide speed values.
Unsupported,
/// Speeds are stored as direct channels.
Stored,
/// Speeds are derived analytically from fitted segment derivatives.
FittedDerivative,
/// Speeds are approximated numerically from neighboring decoded samples.
NumericalDifference,
}
impl SpeedPolicy {
/// Returns the compact label used in release-facing summaries.
pub const fn label(self) -> &'static str {
match self {
Self::Unsupported => "Unsupported",
Self::Stored => "Stored",
Self::FittedDerivative => "FittedDerivative",
Self::NumericalDifference => "NumericalDifference",
}
}
/// Returns how motion/speed output is represented when this policy is used.
pub const fn motion_output_support(self) -> ArtifactOutputSupport {
match self {
Self::Unsupported => ArtifactOutputSupport::Unsupported,
Self::Stored => ArtifactOutputSupport::Stored,
Self::FittedDerivative => ArtifactOutputSupport::Derived,
Self::NumericalDifference => ArtifactOutputSupport::Approximated,
}
}
}
impl fmt::Display for SpeedPolicy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label())
}
}
/// Capability/profile metadata for a compressed artifact.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ArtifactProfile {
/// Coordinate channels stored directly in each applicable segment.
pub stored_channels: Vec<ChannelKind>,
/// Higher-level outputs that decoders may derive deterministically from stored data.
pub derived_outputs: Vec<ArtifactOutput>,
/// Outputs explicitly unsupported by this artifact profile.
pub unsupported_outputs: Vec<ArtifactOutput>,
/// Motion/speed representation policy.
pub speed_policy: SpeedPolicy,
}
impl ArtifactProfile {
/// Creates a profile from explicit fields.
pub fn new(
stored_channels: Vec<ChannelKind>,
derived_outputs: Vec<ArtifactOutput>,
unsupported_outputs: Vec<ArtifactOutput>,
speed_policy: SpeedPolicy,
) -> Self {
Self {
stored_channels,
derived_outputs,
unsupported_outputs,
speed_policy,
}
}
/// Validates that the profile does not contain duplicate, conflicting, or
/// non-canonical entries.
///
/// The codec performs the same checks when encoding or decoding artifacts,
/// but exposing the validation step directly lets artifact generators fail
/// before serialization if they assemble an invalid capability profile.
pub fn validate(&self) -> Result<(), CompressionError> {
validate_artifact_profile(self)
}
/// Returns a compact one-line summary of the stored, derived, approximated,
/// unsupported, and speed-policy capabilities encoded by this profile.
pub fn summary(&self) -> String {
self.summary_line()
}
/// Returns how motion output is represented by this profile.
pub fn motion_output_support(&self) -> ArtifactOutputSupport {
self.speed_policy.motion_output_support()
}
/// Returns a compact one-line summary of the stored, derived, approximated,
/// unsupported, and speed-policy capabilities encoded by this profile.
pub fn summary_line(&self) -> String {
format!(
"stored channels: {}; derived outputs: {}; unsupported outputs: {}; speed policy: {}",
format_bracketed_labels(&self.stored_channels),
format_bracketed_labels(&self.derived_outputs),
format_bracketed_labels(&self.unsupported_outputs),
self.speed_policy,
)
}
/// Returns the validated capability summary line.
pub fn validated_summary_line(&self) -> Result<String, CompressionError> {
self.validate()?;
Ok(self.summary_line())
}
/// Returns the validated compact support entries used by the output-support summary.
pub fn validated_output_support_entries_summary_line(
&self,
) -> Result<String, CompressionError> {
self.validate()?;
Ok(self.output_support_entries_summary_line())
}
/// Returns the validated output-support summary line.
pub fn validated_output_support_summary_line(&self) -> Result<String, CompressionError> {
self.validate()?;
Ok(self.output_support_summary_line())
}
/// Returns the capability summary annotated with how many bodies share it.
pub fn summary_for_body_count(&self, body_count: usize) -> String {
format!(
"{}; applies to {} bundled bodies",
self.summary_line(),
body_count
)
}
/// Returns the capability summary annotated with how many bodies share it.
pub fn summary_line_with_body_count(&self, body_count: usize) -> String {
self.summary_for_body_count(body_count)
}
/// Returns the compact support entries used by the output-support summary.
pub fn output_support_entries_summary_line(&self) -> String {
ArtifactOutput::all()
.into_iter()
.map(|output| format!("{output}={}", self.output_support(output)))
.collect::<Vec<_>>()
.join(", ")
}
/// Returns a compact one-line summary of each artifact output's support state.
///
/// The rendered line also makes the explicit `unlisted` bucket visible so
/// release-facing summaries can fail closed if a built-in output stops being
/// classified. It also reports how many outputs are stored, derived,
/// approximated, unsupported, or unlisted so the profile makes the support
/// buckets explicit without requiring the reader to count them manually.
pub fn output_support_summary_line(&self) -> String {
let mut stored_count = 0usize;
let mut derived_count = 0usize;
let mut approximated_count = 0usize;
let mut unsupported_count = 0usize;
let mut unlisted_count = 0usize;
let mut unlisted_outputs = Vec::new();
for output in ArtifactOutput::all() {
match self.output_support(output) {
ArtifactOutputSupport::Stored => stored_count += 1,
ArtifactOutputSupport::Derived => derived_count += 1,
ArtifactOutputSupport::Approximated => approximated_count += 1,
ArtifactOutputSupport::Unsupported => unsupported_count += 1,
ArtifactOutputSupport::Unlisted => {
unlisted_count += 1;
unlisted_outputs.push(output);
}
}
}
format!(
"{}; unlisted outputs: {}; support counts: stored={}, derived={}, approximated={}, unsupported={}, unlisted={}",
self.output_support_entries_summary_line(),
format_bracketed_labels(&unlisted_outputs),
stored_count,
derived_count,
approximated_count,
unsupported_count,
unlisted_count,
)
}
/// Returns how a high-level output is represented by this profile.
pub fn output_support(&self, output: ArtifactOutput) -> ArtifactOutputSupport {
if output == ArtifactOutput::Motion {
self.motion_output_support()
} else if self.derived_outputs.contains(&output) {
ArtifactOutputSupport::Derived
} else if self.unsupported_outputs.contains(&output) {
ArtifactOutputSupport::Unsupported
} else {
ArtifactOutputSupport::Unlisted
}
}
/// Returns whether the profile can provide the requested output.
pub fn supports_output(&self, output: ArtifactOutput) -> bool {
matches!(
self.output_support(output),
ArtifactOutputSupport::Stored
| ArtifactOutputSupport::Derived
| ArtifactOutputSupport::Approximated
)
}
/// Returns whether the profile explicitly marks the output unsupported.
pub fn is_unsupported_output(&self, output: ArtifactOutput) -> bool {
matches!(
self.output_support(output),
ArtifactOutputSupport::Unsupported
)
}
/// Returns the current packaged-artifact profile shorthand: ecliptic longitude,
/// latitude, and distance are stored directly; ecliptic coordinates are
/// reconstructed from those channels; equatorial coordinates are derived from
/// the stored ecliptic coordinates and mean-obliquity policy; and motion/speed
/// is `Motion = Derived` (`SpeedPolicy::FittedDerivative`), not unsupported.
pub fn ecliptic_longitude_latitude_distance() -> Self {
Self::ecliptic_longitude_latitude_distance_with_derived_equatorial()
}
/// Returns the current packaged-artifact profile with stored ecliptic
/// longitude, latitude, and distance channels plus derived equatorial
/// coordinates.
pub fn packaged_ecliptic_longitude_latitude_distance_with_derived_equatorial() -> Self {
Self::new(
vec![
ChannelKind::Longitude,
ChannelKind::Latitude,
ChannelKind::DistanceAu,
],
vec![
ArtifactOutput::EclipticCoordinates,
ArtifactOutput::EquatorialCoordinates,
ArtifactOutput::Motion,
],
vec![
ArtifactOutput::ApparentCorrections,
ArtifactOutput::TopocentricCoordinates,
ArtifactOutput::SiderealCoordinates,
],
SpeedPolicy::FittedDerivative,
)
}
/// Returns the current packaged-artifact profile with stored ecliptic
/// longitude, latitude, and distance channels plus derived equatorial
/// coordinates.
pub fn ecliptic_longitude_latitude_distance_with_derived_equatorial() -> Self {
Self::packaged_ecliptic_longitude_latitude_distance_with_derived_equatorial()
}
}
impl fmt::Display for ArtifactProfile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.summary_line())
}
}
/// Structured body coverage attached to an artifact capability profile.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ArtifactProfileCoverageSummary {
/// Number of bundled bodies that share the profile.
pub body_count: usize,
/// Bodies bundled under the profile.
pub bodies: Vec<CelestialBody>,
/// Capability profile encoded by the artifact.
pub profile: ArtifactProfile,
}
impl ArtifactProfileCoverageSummary {
/// Creates a profile coverage summary from the profile and bundled bodies.
pub fn new(profile: ArtifactProfile, bodies: Vec<CelestialBody>) -> Self {
let body_count = bodies.len();
Self {
body_count,
bodies,
profile,
}
}
/// Validates that the summary's body count matches the bundled body list and
/// that the embedded artifact profile is internally consistent.
pub fn validate(&self) -> Result<(), CompressionError> {
self.profile.validate()?;
if self.bodies.is_empty() {
return Err(CompressionError::new(
CompressionErrorKind::InvalidFormat,
"artifact profile coverage bundled body list must not be empty",
));
}
validate_unique_values("artifact profile coverage bundled bodies", &self.bodies)?;
validate_canonical_body_order("artifact profile coverage bundled bodies", &self.bodies)?;
if self.body_count != self.bodies.len() {
return Err(CompressionError::new(
CompressionErrorKind::InvalidFormat,
"artifact profile coverage body count does not match bundled body list",
));
}
Ok(())
}
/// Returns the capability summary annotated with how many bundled bodies
/// currently appear in the summary.
pub fn summary_line(&self) -> String {
self.profile.summary_for_body_count(self.bodies.len())
}
/// Returns the validated capability summary annotated with how many bundled
/// bodies currently appear in the summary.
pub fn validated_summary_line(&self) -> Result<String, CompressionError> {
self.validate()?;
Ok(self.summary_line())
}
/// Returns the capability summary annotated with how many bodies share it
/// and lists the bundled bodies explicitly.
pub fn summary_line_with_bodies(&self) -> String {
format!(
"{}; bundled bodies: {}",
self.summary_line(),
crate::join_display(&self.bodies)
)
}
/// Returns the bundled-body summary line after validating the coverage record.
pub fn validated_summary_line_with_bodies(&self) -> Result<String, CompressionError> {
self.validate()?;
Ok(self.summary_line_with_bodies())
}
}
impl fmt::Display for ArtifactProfileCoverageSummary {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.summary_line())
}
}
/// Structured body coverage for residual-correction-bearing segments in a compressed artifact.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ArtifactResidualBodyCoverageSummary {
/// Number of bundled bodies that include at least one residual-correction segment.
pub body_count: usize,
/// Bodies that include at least one residual-correction segment.
pub bodies: Vec<CelestialBody>,
}
impl ArtifactResidualBodyCoverageSummary {
/// Creates a residual-body coverage summary from an explicit body list.
pub fn new(bodies: Vec<CelestialBody>) -> Self {
let body_count = bodies.len();
Self { body_count, bodies }
}
/// Validates that the summary still matches the current artifact residual-body set.
pub fn validate(
&self,
artifact: &crate::artifact::CompressedArtifact,
) -> Result<(), CompressionError> {
let expected_bodies = artifact.residual_bodies();
if self.body_count != self.bodies.len() {
return Err(CompressionError::new(
CompressionErrorKind::InvalidFormat,
"artifact residual-body coverage body count does not match the body list",
));
}
validate_unique_values("artifact residual-body coverage bodies", &self.bodies)?;
if self.body_count != expected_bodies.len() {
return Err(CompressionError::new(
CompressionErrorKind::InvalidFormat,
"artifact residual-body coverage body count does not match residual body list",
));
}
if self.bodies != expected_bodies {
return Err(CompressionError::new(
CompressionErrorKind::InvalidFormat,
"artifact residual-body coverage body list does not match the current artifact",
));
}
Ok(())
}
/// Returns the residual-body coverage as a compact human-readable line.
pub fn summary_line(&self) -> String {
match self.bodies.as_slice() {
[] => "residual bodies: none".to_string(),
bodies => format!("residual bodies: {}", crate::join_display(bodies)),
}
}
/// Returns the residual-body coverage after validating the artifact.
pub fn validated_summary_line(
&self,
artifact: &crate::artifact::CompressedArtifact,
) -> Result<String, CompressionError> {
self.validate(artifact)?;
Ok(self.summary_line())
}
/// Returns the residual-body coverage annotated with how many bodies share it.
pub fn summary_line_with_body_count(&self) -> String {
format!(
"{}; applies to {}",
self.summary_line(),
self.body_count_suffix()
)
}
/// Returns the residual-body coverage line after validating the artifact.
pub fn validated_summary_line_with_body_count(
&self,
artifact: &crate::artifact::CompressedArtifact,
) -> Result<String, CompressionError> {
let summary = self.validated_summary_line(artifact)?;
Ok(format!(
"{}; applies to {}",
summary,
self.body_count_suffix()
))
}
fn body_count_suffix(&self) -> String {
match self.body_count {
1 => "1 bundled body".to_string(),
count => format!("{count} bundled bodies"),
}
}
}
impl fmt::Display for ArtifactResidualBodyCoverageSummary {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.summary_line())
}
}
// ── ArtifactHeader ────────────────────────────────────────────────────────────
/// Describes the non-body metadata stored in a compressed artifact.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ArtifactHeader {
/// Format version.
pub version: u16,
/// Human-readable generation label.
pub generation_label: String,
/// Human-readable provenance/source summary.
pub source: String,
/// Explicit byte-order policy for the stored numeric fields.
pub endian_policy: EndianPolicy,
/// Artifact capability profile describing stored, derived, and unsupported outputs.
pub profile: ArtifactProfile,
}
impl ArtifactHeader {
/// Creates a new header using the current artifact version, an explicit
/// little-endian byte-order policy, and a conservative profile that stores
/// only ecliptic longitude/latitude/distance channels (with equatorial
/// coordinates and motion derived, and apparent/topocentric/sidereal outputs
/// unsupported).
pub fn new(generation_label: impl Into<String>, source: impl Into<String>) -> Self {
Self::with_profile(
generation_label,
source,
ArtifactProfile::packaged_ecliptic_longitude_latitude_distance_with_derived_equatorial(
),
)
}
/// Creates a new header using the current artifact version, an explicit
/// little-endian byte-order policy, and an explicit profile.
pub fn with_profile(
generation_label: impl Into<String>,
source: impl Into<String>,
profile: ArtifactProfile,
) -> Self {
Self::with_profile_and_endian(
generation_label,
source,
EndianPolicy::LittleEndian,
profile,
)
}
/// Creates a new header with an explicit byte-order policy and profile.
pub fn with_profile_and_endian(
generation_label: impl Into<String>,
source: impl Into<String>,
endian_policy: EndianPolicy,
profile: ArtifactProfile,
) -> Self {
Self {
version: crate::ARTIFACT_VERSION,
generation_label: generation_label.into(),
source: source.into(),
endian_policy,
profile,
}
}
/// Returns a compact one-line summary of the byte order and capability
/// profile encoded by this header.
pub fn summary(&self) -> String {
self.summary_line()
}
/// Returns a compact one-line summary of the byte order and capability
/// profile encoded by this header.
pub fn summary_line(&self) -> String {
format!("byte order: {}; {}", self.endian_policy, self.profile)
}
/// Validates that the header's version and provenance fields are populated
/// with canonical, non-whitespace-padded text.
///
/// The codec already enforces these checks at encode/decode time, but
/// exposing the validation step directly lets artifact generators and
/// release tooling fail before writing or reusing an invalid header.
pub fn validate(&self) -> Result<(), CompressionError> {
if self.version != crate::ARTIFACT_VERSION {
return Err(CompressionError::new(
CompressionErrorKind::InvalidFormat,
format!(
"artifact header version {} does not match the current format version {}",
self.version,
crate::ARTIFACT_VERSION
),
));
}
crate::codec::validate_canonical_header_text(
"artifact header generation label",
&self.generation_label,
)?;
crate::codec::validate_canonical_header_text("artifact header source", &self.source)?;
self.profile.validate()
}
/// Returns the header summary annotated with how many bodies share it.
pub fn summary_for_body_count(&self, body_count: usize) -> String {
format!(
"{}; applies to {} bundled bodies",
self.summary_line(),
body_count
)
}
}
impl fmt::Display for ArtifactHeader {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.summary_line())
}
}
// ── Formatting helpers ────────────────────────────────────────────────────────
pub(crate) fn format_bracketed_labels<T: fmt::Display>(values: &[T]) -> String {
format!("[{}]", crate::join_display(values))
}