Skip to main content

shardline_xet_adapter/
model.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5/// End-exclusive chunk index range within one xorb.
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7pub struct ReconstructionChunkRange {
8    /// First chunk index included by this range.
9    pub start: u32,
10    /// End-exclusive chunk index.
11    pub end: u32,
12}
13
14/// Inclusive byte range for a ranged fetch URL.
15#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
16pub struct ReconstructionUrlRange {
17    /// First byte offset.
18    pub start: u64,
19    /// Inclusive final byte offset.
20    pub end: u64,
21}
22
23/// Ordered reconstruction term returned by the Xet reconstruction API.
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
25pub struct ReconstructionTerm {
26    /// Xorb hash in Xet CAS API hexadecimal ordering.
27    pub hash: String,
28    /// Expected total decompressed byte length for this term.
29    pub unpacked_length: u64,
30    /// Chunk range to read from the referenced xorb.
31    pub range: ReconstructionChunkRange,
32}
33
34/// Fetch information for downloading one xorb range.
35#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
36pub struct ReconstructionFetchInfo {
37    /// Chunk range provided by this fetch URL.
38    pub range: ReconstructionChunkRange,
39    /// Download URL for the serialized xorb bytes.
40    pub url: String,
41    /// Inclusive byte range to request from the download URL.
42    pub url_range: ReconstructionUrlRange,
43}
44
45/// V2 byte-range descriptor for one xorb fetch entry.
46#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
47pub struct ReconstructionRangeDescriptor {
48    /// Chunk range covered by this fetch descriptor.
49    pub chunks: ReconstructionChunkRange,
50    /// Inclusive byte range to request from the xorb URL.
51    pub bytes: ReconstructionUrlRange,
52}
53
54/// V2 fetch information for downloading one xorb via one or more byte ranges.
55#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
56pub struct ReconstructionMultiRangeFetch {
57    /// Download URL for the serialized xorb bytes.
58    pub url: String,
59    /// Ordered byte ranges covered by this fetch descriptor.
60    pub ranges: Vec<ReconstructionRangeDescriptor>,
61}
62
63/// File reconstruction response.
64#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
65pub struct FileReconstructionResponse {
66    /// Byte offset to skip from the first returned term when the request used a
67    /// reconstruction range.
68    pub offset_into_first_range: u64,
69    /// Ordered reconstruction terms in Xet download order.
70    pub terms: Vec<ReconstructionTerm>,
71    /// Download metadata keyed by xorb hash.
72    pub fetch_info: BTreeMap<String, Vec<ReconstructionFetchInfo>>,
73}
74
75/// V2 file reconstruction response.
76#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
77pub struct FileReconstructionV2Response {
78    /// Byte offset to skip from the first returned term when the request used a
79    /// reconstruction range.
80    pub offset_into_first_range: u64,
81    /// Ordered reconstruction terms in Xet download order.
82    pub terms: Vec<ReconstructionTerm>,
83    /// Download metadata keyed by xorb hash.
84    pub xorbs: BTreeMap<String, Vec<ReconstructionMultiRangeFetch>>,
85}
86
87/// Batch reconstruction response for multiple file identifiers.
88#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
89pub struct BatchReconstructionResponse {
90    /// Ordered reconstruction terms keyed by file identifier.
91    pub files: BTreeMap<String, Vec<ReconstructionTerm>>,
92    /// Download metadata keyed by xorb hash.
93    pub fetch_info: BTreeMap<String, Vec<ReconstructionFetchInfo>>,
94}
95
96/// Upload result for a single xorb.
97#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
98pub struct XorbUploadResponse {
99    /// Whether the xorb bytes were newly inserted.
100    pub was_inserted: bool,
101}
102
103/// Upload result for a single shard.
104#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
105pub struct ShardUploadResponse {
106    /// Shard registration status.
107    pub result: u8,
108}