How to use the lib0/decoding.js.readVarUint function in lib0

To help you get started, we’ve selected a few lib0 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yjs / yjs / src / utils / DeleteSet.js View on Github external
export const readDeleteSet = decoder => {
  const ds = new DeleteSet()
  const numClients = decoding.readVarUint(decoder)
  for (let i = 0; i < numClients; i++) {
    const client = decoding.readVarUint(decoder)
    const numberOfDeletes = decoding.readVarUint(decoder)
    for (let i = 0; i < numberOfDeletes; i++) {
      addToDeleteSet(ds, createID(client, decoding.readVarUint(decoder)), decoding.readVarUint(decoder))
    }
  }
  return ds
}
github yjs / yjs / src / utils / integrateRemoteStructs.js View on Github external
export const integrateRemoteStructs = (decoder, y) => {
  const len = decoding.readUint32(decoder)
  for (let i = 0; i < len; i++) {
    let reference = decoding.readVarUint(decoder)
    let Constr = getStruct(reference)
    let struct = new Constr()
    let decoderPos = decoder.pos
    let missing = struct._fromBinary(y, decoder)
    if (missing.length === 0) {
      while (struct !== null) {
        _integrateRemoteStructHelper(y, struct)
        struct = null
        if (y._readyToIntegrate.length > 0) {
          const missingDef = y._readyToIntegrate.shift()
          const decoder = missingDef.decoder
          let oldPos = decoder.pos
          let missing = missingDef.struct._fromBinary(y, decoder)
          decoder.pos = oldPos
          if (missing.length === 0) {
            struct = missingDef.struct
github yjs / yjs / src / utils / DeleteSet.js View on Github external
export const readDeleteSet = decoder => {
  const ds = new DeleteSet()
  const numClients = decoding.readVarUint(decoder)
  for (let i = 0; i < numClients; i++) {
    const client = decoding.readVarUint(decoder)
    const numberOfDeletes = decoding.readVarUint(decoder)
    for (let i = 0; i < numberOfDeletes; i++) {
      addToDeleteSet(ds, createID(client, decoding.readVarUint(decoder)), decoding.readVarUint(decoder))
    }
  }
  return ds
}
github yjs / yjs / src / utils / encoding.js View on Github external
export const readStateVector = decoder => {
  const ss = new Map()
  const ssLength = decoding.readVarUint(decoder)
  for (let i = 0; i < ssLength; i++) {
    const client = decoding.readVarUint(decoder)
    const clock = decoding.readVarUint(decoder)
    ss.set(client, clock)
  }
  return ss
}
github yjs / yjs / src / utils / DeleteSet.js View on Github external
export const readDeleteSet = decoder => {
  const ds = new DeleteSet()
  const numClients = decoding.readVarUint(decoder)
  for (let i = 0; i < numClients; i++) {
    const client = decoding.readVarUint(decoder)
    const numberOfDeletes = decoding.readVarUint(decoder)
    for (let i = 0; i < numberOfDeletes; i++) {
      addToDeleteSet(ds, createID(client, decoding.readVarUint(decoder)), decoding.readVarUint(decoder))
    }
  }
  return ds
}
github yjs / y-webrtc / src / y-webrtc.js View on Github external
const readMessage = (room, buf, syncedCallback) => {
  const decoder = decoding.createDecoder(buf)
  const encoder = encoding.createEncoder()
  const messageType = decoding.readVarUint(decoder)
  if (room === undefined) {
    return null
  }
  const awareness = room.awareness
  const doc = room.doc
  let sendReply = false
  switch (messageType) {
    case messageSync:
      encoding.writeVarUint(encoder, messageSync)
      const syncMessageType = syncProtocol.readSyncMessage(decoder, encoder, doc, room)
      if (syncMessageType === syncProtocol.messageYjsSyncStep2 && !room.synced) {
        syncedCallback()
      }
      if (syncMessageType === syncProtocol.messageYjsSyncStep1) {
        sendReply = true
      }
github yjs / yjs / src / utils / encoding.js View on Github external
export const readClientsStructRefs = decoder => {
  /**
   * @type {Map>}
   */
  const clientRefs = new Map()
  const numOfStateUpdates = decoding.readVarUint(decoder)
  for (let i = 0; i < numOfStateUpdates; i++) {
    const numberOfStructs = decoding.readVarUint(decoder)
    const nextID = readID(decoder)
    const refs = readStructRefs(decoder, numberOfStructs, nextID)
    clientRefs.set(nextID.client, refs)
  }
  return clientRefs
}
github yjs / yjs / src / utils / encoding.js View on Github external
export const readClientsStructRefs = decoder => {
  /**
   * @type {Map>}
   */
  const clientRefs = new Map()
  const numOfStateUpdates = decoding.readVarUint(decoder)
  for (let i = 0; i < numOfStateUpdates; i++) {
    const numberOfStructs = decoding.readVarUint(decoder)
    const nextID = readID(decoder)
    const refs = readStructRefs(decoder, numberOfStructs, nextID)
    clientRefs.set(nextID.client, refs)
  }
  return clientRefs
}
github yjs / yjs / src / structs / ContentJSON.js View on Github external
export const readContentJSON = decoder => {
  const len = decoding.readVarUint(decoder)
  const cs = []
  for (let i = 0; i < len; i++) {
    const c = decoding.readVarString(decoder)
    if (c === 'undefined') {
      cs.push(undefined)
    } else {
      cs.push(JSON.parse(c))
    }
  }
  return new ContentJSON(cs)
}