pub struct VersionedEnvelope {
pub version: u8,
pub crdt_type: CrdtType,
pub payload: Vec<u8>,
}Expand description
A version envelope wrapping serialized CRDT data.
Binary format (3 bytes overhead):
[MAGIC: 0xCF][VERSION: u8][CRDT_TYPE: u8][PAYLOAD: N bytes]§Example
use crdt_migrate::{VersionedEnvelope, CrdtType};
let data = b"some serialized crdt state";
let envelope = VersionedEnvelope::new(1, CrdtType::GCounter, data.to_vec());
let bytes = envelope.to_bytes();
let decoded = VersionedEnvelope::from_bytes(&bytes).unwrap();
assert_eq!(decoded.version, 1);
assert_eq!(decoded.crdt_type, CrdtType::GCounter);
assert_eq!(decoded.payload, data);Fields§
§version: u8Schema version of the payload.
crdt_type: CrdtTypeType of CRDT contained.
payload: Vec<u8>Serialized CRDT data.
Implementations§
Source§impl VersionedEnvelope
impl VersionedEnvelope
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self, EnvelopeError>
pub fn from_bytes(data: &[u8]) -> Result<Self, EnvelopeError>
Parse an envelope from bytes.
Sourcepub fn peek_version(data: &[u8]) -> Result<u8, EnvelopeError>
pub fn peek_version(data: &[u8]) -> Result<u8, EnvelopeError>
Peek at the version without fully parsing the envelope.
Sourcepub fn is_versioned(data: &[u8]) -> bool
pub fn is_versioned(data: &[u8]) -> bool
Check if bytes look like a versioned envelope (starts with magic byte).
Trait Implementations§
Source§impl Clone for VersionedEnvelope
impl Clone for VersionedEnvelope
Source§fn clone(&self) -> VersionedEnvelope
fn clone(&self) -> VersionedEnvelope
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for VersionedEnvelope
impl Debug for VersionedEnvelope
Source§impl PartialEq for VersionedEnvelope
impl PartialEq for VersionedEnvelope
impl StructuralPartialEq for VersionedEnvelope
Auto Trait Implementations§
impl Freeze for VersionedEnvelope
impl RefUnwindSafe for VersionedEnvelope
impl Send for VersionedEnvelope
impl Sync for VersionedEnvelope
impl Unpin for VersionedEnvelope
impl UnwindSafe for VersionedEnvelope
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
Mutably borrows from an owned value. Read more