Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to use with simd-json? #41

Open
AlJohri opened this issue Jan 25, 2024 · 0 comments
Open

Possible to use with simd-json? #41

AlJohri opened this issue Jan 25, 2024 · 0 comments

Comments

@AlJohri
Copy link

AlJohri commented Jan 25, 2024

Is it possible to use tonic-rpc with simd-json (with the serde_impl flag)? Does this require implementing a new codec similar to the existing JSON version or is there a way to plug in an alternative implementation?

#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub struct JsonSerdeCodec;

#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
impl SerdeCodec for JsonSerdeCodec {
fn write<T, W>(item: T, w: W) -> Result<(), Status>
where
T: Serialize,
W: Write,
{
serde_json::to_writer(w, &item)
.map_err(|serde_err| Status::internal(format!("Error serializing {}", serde_err)))
}
fn read<T, R>(r: R) -> Result<T, Status>
where
T: for<'de> Deserialize<'de>,
R: Read,
{
serde_json::from_reader(r)
.map_err(|serde_err| Status::internal(format!("Error deserializing {}", serde_err)))
}
}

#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub type JsonCodec<T, U> = Codec<JsonSerdeCodec, T, U>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant