How to use the lib0/decoding.js.readVarString 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 / relativePosition.js View on Github external
export const readRelativePosition = (decoder, y, store) => {
  let type = null
  let tname = null
  let itemID = null
  switch (decoding.readVarUint(decoder)) {
    case 0:
      // case 1: found position somewhere in the linked list
      itemID = ID.readID(decoder)
      break
    case 1:
      // case 2: found position at the end of the list and type is stored in y.share
      tname = decoding.readVarString(decoder)
      break
    case 2: {
      // case 3: found position at the end of the list and type is attached to an item
      type = ID.readID(decoder)
    }
  }
  return new RelativePosition(type, tname, itemID)
}
github yjs / yjs / src / utils / RelativePosition.js View on Github external
export const readRelativePosition = decoder => {
  let type = null
  let tname = null
  let itemID = null
  switch (decoding.readVarUint(decoder)) {
    case 0:
      // case 1: found position somewhere in the linked list
      itemID = readID(decoder)
      break
    case 1:
      // case 2: found position at the end of the list and type is stored in y.share
      tname = decoding.readVarString(decoder)
      break
    case 2: {
      // case 3: found position at the end of the list and type is attached to an item
      type = readID(decoder)
    }
  }
  return new RelativePosition(type, tname, itemID)
}
github yjs / yjs / src / structs / Item.js View on Github external
if (parent === null) {
          missing.push(parentID)
        } else {
          this._parent = parent
        }
      }
    } else if (this._parent === null) {
      if (this._origin !== null) {
        this._parent = this._origin._parent
      } else if (this._right_origin !== null) {
        this._parent = this._right_origin._parent
      }
    }
    if (info & 0b1000) {
      // TODO: maybe put this in read parent condition (you can also read parentsub from left/right)
      this._parentSub = JSON.parse(decoding.readVarString(decoder))
    }
    if (id instanceof ID.ID && y.ss.getState(id.user) < id.clock) {
      missing.push(ID.createID(id.user, id.clock - 1))
    }
    return missing
  }
}
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)
}
github yjs / yjs / src / structs / ItemFormat.js View on Github external
constructor (decoder, id, info) {
    super(decoder, id, info)
    /**
     * @type {string}
     */
    this.key = decoding.readVarString(decoder)
    this.value = JSON.parse(decoding.readVarString(decoder))
  }
  /**
github yjs / yjs / src / types / YXmlHook.js View on Github external
export const readYXmlHook = decoder =>
  new YXmlHook(decoding.readVarString(decoder))
github yjs / yjs / src / structs / ItemEmbed.js View on Github external
constructor (decoder, id, info) {
    super(decoder, id, info)
    /**
     * @type {Object}
     */
    this.embed = JSON.parse(decoding.readVarString(decoder))
  }
  /**
github yjs / yjs / src / structs / ItemString.js View on Github external
constructor (decoder, id, info) {
    super(decoder, id, info)
    /**
     * @type {string}
     */
    this.string = decoding.readVarString(decoder)
  }
  get length () {
github yjs / yjs / src / types / YXmlElement.js View on Github external
export const readYXmlElement = decoder => new YXmlElement(decoding.readVarString(decoder))
github yjs / yjs / src / structs / ItemFormat.js View on Github external
constructor (decoder, id, info) {
    super(decoder, id, info)
    /**
     * @type {string}
     */
    this.key = decoding.readVarString(decoder)
    this.value = JSON.parse(decoding.readVarString(decoder))
  }
  /**