git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit f7af9769dc163a3efc6196f8cc06ab9115567a9f

change type -> varint

wanderer committed on 12/5/2017, 5:53:34 PM
Parent: 86f9d39232c23d80576543898b260fdb486becd1

Files changed

actor.jschanged
index.jschanged
actor.jsView
@@ -14,9 +14,8 @@
1414 * @param {Object} opts.hypervisor - the instance of the hypervisor
1515 * @param {Object} opts.container - the container constuctor and argments
1616 */
1717 constructor (opts) {
18- // console.log(opts.state)
1918 this.state = opts.state
2019 this.nonce = leb128.decode(opts.state.root['/'][3].subarray(2))
2120 this.hypervisor = opts.hypervisor
2221 this.id = opts.id
index.jsView
@@ -1,6 +1,7 @@
11 const Actor = require('./actor.js')
22 const Scheduler = require('./scheduler.js')
3+const leb128 = require('leb128').unsigned
34
45 module.exports = class Hypervisor {
56 /**
67 * The Hypervisor manages the container instances by instantiating them and
@@ -28,9 +29,10 @@
2829
2930 // loads an instance of a container from the state
3031 async _loadActor (id) {
3132 const state = await this.tree.getSubTree(id)
32- const container = this._containerTypes[state.root['/'][3][0]]
33+ const type = leb128.decode(state.root['/'][3])
34+ const container = this._containerTypes[type]
3335
3436 // create a new actor instance
3537 const actor = new Actor({
3638 hypervisor: this,
@@ -70,9 +72,9 @@
7072 */
7173 async createActor (type, message, id = {nonce: this.nonce++, parent: null}) {
7274 const encoded = encodedID(id)
7375 const idHash = await this._getHashFromObj(encoded)
74- const state = Buffer.from([type, 0, 0])
76+ const state = Buffer.concat([leb128.encode(type), Buffer.from([0, 0])])
7577
7678 // save the container in the state
7779 this.tree.set(idHash, state)
7880

Built with git-ssb-web