#![doc = include_str!("../README.md")]
use std::ops::RangeInclusive;
mod convert;
mod frame;
mod generated;
#[cfg(feature = "python")]
pub mod python;
mod requirement;
mod wire;
#[cfg(feature = "worker")]
pub mod worker;
pub const PROTOCOL_VERSION: u32 = 1;
pub const MIN_SUPPORTED_PROTOCOL_VERSION: u32 = 1;
const _: () = assert!(MIN_SUPPORTED_PROTOCOL_VERSION >= 1);
const _: () = assert!(MIN_SUPPORTED_PROTOCOL_VERSION <= PROTOCOL_VERSION);
const SUPPORTED_PROTOCOL_VERSIONS: RangeInclusive<u32> = MIN_SUPPORTED_PROTOCOL_VERSION..=PROTOCOL_VERSION;
pub fn check_protocol_version(version: u32) -> Result<(), String> {
if SUPPORTED_PROTOCOL_VERSIONS.contains(&version) {
Ok(())
} else {
Err(format!(
"unsupported protocol version {version} ({})",
supported_versions()
))
}
}
fn supported_versions() -> String {
if MIN_SUPPORTED_PROTOCOL_VERSION == PROTOCOL_VERSION {
format!("this build supports protocol version {PROTOCOL_VERSION}")
} else {
format!("this build supports protocol versions {MIN_SUPPORTED_PROTOCOL_VERSION} to {PROTOCOL_VERSION}")
}
}
pub use convert::{MAX_VALUE_DEPTH, ProtoConvertError, exceeds_max_value_depth, future_results_from_proto};
pub use frame::{
DEFAULT_MAX_DECODE_BYTES, FrameError, FrameReader, MAX_FRAME_LEN, decode_frame, encode_framed_into,
encode_to_capped_vec, exceeds_max_frame_len, write_frame,
};
pub use generated::pb;
pub use requirement::validate_requirement;
pub use wire::{WireFunctionCall, WireObject, reset_decode_budget};