Skip to content

Commit

Permalink
feat: add Deserialize and Serialize to message (#193)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Oct 9, 2023
1 parent 1a26fa3 commit f69a819
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 14 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dragonfly-api"
version = "2.0.30"
version = "2.0.31"
authors = ["Gaius <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -15,6 +15,8 @@ tonic = "0.9.2"
prost = "0.11.9"
prost-types = "0.11.9"
tokio = { version = "1.29.1", features = ["rt-multi-thread", "macros"] }
serde = { version = "1.0", features = ["derive"] }
prost-wkt-types = "0.4"

[build-dependencies]
tonic-build = "0.9.2"
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.file_descriptor_set_path("src/descriptor.bin")
.protoc_arg("--experimental_allow_proto3_optional")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.extern_path(".google.protobuf.Timestamp", "::prost_wkt_types::Timestamp")
.extern_path(".google.protobuf.Duration", "::prost_wkt_types::Duration")
.out_dir("src")
.compile(
&[
Expand Down
32 changes: 24 additions & 8 deletions src/common.v2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// Peer metadata.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Peer {
Expand All @@ -16,7 +17,7 @@ pub struct Peer {
pub pieces: ::prost::alloc::vec::Vec<Piece>,
/// Peer downloads costs time.
#[prost(message, optional, tag = "5")]
pub cost: ::core::option::Option<::prost_types::Duration>,
pub cost: ::core::option::Option<::prost_wkt_types::Duration>,
/// Peer state.
#[prost(string, tag = "6")]
pub state: ::prost::alloc::string::String,
Expand All @@ -31,12 +32,13 @@ pub struct Peer {
pub need_back_to_source: bool,
/// Peer create time.
#[prost(message, optional, tag = "10")]
pub created_at: ::core::option::Option<::prost_types::Timestamp>,
pub created_at: ::core::option::Option<::prost_wkt_types::Timestamp>,
/// Peer update time.
#[prost(message, optional, tag = "11")]
pub updated_at: ::core::option::Option<::prost_types::Timestamp>,
pub updated_at: ::core::option::Option<::prost_wkt_types::Timestamp>,
}
/// Task metadata.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Task {
Expand Down Expand Up @@ -93,12 +95,13 @@ pub struct Task {
pub has_available_peer: bool,
/// Task create time.
#[prost(message, optional, tag = "17")]
pub created_at: ::core::option::Option<::prost_types::Timestamp>,
pub created_at: ::core::option::Option<::prost_wkt_types::Timestamp>,
/// Task update time.
#[prost(message, optional, tag = "18")]
pub updated_at: ::core::option::Option<::prost_types::Timestamp>,
pub updated_at: ::core::option::Option<::prost_wkt_types::Timestamp>,
}
/// Host metadata.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Host {
Expand Down Expand Up @@ -158,6 +161,7 @@ pub struct Host {
pub object_storage_port: i32,
}
/// CPU Stat.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Cpu {
Expand All @@ -179,6 +183,7 @@ pub struct Cpu {
}
/// CPUTimes contains the amounts of time the CPU has spent performing different
/// kinds of work. Time units are in seconds.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CpuTimes {
Expand Down Expand Up @@ -214,6 +219,7 @@ pub struct CpuTimes {
pub guest_nice: f64,
}
/// Memory Stat.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Memory {
Expand All @@ -237,6 +243,7 @@ pub struct Memory {
pub free: u64,
}
/// Network Stat.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Network {
Expand All @@ -254,6 +261,7 @@ pub struct Network {
pub idc: ::core::option::Option<::prost::alloc::string::String>,
}
/// Disk Stat.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Disk {
Expand Down Expand Up @@ -283,6 +291,7 @@ pub struct Disk {
pub inodes_used_percent: f64,
}
/// Build information.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Build {
Expand All @@ -303,6 +312,7 @@ pub struct Build {
pub platform: ::core::option::Option<::prost::alloc::string::String>,
}
/// Download information.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Download {
Expand Down Expand Up @@ -344,7 +354,7 @@ pub struct Download {
pub output_path: ::prost::alloc::string::String,
/// Download timeout.
#[prost(message, optional, tag = "12")]
pub timeout: ::core::option::Option<::prost_types::Duration>,
pub timeout: ::core::option::Option<::prost_wkt_types::Duration>,
/// Download rate limit in bytes per second.
#[prost(double, optional, tag = "13")]
pub download_rate_limit: ::core::option::Option<f64>,
Expand All @@ -353,6 +363,7 @@ pub struct Download {
pub need_back_to_source: bool,
}
/// Range represents download range.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Range {
Expand All @@ -364,6 +375,7 @@ pub struct Range {
pub length: i64,
}
/// Piece represents information of piece.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Piece {
Expand All @@ -390,12 +402,13 @@ pub struct Piece {
pub traffic_type: i32,
/// Downloading piece costs time.
#[prost(message, optional, tag = "8")]
pub cost: ::core::option::Option<::prost_types::Duration>,
pub cost: ::core::option::Option<::prost_wkt_types::Duration>,
/// Piece create time.
#[prost(message, optional, tag = "9")]
pub created_at: ::core::option::Option<::prost_types::Timestamp>,
pub created_at: ::core::option::Option<::prost_wkt_types::Timestamp>,
}
/// SizeScope represents size scope of task.
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum SizeScope {
Expand Down Expand Up @@ -433,6 +446,7 @@ impl SizeScope {
}
}
/// TaskType represents type of task.
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum TaskType {
Expand Down Expand Up @@ -470,6 +484,7 @@ impl TaskType {
}
}
/// TrafficType represents type of traffic.
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum TrafficType {
Expand Down Expand Up @@ -503,6 +518,7 @@ impl TrafficType {
}
}
/// Priority represents priority of application.
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum Priority {
Expand Down
16 changes: 14 additions & 2 deletions src/dfdaemon.v2.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// InterestedAllPiecesRequest represents interested all pieces request of SyncPiecesRequest.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InterestedAllPiecesRequest {}
/// InterestedPiecesRequest represents interested pieces request of SyncPiecesRequest.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InterestedPiecesRequest {
Expand All @@ -11,6 +13,7 @@ pub struct InterestedPiecesRequest {
pub piece_numbers: ::prost::alloc::vec::Vec<u32>,
}
/// SyncPiecesRequest represents request of AnnouncePeer.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SyncPiecesRequest {
Expand All @@ -22,6 +25,7 @@ pub struct SyncPiecesRequest {
}
/// Nested message and enum types in `SyncPiecesRequest`.
pub mod sync_pieces_request {
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Request {
Expand All @@ -32,6 +36,7 @@ pub mod sync_pieces_request {
}
}
/// InterestedPiecesResponse represents interested pieces response of SyncPiecesResponse.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InterestedPiecesResponse {
Expand All @@ -40,6 +45,7 @@ pub struct InterestedPiecesResponse {
pub pieces: ::prost::alloc::vec::Vec<super::super::common::v2::Piece>,
}
/// SyncPiecesResponse represents response of SyncPieces.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SyncPiecesResponse {
Expand All @@ -48,6 +54,7 @@ pub struct SyncPiecesResponse {
}
/// Nested message and enum types in `SyncPiecesResponse`.
pub mod sync_pieces_response {
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Response {
Expand All @@ -56,6 +63,7 @@ pub mod sync_pieces_response {
}
}
/// DownloadTaskRequest represents request of DownloadTask.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DownloadTaskRequest {
Expand All @@ -64,6 +72,7 @@ pub struct DownloadTaskRequest {
pub download: ::core::option::Option<super::super::common::v2::Download>,
}
/// UploadTaskRequest represents request of UploadTask.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UploadTaskRequest {
Expand All @@ -72,6 +81,7 @@ pub struct UploadTaskRequest {
pub task: ::core::option::Option<super::super::common::v2::Task>,
}
/// StatTaskRequest represents request of StatTask.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StatTaskRequest {
Expand All @@ -80,6 +90,7 @@ pub struct StatTaskRequest {
pub task_id: ::prost::alloc::string::String,
}
/// StatTaskResponse represents response of StatTask.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StatTaskResponse {
Expand Down Expand Up @@ -115,12 +126,13 @@ pub struct StatTaskResponse {
pub piece_length: i32,
/// Task create time.
#[prost(message, optional, tag = "10")]
pub created_at: ::core::option::Option<::prost_types::Timestamp>,
pub created_at: ::core::option::Option<::prost_wkt_types::Timestamp>,
/// Task update time.
#[prost(message, optional, tag = "11")]
pub updated_at: ::core::option::Option<::prost_types::Timestamp>,
pub updated_at: ::core::option::Option<::prost_wkt_types::Timestamp>,
}
/// DeleteTaskRequest represents request of DeleteTask.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteTaskRequest {
Expand Down
Loading

0 comments on commit f69a819

Please sign in to comment.