pub struct VersionedValue {
pub schema: String,
pub version: u64,
pub encoding: Encoding,
pub payload: Vec<u8>,
}Expand description
Deterministic schema/version envelope for an application value.
The envelope is useful when a tree contains values that may evolve over time. It keeps the core map byte-oriented while giving applications a stable place to record a schema name, schema version, value encoding, and payload bytes.
Fields§
§schema: StringApplication schema or type name.
version: u64Application-controlled schema version.
encoding: EncodingEncoding used for payload.
payload: Vec<u8>Encoded application payload.
Implementations§
Source§impl VersionedValue
impl VersionedValue
Sourcepub fn raw(
schema: impl Into<String>,
version: u64,
payload: impl Into<Vec<u8>>,
) -> Self
pub fn raw( schema: impl Into<String>, version: u64, payload: impl Into<Vec<u8>>, ) -> Self
Create a versioned raw-byte value.
Sourcepub fn json<T: Serialize>(
schema: impl Into<String>,
version: u64,
value: &T,
) -> Result<Self, Error>
pub fn json<T: Serialize>( schema: impl Into<String>, version: u64, value: &T, ) -> Result<Self, Error>
Create a versioned JSON value.
Sourcepub fn cbor<T: Serialize>(
schema: impl Into<String>,
version: u64,
value: &T,
) -> Result<Self, Error>
pub fn cbor<T: Serialize>( schema: impl Into<String>, version: u64, value: &T, ) -> Result<Self, Error>
Create a versioned CBOR value.
Sourcepub fn with_encoding(
schema: impl Into<String>,
version: u64,
encoding: Encoding,
payload: impl Into<Vec<u8>>,
) -> Self
pub fn with_encoding( schema: impl Into<String>, version: u64, encoding: Encoding, payload: impl Into<Vec<u8>>, ) -> Self
Create a versioned value with an explicit encoding marker.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, Error>
pub fn to_bytes(&self) -> Result<Vec<u8>, Error>
Encode the envelope as deterministic bytes suitable for a leaf value.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
Decode a deterministic versioned value envelope.
Sourcepub fn decode_json<T: DeserializeOwned>(&self) -> Result<T, Error>
pub fn decode_json<T: DeserializeOwned>(&self) -> Result<T, Error>
Decode the payload as JSON, failing if the envelope is not JSON encoded.
Sourcepub fn decode_cbor<T: DeserializeOwned>(&self) -> Result<T, Error>
pub fn decode_cbor<T: DeserializeOwned>(&self) -> Result<T, Error>
Decode the payload as CBOR, failing if the envelope is not CBOR encoded.
Sourcepub fn require_schema(&self, schema: &str, version: u64) -> Result<(), Error>
pub fn require_schema(&self, schema: &str, version: u64) -> Result<(), Error>
Verify the envelope schema and version before decoding a payload.
Sourcepub fn matches_schema(&self, schema: &str, version: u64) -> bool
pub fn matches_schema(&self, schema: &str, version: u64) -> bool
Return true when this value has the requested schema and version.
Trait Implementations§
Source§impl Clone for VersionedValue
impl Clone for VersionedValue
Source§fn clone(&self) -> VersionedValue
fn clone(&self) -> VersionedValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VersionedValue
impl Debug for VersionedValue
Source§impl<'de> Deserialize<'de> for VersionedValue
impl<'de> Deserialize<'de> for VersionedValue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for VersionedValue
Source§impl PartialEq for VersionedValue
impl PartialEq for VersionedValue
Source§impl Serialize for VersionedValue
impl Serialize for VersionedValue
impl StructuralPartialEq for VersionedValue
Auto Trait Implementations§
impl Freeze for VersionedValue
impl RefUnwindSafe for VersionedValue
impl Send for VersionedValue
impl Sync for VersionedValue
impl Unpin for VersionedValue
impl UnsafeUnpin for VersionedValue
impl UnwindSafe for VersionedValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more