try to add cbor support
This commit is contained in:
parent
411ddfbe7b
commit
9fe4188196
|
@ -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"
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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)?)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user