Protocol
elva.protocol
Module holding the Y-Protocol specification.
Classes:
-
YCodec
–Codec for Y messages according to the Yjs base encoding.
-
Message
–Base class for Y messages according to the Yjs sync and awareness protocol.
-
YMessage
–Implementation of Y messages according to the Yjs sync and awareness protocol
-
ElvaMessage
–Extension of Y messages with additional message types.
Functions:
-
write_var_uint
–Calculate the variable unsigned integer length of
data
. -
read_var_uint
–Read and strip off the variable unsigned interger value from
data
.
YCodec
Bases: Codec
Codec for Y messages according to the Yjs base encoding.
Methods:
-
encode
–Prepend the size of
payload
to itself as a variable unsigned integer. -
decode
–Read and strip off the encoded size from
payload
.
encode(payload, errors='strict')
Prepend the size of payload
to itself as a variable unsigned integer.
Parameters:
Returns:
-
tuple[bytes, int]
–A tuple of two values:
data
with the variable unsigned integer prepended and the length ofdata
.
Source code in src/elva/protocol.py
decode(message, errors='strict')
Read and strip off the encoded size from payload
.
Parameters:
Returns:
-
tuple[bytes, int]
–A tuple of two values:
data
with the variable unsigned integer stripped and the length of bytes ofdata
being processed.
Source code in src/elva/protocol.py
Message(*magic_bytes)
Base class for Y messages according to the Yjs sync and awareness protocol.
Parameters:
-
magic_bytes
(bytes
, default:()
) –arbitrary number of bytes prepended in the encoded payload.
Methods:
-
encode
–Calculate the encoded
payload
with the message type's magic bytes prepended. -
decode
–Remove magic bytes and decode
message
. -
infer_and_decode
–Infer the type of the given message and return its decoded form.
Source code in src/elva/protocol.py
encode(payload, errors='strict')
Calculate the encoded payload
with the message type's magic bytes prepended.
Parameters:
Returns:
-
tuple[bytes, int]
–A tuple of two objects: the encoded payload with the message type's magic bytes prepended and the length of bytes being processed.
Source code in src/elva/protocol.py
decode(message, errors='strict')
Remove magic bytes and decode message
.
Parameters:
Returns:
-
tuple[bytes, int]
–A tuple of two objects: the decoded message with the message type's magic bytes removed and the length of bytes being processed.
Source code in src/elva/protocol.py
infer_and_decode(message, errors='strict')
classmethod
Infer the type of the given message and return its decoded form.
Parameters:
Returns:
-
tuple[Self, bytes, int]
–A tuple of three objects: the inferred message type of
message
, the decoded form ofmessage
and the length of processed bytes frommessage
Source code in src/elva/protocol.py
YMessage(*magic_bytes)
Bases: Message
Implementation of Y messages according to the Yjs sync and awareness protocol
Attributes:
-
SYNC_STEP1
–Synchronization request message.
-
SYNC_STEP2
–synchronization reply message.
-
SYNC_UPDATE
–Update message.
-
AWARENESS
–Awareness message.
Source code in src/elva/protocol.py
SYNC_STEP1 = (0, 0)
class-attribute
instance-attribute
Synchronization request message.
SYNC_STEP2 = (0, 1)
class-attribute
instance-attribute
synchronization reply message.
SYNC_UPDATE = (0, 2)
class-attribute
instance-attribute
Update message.
AWARENESS = (1,)
class-attribute
instance-attribute
Awareness message.
ElvaMessage(*magic_bytes)
Bases: Message
Extension of Y messages with additional message types.
Attributes:
-
SYNC_STEP1
–Synchronization request message.
-
SYNC_STEP2
–Synchronization reply message.
-
SYNC_UPDATE
–Update message.
-
SYNC_CROSS
–Cross-synchronization message holding
-
AWARENESS
–Awareness message.
-
ID
–Identitity message.
-
READ
–Read-only message.
-
READ_WRITE
–Read-write message.
-
DATA_REQUEST
–Message requesting a specific blob of data.
-
DATA_OFFER
–Message offering a requested blob of data.
-
DATA_ORDER
–Message ordering a offered blob of data.
-
DATA_TRANSFER
–Message transferring a ordered blob of data.
Source code in src/elva/protocol.py
SYNC_STEP1 = (0, 0)
class-attribute
instance-attribute
Synchronization request message.
SYNC_STEP2 = (0, 1)
class-attribute
instance-attribute
Synchronization reply message.
SYNC_UPDATE = (0, 2)
class-attribute
instance-attribute
Update message.
SYNC_CROSS = (0, 3)
class-attribute
instance-attribute
Cross-synchronization message holding
SYNC_STEP1
and
SYNC_STEP2
.
AWARENESS = (1,)
class-attribute
instance-attribute
Awareness message.
ID = (2, 0)
class-attribute
instance-attribute
Identitity message.
READ = (2, 1)
class-attribute
instance-attribute
Read-only message.
READ_WRITE = (2, 2)
class-attribute
instance-attribute
Read-write message.
DATA_REQUEST = (3, 0)
class-attribute
instance-attribute
Message requesting a specific blob of data.
DATA_OFFER = (3, 1)
class-attribute
instance-attribute
Message offering a requested blob of data.
DATA_ORDER = (3, 2)
class-attribute
instance-attribute
Message ordering a offered blob of data.
DATA_TRANSFER = (3, 3)
class-attribute
instance-attribute
Message transferring a ordered blob of data.
write_var_uint(data)
Calculate the variable unsigned integer length of data
.
Parameters:
-
data
(bytes
) –bytes object.
Returns:
-
tuple[bytes, int]
–A tuple of two values:
data
with the variable unsigned integer prepended and the length ofdata
.
Source code in src/elva/protocol.py
read_var_uint(data)
Read and strip off the variable unsigned interger value from data
.
Parameters:
-
data
(bytes
) –bytes object.
Returns:
-
tuple[bytes, int]
–A tuple of two values:
data
with the variable unsigned integer stripped and the length of bytes ofdata
being processed.