From ca22261401990655694fb639bdf40a911a5c0963 Mon Sep 17 00:00:00 2001 From: Antonio Gisondi Date: Tue, 10 Oct 2023 18:03:42 +0200 Subject: [PATCH] Add generated code Signed-off-by: Antonio Gisondi --- .../src/astarteplatform.msghub.rs | 109 ++++++++++++++++-- 1 file changed, 100 insertions(+), 9 deletions(-) diff --git a/rust/astarte-message-hub-proto/src/astarteplatform.msghub.rs b/rust/astarte-message-hub-proto/src/astarteplatform.msghub.rs index 7b75dfc..cecf8ee 100644 --- a/rust/astarte-message-hub-proto/src/astarteplatform.msghub.rs +++ b/rust/astarte-message-hub-proto/src/astarteplatform.msghub.rs @@ -135,6 +135,77 @@ pub mod astarte_data_type { AstarteObject(super::AstarteDataTypeObject), } } +/// Astarte Error type +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct MessageHubError { + /// Error enum value. + #[prost(enumeration = "message_hub_error::ErrorCode", tag = "1")] + pub error_code: i32, + /// Human-readable string describing the error. + #[prost(string, tag = "2")] + pub error_description: ::prost::alloc::string::String, +} +/// Nested message and enum types in `MessageHubError`. +pub mod message_hub_error { + /// A list specifying general categories of Astarte Message Hub error. + #[derive( + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::prost::Enumeration + )] + #[repr(i32)] + pub enum ErrorCode { + /// Unknown error. + Unknown = 0, + /// Error occurred when trying to send an invalid data. + AstarteInvalidData = 1, + /// Error returned by the Astarte SDK. + AstarteSdkError = 2, + /// Error occurred during conversion between types. + ConversionError = 3, + } + impl ErrorCode { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + ErrorCode::Unknown => "UNKNOWN", + ErrorCode::AstarteInvalidData => "ASTARTE_INVALID_DATA", + ErrorCode::AstarteSdkError => "ASTARTE_SDK_ERROR", + ErrorCode::ConversionError => "CONVERSION_ERROR", + } + } + } +} +/// Astarte message result used when receiving data or an error from Astarte. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct AstarteMessageResult { + #[prost(oneof = "astarte_message_result::Result", tags = "1, 2")] + pub result: ::core::option::Option, +} +/// Nested message and enum types in `AstarteMessageResult`. +pub mod astarte_message_result { + #[allow(clippy::derive_partial_eq_without_eq)] + #[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum Result { + /// A message that contains data sent from Astarte. + #[prost(message, tag = "1")] + AstarteMessage(super::AstarteMessage), + /// A message that contains a specific Astarte Message Hub error. + #[prost(message, tag = "2")] + HubError(super::MessageHubError), + } +} /// Astarte message to be used when sending data to Astarte. #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -181,6 +252,26 @@ pub struct Node { #[prost(bytes = "vec", repeated, tag = "2")] pub interface_jsons: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, } +/// Astarte Data result used when receiving data or an error from Astarte. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct MessageHubResult { + #[prost(oneof = "message_hub_result::Result", tags = "1, 2")] + pub result: ::core::option::Option, +} +/// Nested message and enum types in `MessageHubResult`. +pub mod message_hub_result { + #[allow(clippy::derive_partial_eq_without_eq)] + #[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum Result { + /// A message that contains an empty value for success response. + #[prost(message, tag = "1")] + EmptyMessage(::pbjson_types::Empty), + /// A message that contains a specific Astarte Message Hub error. + #[prost(message, tag = "2")] + HubError(super::MessageHubError), + } +} /// Generated client implementations. pub mod message_hub_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] @@ -256,7 +347,7 @@ pub mod message_hub_client { &mut self, request: impl tonic::IntoRequest, ) -> Result< - tonic::Response>, + tonic::Response>, tonic::Status, > { self.inner @@ -278,7 +369,7 @@ pub mod message_hub_client { pub async fn send( &mut self, request: impl tonic::IntoRequest, - ) -> Result, tonic::Status> { + ) -> Result, tonic::Status> { self.inner .ready() .await @@ -298,7 +389,7 @@ pub mod message_hub_client { pub async fn detach( &mut self, request: impl tonic::IntoRequest, - ) -> Result, tonic::Status> { + ) -> Result, tonic::Status> { self.inner .ready() .await @@ -325,7 +416,7 @@ pub mod message_hub_server { pub trait MessageHub: Send + Sync + 'static { ///Server streaming response type for the Attach method. type AttachStream: futures_core::Stream< - Item = Result, + Item = Result, > + Send + 'static; @@ -339,12 +430,12 @@ pub mod message_hub_server { async fn send( &self, request: tonic::Request, - ) -> Result, tonic::Status>; + ) -> Result, tonic::Status>; /// This function should be used to detach a node from an instance of the Astarte message hub. async fn detach( &self, request: tonic::Request, - ) -> Result, tonic::Status>; + ) -> Result, tonic::Status>; } #[derive(Debug)] pub struct MessageHubServer { @@ -412,7 +503,7 @@ pub mod message_hub_server { T: MessageHub, > tonic::server::ServerStreamingService for AttachSvc { - type Response = super::AstarteMessage; + type Response = super::AstarteMessageResult; type ResponseStream = T::AttachStream; type Future = BoxFuture< tonic::Response, @@ -450,7 +541,7 @@ pub mod message_hub_server { impl< T: MessageHub, > tonic::server::UnaryService for SendSvc { - type Response = ::pbjson_types::Empty; + type Response = super::MessageHubResult; type Future = BoxFuture< tonic::Response, tonic::Status, @@ -486,7 +577,7 @@ pub mod message_hub_server { struct DetachSvc(pub Arc); impl tonic::server::UnaryService for DetachSvc { - type Response = ::pbjson_types::Empty; + type Response = super::MessageHubResult; type Future = BoxFuture< tonic::Response, tonic::Status,