How to use the lib0/decoding.js.readUint8 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 / structs / Item.js View on Github external
_fromBinary (y, decoder) {
    let missing = []
    const info = decoding.readUint8(decoder)
    const id = ID.decode(decoder)
    this._id = id
    // read origin
    if (info & 0b1) {
      // origin != null
      const originID = ID.decode(decoder)
      // we have to query for left again because it might have been split/merged..
      const origin = y.os.getItemCleanEnd(originID)
      if (origin === null) {
        missing.push(originID)
      } else {
        this._origin = origin
        this._left = this._origin
      }
    }
    // read right
github yjs / y-webrtc / src / y-webrtc.js View on Github external
syncedCallback()
      }
      if (syncMessageType === syncProtocol.messageYjsSyncStep1) {
        sendReply = true
      }
      break
    case messageQueryAwareness:
      encoding.writeVarUint(encoder, messageAwareness)
      encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(awareness, Array.from(awareness.getStates().keys())))
      sendReply = true
      break
    case messageAwareness:
      awarenessProtocol.applyAwarenessUpdate(awareness, decoding.readVarUint8Array(decoder), room)
      break
    case messageBcPeerId: {
      const add = decoding.readUint8(decoder) === 1
      const peerName = decoding.readVarString(decoder)
      if (peerName !== room.peerId && ((room.bcConns.has(peerName) && !add) || (!room.bcConns.has(peerName) && add))) {
        const removed = []
        const added = []
        if (add) {
          room.bcConns.add(peerName)
          added.push(peerName)
        } else {
          room.bcConns.delete(peerName)
          removed.push(peerName)
        }
        room.provider.emit('peers', [{
          added,
          removed,
          webrtcPeers: Array.from(room.webrtcConns.keys()),
          bcPeers: Array.from(room.bcConns)
github yjs / yjs / src / utils / encoding.js View on Github external
const readStructRefs = (decoder, numOfStructs, nextID) => {
  /**
   * @type {Array}
   */
  const refs = []
  for (let i = 0; i < numOfStructs; i++) {
    const info = decoding.readUint8(decoder)
    const ref = (binary.BITS5 & info) === 0 ? new GCRef(decoder, nextID, info) : new ItemRef(decoder, nextID, info)
    nextID = createID(nextID.client, nextID.clock + ref.length)
    refs.push(ref)
  }
  return refs
}