use bytes::Bytes;
use serde::Serialize;
use crate::codec::{self, DecodeError, EncodeError};
pub const MAX_JSON_DEPTH: usize = codec::MAX_JSON_DEPTH;
pub fn encode_into<T>(buffer: &mut Vec<u8>, value: &T) -> Result<(), EncodeError>
where
T: Serialize + ?Sized,
{
codec::encode_into(buffer, value)
}
pub fn encode_body<F>(fill: F) -> Result<Bytes, EncodeError>
where
F: FnOnce(&mut Vec<u8>) -> Result<(), EncodeError>,
{
codec::encode_body(fill)
}
pub fn check_depth(json: &[u8]) -> Result<(), DecodeError> {
codec::check_depth(json)
}
#[must_use]
pub fn scratch_capacity() -> usize {
codec::scratch_capacity()
}
#[must_use]
pub fn scratch_hint() -> usize {
codec::scratch_hint()
}
pub fn reset_scratch() {
codec::reset_scratch();
}
pub fn decode<'de, T>(bytes: &'de [u8]) -> Result<T, DecodeError>
where
T: serde::Deserialize<'de>,
{
codec::decode(bytes)
}
pub fn decode_system_one<A>(
body: Bytes,
status: http::StatusCode,
headers: http::HeaderMap,
questions: usize,
) -> Result<crate::response::SystemOneResponse<A>, crate::Error>
where
A: crate::de::AnswerSet,
{
crate::de::decode_system_one_with(
body,
status,
headers,
crate::de::AnswerContext::new(questions),
None,
)
}
pub fn decode_list_models(
body: Bytes,
status: http::StatusCode,
headers: http::HeaderMap,
) -> Result<crate::models::ListModelsResponse, crate::Error> {
crate::models::decode_list_models(body, status, headers, None)
}
#[must_use]
pub fn api_error(
status: http::StatusCode,
body: Bytes,
headers: http::HeaderMap,
) -> crate::ApiError {
crate::error::ApiError::new(status, body, headers, None)
}
#[must_use]
pub fn parse_retry_after(
headers: &http::HeaderMap,
now: std::time::SystemTime,
) -> Option<std::time::Duration> {
crate::error::parse_retry_after(headers, now)
}
#[inline]
#[must_use]
pub fn backoff_seconds(attempt: u32, initial: f64, max: f64, jitter: f64, draw: f64) -> f64 {
crate::retry::backoff_seconds(attempt, initial, max, jitter, draw)
}