#[non_exhaustive]pub struct ClientContractPolicy { /* private fields */ }Expand description
Server policy for version negotiation and bounded JSON encoding/decoding.
Implementations§
Source§impl ClientContractPolicy
impl ClientContractPolicy
Sourcepub const fn new(
minimum_version: ContractVersion,
current_version: ContractVersion,
max_body_bytes: usize,
) -> Result<Self, ClientContractError>
pub const fn new( minimum_version: ContractVersion, current_version: ContractVersion, max_body_bytes: usize, ) -> Result<Self, ClientContractError>
Creates a policy with an inclusive supported version range and body limit.
Sourcepub const fn minimum_version(self) -> ContractVersion
pub const fn minimum_version(self) -> ContractVersion
Returns the minimum accepted wire version.
Sourcepub const fn current_version(self) -> ContractVersion
pub const fn current_version(self) -> ContractVersion
Returns the latest emitted wire version.
Sourcepub const fn max_body_bytes(self) -> usize
pub const fn max_body_bytes(self) -> usize
Returns the configured encoded-body ceiling.
Sourcepub fn decode_offer(
self,
body: &[u8],
) -> Result<ClientVersionOffer, ClientContractError>
pub fn decode_offer( self, body: &[u8], ) -> Result<ClientVersionOffer, ClientContractError>
Decodes a bounded client version offer.
Sourcepub fn encode_offer(
self,
offer: &ClientVersionOffer,
) -> Result<Vec<u8>, ClientContractError>
pub fn encode_offer( self, offer: &ClientVersionOffer, ) -> Result<Vec<u8>, ClientContractError>
Encodes a client version offer within the configured ceiling.
Sourcepub fn negotiate(
self,
offer: &ClientVersionOffer,
) -> Result<ContractVersion, ClientContractError>
pub fn negotiate( self, offer: &ClientVersionOffer, ) -> Result<ContractVersion, ClientContractError>
Selects the highest mutually supported version.
Sourcepub const fn validate_version(
self,
version: ContractVersion,
) -> Result<(), ClientContractError>
pub const fn validate_version( self, version: ContractVersion, ) -> Result<(), ClientContractError>
Verifies that a version falls inside the configured inclusive range.
Sourcepub fn decode_request<T>(
self,
body: &[u8],
) -> Result<ClientRequest<T>, ClientContractError>where
T: DeserializeOwned,
pub fn decode_request<T>(
self,
body: &[u8],
) -> Result<ClientRequest<T>, ClientContractError>where
T: DeserializeOwned,
Decodes and validates a bounded client request.
Sourcepub fn encode_request<T>(
self,
request: &ClientRequest<T>,
) -> Result<Vec<u8>, ClientContractError>where
T: Serialize,
pub fn encode_request<T>(
self,
request: &ClientRequest<T>,
) -> Result<Vec<u8>, ClientContractError>where
T: Serialize,
Encodes a validated client request within the configured ceiling.
Sourcepub fn decode_response<T>(
self,
body: &[u8],
) -> Result<ServerResponse<T>, ClientContractError>where
T: DeserializeOwned,
pub fn decode_response<T>(
self,
body: &[u8],
) -> Result<ServerResponse<T>, ClientContractError>where
T: DeserializeOwned,
Decodes and validates a bounded success response.
Sourcepub fn encode_response<T>(
self,
response: &ServerResponse<T>,
) -> Result<Vec<u8>, ClientContractError>where
T: Serialize,
pub fn encode_response<T>(
self,
response: &ServerResponse<T>,
) -> Result<Vec<u8>, ClientContractError>where
T: Serialize,
Encodes a success response within the configured ceiling.
Sourcepub fn decode_failure(
self,
body: &[u8],
) -> Result<ServerFailure, ClientContractError>
pub fn decode_failure( self, body: &[u8], ) -> Result<ServerFailure, ClientContractError>
Decodes and validates a bounded failure response.
Sourcepub fn encode_failure(
self,
response: &ServerFailure,
) -> Result<Vec<u8>, ClientContractError>
pub fn encode_failure( self, response: &ServerFailure, ) -> Result<Vec<u8>, ClientContractError>
Encodes a failure response within the configured ceiling.