mirror of
https://github.com/AThilenius/axum-connect.git
synced 2025-01-06 18:18:42 +00:00
WIP - Decouple Prost
This commit is contained in:
parent
ccbebb8dce
commit
93d940f5c7
6 changed files with 45 additions and 17 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -3,7 +3,9 @@
|
||||||
"Buf's",
|
"Buf's",
|
||||||
"bufbuild",
|
"bufbuild",
|
||||||
"codegen",
|
"codegen",
|
||||||
|
"Compressable",
|
||||||
"concat",
|
"concat",
|
||||||
|
"crosstest",
|
||||||
"DTLS",
|
"DTLS",
|
||||||
"impls",
|
"impls",
|
||||||
"pbjson",
|
"pbjson",
|
||||||
|
|
|
@ -18,6 +18,8 @@ repository = "https://github.com/AThilenius/axum-connect"
|
||||||
async-stream = "0.3.5"
|
async-stream = "0.3.5"
|
||||||
async-trait = "0.1.64"
|
async-trait = "0.1.64"
|
||||||
axum = "0.6.9"
|
axum = "0.6.9"
|
||||||
|
base-62 = "0.1.1"
|
||||||
|
bytes = "1.4.0"
|
||||||
futures = "0.3.26"
|
futures = "0.3.26"
|
||||||
pbjson = "0.5.1"
|
pbjson = "0.5.1"
|
||||||
pbjson-types = "0.5.1"
|
pbjson-types = "0.5.1"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
|
use base_62::base62;
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
@ -51,8 +52,28 @@ pub struct RpcErrorDetail {
|
||||||
pub proto_type: String,
|
pub proto_type: String,
|
||||||
#[serde(rename = "value")]
|
#[serde(rename = "value")]
|
||||||
pub proto_b62_value: String,
|
pub proto_b62_value: String,
|
||||||
|
#[serde(rename = "debug")]
|
||||||
|
pub debug_json: Box<serde_json::value::RawValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// impl<M> From<M> for RpcErrorDetail
|
||||||
|
// where
|
||||||
|
// M: Message + Serialize,
|
||||||
|
// {
|
||||||
|
// fn from(val: M) -> Self {
|
||||||
|
// let binary = M::encode_to_vec(&val.1);
|
||||||
|
// // Encode as base62
|
||||||
|
// let b62 = base62::encode(&binary);
|
||||||
|
// let json = serde_json::to_string(&val.1).unwrap();
|
||||||
|
|
||||||
|
// Self {
|
||||||
|
// M::
|
||||||
|
// proto_b62_value: b62,
|
||||||
|
// debug_json: serde_json::value::RawValue::from_string(json).unwrap(),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
#[derive(Clone, Serialize)]
|
#[derive(Clone, Serialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum RpcErrorCode {
|
pub enum RpcErrorCode {
|
||||||
|
@ -115,12 +136,3 @@ where
|
||||||
Err(self)
|
Err(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This needs to be done in the handler to support streaming errors.
|
|
||||||
// impl IntoResponse for RpcError {
|
|
||||||
// fn into_response(self) -> Response {
|
|
||||||
// let status_code = StatusCode::from(self.code.clone());
|
|
||||||
// let json = serde_json::to_string(&self).expect("serialize error type");
|
|
||||||
// (status_code, json).into_response()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod handler;
|
pub mod handler;
|
||||||
|
mod message;
|
||||||
pub mod parts;
|
pub mod parts;
|
||||||
pub mod response;
|
pub mod response;
|
||||||
pub mod router;
|
pub mod router;
|
||||||
|
@ -13,6 +14,7 @@ pub use serde;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::error::*;
|
pub use crate::error::*;
|
||||||
|
pub use crate::message::*;
|
||||||
pub use crate::parts::*;
|
pub use crate::parts::*;
|
||||||
pub use crate::response::*;
|
pub use crate::response::*;
|
||||||
pub use crate::router::RpcRouterExt;
|
pub use crate::router::RpcRouterExt;
|
||||||
|
|
18
axum-connect/src/message.rs
Normal file
18
axum-connect/src/message.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use bytes::{Buf, BufMut};
|
||||||
|
|
||||||
|
use crate::prelude::RpcError;
|
||||||
|
|
||||||
|
/// Wrap Prost traits in our own, so I can start decoupling Prost because it's driving me insane.
|
||||||
|
pub trait Message: prost::Message {
|
||||||
|
const TYPE_URL: &'static str;
|
||||||
|
|
||||||
|
fn encode<B>(&self, buf: &mut B)
|
||||||
|
where
|
||||||
|
B: BufMut,
|
||||||
|
Self: Sized;
|
||||||
|
|
||||||
|
fn decode<B>(buf: B) -> Result<Self, RpcError>
|
||||||
|
where
|
||||||
|
B: Buf,
|
||||||
|
Self: Default;
|
||||||
|
}
|
8
buf.yaml
8
buf.yaml
|
@ -1,8 +0,0 @@
|
||||||
version: v1
|
|
||||||
name: buf.build/woodriver-energy/blink
|
|
||||||
breaking:
|
|
||||||
use:
|
|
||||||
- FILE
|
|
||||||
lint:
|
|
||||||
use:
|
|
||||||
- DEFAULT
|
|
Loading…
Reference in a new issue