How to use the libp2p-record.Record.deserialize function in libp2p-record

To help you get started, we’ve selected a few libp2p-record 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 ipfs / js-datastore-pubsub / test / index.spec.js View on Github external
// not locally stored record
        expect(err.code).to.equal('ERR_NOT_FOUND')
      })

    await waitForPeerToSubscribe(subsTopic, peerIdB, pubsubA)

    // subscribe in order to understand when the message arrive to the node
    await pubsubB.subscribe(subsTopic, messageHandler)
    await dsPubsubA.put(key, serializedRecord)

    // wait until message arrives
    await waitFor(() => receivedMessage === true)

    // get from datastore
    const result = await dsPubsubB.get(keyNew)
    const receivedRecord = Record.deserialize(result)

    expect(receivedRecord.value.toString()).to.equal(value)
  })
github ipfs / js-datastore-pubsub / test / index.spec.js View on Github external
validate: (data) => {
        const receivedRecord = Record.deserialize(data)

        expect(receivedRecord.value.toString()).to.equal(value) // validator should deserialize correctly

        return receivedRecord.value.toString() === value
      },
      select: () => {
github ipfs / js-ipfs / src / core / ipns / routing / offline-datastore.js View on Github external
let routingKey

    try {
      routingKey = this._routingKey(key)
    } catch (err) {
      log.error(err)
      throw errcode(new Error('Not possible to generate the routing key'), 'ERR_GENERATING_ROUTING_KEY')
    }

    const res = await this._repo.datastore.get(routingKey)

    // Unmarshal libp2p record as the DHT does
    let record
    try {
      record = Record.deserialize(res)
    } catch (err) {
      log.error(err)
      throw (err)
    }

    return record.value
  }

libp2p-record

libp2p record implementation

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis