try to add cbor support

This commit is contained in:
cloudybyte 2021-07-26 17:29:52 +02:00
parent 411ddfbe7b
commit 9fe4188196
No known key found for this signature in database
GPG Key ID: B5D60699E041B91C
3 changed files with 12 additions and 0 deletions

View File

@ -37,6 +37,7 @@ pin-project-lite = "0.2.6"
regex = "1.4.5"
serde = { version = "1.0.125", features = ["derive"] }
serde_json = "1.0.64"
serde_cbor = "0.11.1"
thiserror = "1.0.24"
static_assertions = "1.1.0"
http = "0.2.3"

View File

@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::{parser, InputType, Pos, Value};
use serde::de::Error as SerdeError;
/// Extensions to the error.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]

View File

@ -54,3 +54,13 @@ pub async fn receive_batch_json(body: impl AsyncRead) -> Result<BatchRequest, Pa
.map_err(ParseRequestError::Io)?;
Ok(serde_json::from_slice::<BatchRequest>(&data).map_err(ParseRequestError::InvalidRequest)?)
}
pub async fn receive_batch_cbor(body: impl AsyncRead) -> Result<BatchRequest, ParseRequestError> {
let mut data = Vec::new();
futures_util::pin_mut!(body);
body.read_to_end(&mut data)
.await
.map_err(ParseRequestError::Io)?;
Ok(serde_cbor::from_slice::<BatchRequest>(&data).map_err(ParseRequestError::InvalidRequest)?)
}