Documentation
¶
Overview ¶
Package protocol implements the Yjs binary wire format: LEB128 unsigned varints, variable-length byte arrays, and UTF-8 strings, matching lib0/encoding exactly.
Index ¶
- Constants
- func DecodeStateVectorV1(data []byte) (map[uint64]uint64, error)
- func EncodeStateVectorV1(sv map[uint64]uint64) ([]byte, error)
- func EncodeSyncStep1(stateVector []byte) []byte
- func EncodeSyncStep2(update []byte) []byte
- func EncodeUpdate(update []byte) []byte
- func EncodeUpdateV1(u *UpdateV1) ([]byte, error)
- func ReadAny(r io.Reader) (interface{}, error)
- func ReadVarBytes(r io.Reader) ([]byte, error)
- func ReadVarString(r io.Reader) (string, error)
- func ReadVarUint(r io.Reader) (uint64, error)
- func WriteAny(w io.Writer, v interface{}) error
- func WriteSyncStep1(w io.Writer, stateVector []byte) error
- func WriteSyncStep2(w io.Writer, update []byte) error
- func WriteUpdate(w io.Writer, update []byte) error
- func WriteVarBytes(w io.Writer, b []byte) error
- func WriteVarString(w io.Writer, s string) error
- func WriteVarUint(w io.Writer, v uint64) error
- type EncodedDeleteRange
- type EncodedID
- type EncodedItem
- type SyncMessage
- type UpdateV1
Constants ¶
const ( MessageYjsSyncStep1 = uint64(0) MessageYjsSyncStep2 = uint64(1) MessageYjsUpdate = uint64(2) )
y-protocols sync message types.
Variables ¶
This section is empty.
Functions ¶
func DecodeStateVectorV1 ¶
DecodeStateVectorV1 parses a state vector from v1 bytes.
func EncodeStateVectorV1 ¶
EncodeStateVectorV1 serializes a state vector in v1 format. Format: varuint(n), then n*(varuint(clientID), varuint(clock)), sorted descending clientID.
func EncodeSyncStep1 ¶
EncodeSyncStep1 returns the binary encoding of a sync step 1 message.
func EncodeSyncStep2 ¶
EncodeSyncStep2 returns the binary encoding of a sync step 2 message.
func EncodeUpdate ¶
EncodeUpdate returns the binary encoding of an update message.
func EncodeUpdateV1 ¶
EncodeUpdateV1 encodes a v1 update to bytes.
func ReadVarBytes ¶
ReadVarBytes reads a length-prefixed byte slice.
func ReadVarString ¶
ReadVarString reads a length-prefixed UTF-8 string.
func ReadVarUint ¶
ReadVarUint reads a LEB128 unsigned varint from r.
func WriteSyncStep1 ¶
WriteSyncStep1 writes a sync step 1 message: the sender's state vector. Format: varuint(0), varBytes(stateVector)
func WriteSyncStep2 ¶
WriteSyncStep2 writes a sync step 2 message: the update the receiver needs. Format: varuint(1), varBytes(update)
func WriteUpdate ¶
WriteUpdate writes an update message. Format: varuint(2), varBytes(update)
func WriteVarBytes ¶
WriteVarBytes writes a length-prefixed byte slice: varuint(len) + bytes.
func WriteVarString ¶
WriteVarString writes a UTF-8 string as varuint(UTF-8 byte length) + UTF-8 bytes.
Types ¶
type EncodedDeleteRange ¶
EncodedDeleteRange is a [clock, clock+len) deletion range.
type EncodedItem ¶
type EncodedItem struct {
ClientID uint64
Clock uint64
Length uint64
IsGC bool
IsSkip bool
InfoByte byte
OriginLeft *EncodedID
OriginRight *EncodedID
// Parent (only when OriginLeft == nil && OriginRight == nil):
ParentIsYKey bool
ParentYKey string
ParentID *EncodedID
ParentSub *string
ContentRef byte
ContentData interface{}
}
EncodedItem is a fully decoded struct from a v1 update.
type SyncMessage ¶
type SyncMessage struct {
Type uint64
// For step1: StateVector bytes.
// For step2 / update: Update bytes.
Payload []byte
}
SyncMessage is a parsed y-protocols sync message.
func ReadSyncMessage ¶
func ReadSyncMessage(r io.Reader) (*SyncMessage, error)
ReadSyncMessage reads one sync message from r.
type UpdateV1 ¶
type UpdateV1 struct {
Items []*EncodedItem
DeleteSet map[uint64][]EncodedDeleteRange
}
UpdateV1 is the fully decoded content of a Yjs v1 update message.
func DecodeUpdateV1 ¶
DecodeUpdateV1 decodes a v1 update from raw bytes.