spoolframe_protocol/resource.rs
1//! One metadata frame followed by exactly `length` raw bytes for every
2//! binary resource. Playback revisions are independent of encoder epochs.
3use crate::{ArtworkRequest, Error, MediaRead, PlaybackHandle, SessionId};
4use serde::{Deserialize, Serialize};
5use spoolframe_types::{ArtworkId, SubtitleFormat};
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(tag = "type", rename_all = "snake_case")]
9pub enum ResourceRequest {
10 Artwork {
11 request: ArtworkRequest,
12 max_bytes: u64,
13 },
14 Media {
15 request: MediaRead,
16 revision: u64,
17 },
18 Subtitle {
19 session: SessionId,
20 handle: PlaybackHandle,
21 revision: u64,
22 offset: u64,
23 version: Option<u64>,
24 },
25 SubtitleSegment {
26 session: SessionId,
27 handle: PlaybackHandle,
28 revision: u64,
29 segment: u32,
30 },
31 /// Upload a cover for playlist `id` (PX-53, `spoolframe:playlist-art`):
32 /// the only request whose stream goes on past it, with exactly
33 /// `length` bytes of a JPEG, PNG, WebP or HEIC picture. Answered
34 /// `ready { length: 0, playlist_art { artwork } }`, with no body.
35 /// Refused before the picture is read when the user may not edit the
36 /// playlist (`NotAllowed`) or `length` is past
37 /// [`crate::playlists::MAX_ART_BYTES`] (`ImageTooLarge`).
38 SetPlaylistArt {
39 session: SessionId,
40 id: String,
41 length: u64,
42 },
43 /// Read download `id`'s file (PX-38, `spoolframe:downloads`): at most
44 /// `length` bytes from `offset`, and no more than [`crate::MAX_READ`].
45 /// Any offset may be asked, so a download broken off resumes where it
46 /// stopped. Answered `ready { length, download { size } }` with the
47 /// bytes; `length` is short only at the file's end. `NotFound` for an
48 /// id that is not the session user's; `DownloadNotReady` until its
49 /// state is `ready`. Not a playback: it takes no playback slot.
50 Download {
51 session: SessionId,
52 id: String,
53 offset: u64,
54 length: u64,
55 },
56}
57
58#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
59#[serde(tag = "type", rename_all = "snake_case")]
60pub enum ResourceMetadata {
61 Artwork {
62 content_type: String,
63 etag: String,
64 },
65 Media {
66 size: u64,
67 complete: bool,
68 epoch: u32,
69 revision: u64,
70 },
71 Subtitle {
72 format: SubtitleFormat,
73 total: u64,
74 version: u64,
75 revision: u64,
76 },
77 /// The cover `SetPlaylistArt` stored: the playlist's `artwork` now.
78 PlaylistArt {
79 artwork: ArtworkId,
80 },
81 /// A download's file (`Download`): its whole length.
82 Download {
83 size: u64,
84 },
85}
86
87#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
88#[serde(tag = "type", rename_all = "snake_case")]
89pub enum ResourceResponse {
90 Ready {
91 length: u64,
92 metadata: ResourceMetadata,
93 },
94 Error {
95 error: Error,
96 },
97}