From 3066b6ac7436f510d2402a15a643c87bd84d75ac Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 10 Jun 2022 18:51:00 +0200 Subject: update protocol spec --- karlcommon/src/protocol.rs | 2 +- karld/protocol.d.ts | 45 +++++++++++++++------------------------------ 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/karlcommon/src/protocol.rs b/karlcommon/src/protocol.rs index a86ca3d..f971ef2 100644 --- a/karlcommon/src/protocol.rs +++ b/karlcommon/src/protocol.rs @@ -13,7 +13,7 @@ pub enum ClientboundPacket { } #[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(tag = "type", content = "data", rename_all = "snake_case")] +#[serde(tag = "kind", content = "details", rename_all = "snake_case")] pub enum ProtoError { UnknownTask, FormatError(String), diff --git a/karld/protocol.d.ts b/karld/protocol.d.ts index a592146..be1a9bd 100644 --- a/karld/protocol.d.ts +++ b/karld/protocol.d.ts @@ -1,34 +1,19 @@ -// { type: "handshake", version: "10"} -// { type: "handshake", data: {version: "10"}} -//! { "handshake": {version: "10"}} - -export type ServerboundPacket = Download | UpdateTask | RemoveTask -export type ClientboundPacket = Handshake | DownloadResponse - -interface Handshake { - type: "handshake" - data: { version: string } -} - -interface Download { - type: "download", - data: null -} -interface DownloadResponse { - type: "download_response", - data: { tasks: Task[] } -} - -interface UpdateTask { - type: "update_task", - data: Task -} -interface RemoveTask { - type: "remove_task", - data: Task -} - +export type ServerboundPacket = Sync | Handshake | ListTasks | ListInstances | UpdateTask | RemoveTask +export type ClientboundPacket = Handshake | Error | TaskList | InstanceList | Sync + +interface Sync { type: "sync", data: null } +interface Error { type: "error", data: { kind: "unknown_task", details: null } | { kind: "format_error", details: string } } +interface Handshake { type: "handshake", data: { version: string } } +interface ListTasks { type: "list_tasks", data: null } +interface TaskList { type: "task_list", data: Task[] } +interface ListInstances { type: "list_instances", data: null } +interface InstanceList { type: "instance_list", data: Instance[] } +interface UpdateTask { type: "update_task", data: Task } +interface RemoveTask { type: "remove_task", data: number } + +interface Instance { of: number, at: Range } +interface Range { start?: number, end?: number } interface Task { id: number name: string, -- cgit v1.2.3-70-g09d2