1#![allow(clippy::too_many_arguments)]
6
7use serde::{Deserialize, Serialize};
8use spatio_types::geo::{DistanceMetric, Point, Polygon};
9use spatio_types::point::Point3d;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct LocationUpdate {
13 pub timestamp: f64,
14 pub position: Point3d,
15 pub metadata: Vec<u8>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct Stats {
20 pub object_count: usize,
21 pub memory_usage_bytes: usize,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct CurrentLocation {
26 pub object_id: String,
27 pub position: Point3d,
28 pub metadata: Vec<u8>,
29}
30
31#[allow(clippy::too_many_arguments)]
32#[tarpc::service]
33pub trait SpatioService {
34 async fn upsert(
35 namespace: String,
36 id: String,
37 point: Point3d,
38 metadata: serde_json::Value,
39 ) -> Result<(), String>;
40
41 async fn get(namespace: String, id: String) -> Result<Option<CurrentLocation>, String>;
42
43 async fn delete(namespace: String, id: String) -> Result<(), String>;
44
45 async fn query_radius(
46 namespace: String,
47 center: Point3d,
48 radius: f64,
49 limit: usize,
50 ) -> Result<Vec<(CurrentLocation, f64)>, String>;
51
52 async fn knn(
53 namespace: String,
54 center: Point3d,
55 k: usize,
56 ) -> Result<Vec<(CurrentLocation, f64)>, String>;
57
58 async fn query_bbox(
59 namespace: String,
60 min_x: f64,
61 min_y: f64,
62 max_x: f64,
63 max_y: f64,
64 limit: usize,
65 ) -> Result<Vec<CurrentLocation>, String>;
66
67 async fn query_cylinder(
68 namespace: String,
69 center: Point,
70 min_z: f64,
71 max_z: f64,
72 radius: f64,
73 limit: usize,
74 ) -> Result<Vec<(CurrentLocation, f64)>, String>;
75
76 async fn query_trajectory(
77 namespace: String,
78 id: String,
79 start_time: Option<f64>,
80 end_time: Option<f64>,
81 limit: usize,
82 ) -> Result<Vec<LocationUpdate>, String>;
83
84 async fn insert_trajectory(
85 namespace: String,
86 id: String,
87 trajectory: Vec<(f64, Point3d, serde_json::Value)>,
88 ) -> Result<(), String>;
89
90 async fn query_bbox_3d(
91 namespace: String,
92 min_x: f64,
93 min_y: f64,
94 min_z: f64,
95 max_x: f64,
96 max_y: f64,
97 max_z: f64,
98 limit: usize,
99 ) -> Result<Vec<CurrentLocation>, String>;
100
101 async fn query_near(
102 namespace: String,
103 id: String,
104 radius: f64,
105 limit: usize,
106 ) -> Result<Vec<(CurrentLocation, f64)>, String>;
107
108 async fn contains(
109 namespace: String,
110 polygon: Polygon,
111 limit: usize,
112 ) -> Result<Vec<CurrentLocation>, String>;
113
114 async fn distance(
115 namespace: String,
116 id1: String,
117 id2: String,
118 metric: Option<DistanceMetric>,
119 ) -> Result<Option<f64>, String>;
120
121 async fn distance_to(
122 namespace: String,
123 id: String,
124 point: Point,
125 metric: Option<DistanceMetric>,
126 ) -> Result<Option<f64>, String>;
127
128 async fn convex_hull(namespace: String) -> Result<Option<Polygon>, String>;
129
130 async fn bounding_box(
131 namespace: String,
132 ) -> Result<Option<spatio_types::bbox::BoundingBox2D>, String>;
133
134 async fn stats() -> Stats;
135}