Struct MessageFlags
pub struct MessageFlags(/* private fields */);Expand description
Per-message flags packed into a bitfield byte on the wire.
§Wire encoding
Flags are encoded a little strangely, it’s easiest to explain by explaining the history. The first flag we added was to indicate that the other end supported “v2” sync protocol messages - sync messages in which the entire document state is sent in a single message. This flag was forward compatibly encoded by taking advantage of the fact that the original parser would ignore any bytes after the end of the sync message. We thus encoded new flags as length prefixed set of flags at the end of the message. I.e. it looked a bit like this:
| message length | < sync message > | number of flags | flags |
The idea was that this allows us to forward compatibly add new flags to the
protocol by just sending a longer list of flags. The problem with this
approach is that it usees a byte per flag, which becomes much more wasteful
as the number of flags grows. Thus, we now encode flags as bitfields. We
want to stay backwards compatible for implementations unaware of the bitfields
though. To do this we take advantage of the fact that there was only ever
one flag sent - the old MessageV2 flag. This means that the only flags
ever sent were:
| 0x01 | 0x02 |
Where 0x01 is the length prefix byte and 0x02 is the old MessageV2 flag.
To stay backwards compatible we encode the old MessageV2 flag as a single byte
and then all the remaining flags as a byte with the high bit set. The old
code thus sees a bunch of unknown bytes after the old MessageV2 flag and
ignores them, the new code reads every bit and parses any byte with it’s high
bit set as a bitfield of flags. This scheme allows us to forward compatibly
add as many flags as we need (by increasing the length prefix) without breaking
old implementations.
The final encoding then is
| length prefix | old MessageV2 flag | bitfield byte (0x80 set) |
When parsing messages from old implementations (all bytes < 0x80), the old individual byte values are mapped to the corresponding flag bits.
Implementations§
§impl MessageFlags
impl MessageFlags
pub const SYNC_RESET: u8
pub const SYNC_RESET: u8
Signals the remote peer should clear its sent_hashes and perform a
fresh sync. Used when switching from read-only to read-write mode.
pub const READ_ONLY: u8
pub const READ_ONLY: u8
Indicates the sender is in read-only mode and will not apply incoming changes.
pub const SUPPORTS_SYNC_RESET: u8
pub const SUPPORTS_SYNC_RESET: u8
Advertises that the sender understands the SYNC_RESET
flag and will clear sent_hashes when it receives one.
pub fn new() -> MessageFlags
pub fn contains(self, flag: u8) -> bool
pub fn set(&mut self, flag: u8)
Trait Implementations§
§impl Clone for MessageFlags
impl Clone for MessageFlags
§fn clone(&self) -> MessageFlags
fn clone(&self) -> MessageFlags
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for MessageFlags
impl Debug for MessageFlags
§impl Default for MessageFlags
impl Default for MessageFlags
§fn default() -> MessageFlags
fn default() -> MessageFlags
§impl Hash for MessageFlags
impl Hash for MessageFlags
§impl PartialEq for MessageFlags
impl PartialEq for MessageFlags
impl Copy for MessageFlags
impl Eq for MessageFlags
impl StructuralPartialEq for MessageFlags
Auto Trait Implementations§
impl Freeze for MessageFlags
impl RefUnwindSafe for MessageFlags
impl Send for MessageFlags
impl Sync for MessageFlags
impl Unpin for MessageFlags
impl UnsafeUnpin for MessageFlags
impl UnwindSafe for MessageFlags
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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