git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 4764e106f64da9641c4d72e1e6974d46024fbab3

Merge pull request #5 from dfinity/small-fixes

Small fixes
wanderer authored on 3/11/2018, 11:37:09 PM
GitHub committed on 3/11/2018, 11:37:09 PM
Parent: cbaa5108c37a1044ce3682079c2e0dd7cb939698
Parent: 762d1ed4087ea8ec034bd4a95090557cc577197e

Files changed

systemObjects.jschanged
systemObjects.jsView
@@ -1,9 +1,9 @@
11 const cbor = require('borc')
22
33 const TAGS = {
4+ id: 41,
45 link: 42,
5- id: 43,
66 func: 43,
77 mod: 44
88 }
99
@@ -15,12 +15,35 @@
1515 link: {'/': null},
1616 func: new cbor.Tagged(TAGS.func, 0)
1717 }
1818
19-class FunctionRef {
19+const decoder = new cbor.Decoder({
20+ tags: {
21+ [TAGS.id]: val => new ID(val),
22+ [TAGS.func]: val => new FunctionRef(...val),
23+ [TAGS.mod]: val => new ModuleRef(...val),
24+ }
25+})
26+
27+class Serializable {
28+ serialize () {
29+ const encoder = new cbor.Encoder()
30+ this.encodeCBOR(encoder)
31+ return encoder.finalize()
32+ }
33+
34+ static deserialize (serialized) {
35+ return decoder.decodeFirst(serialized)
36+ }
37+}
38+
39+class FunctionRef extends Serializable {
2040 constructor (privateFunc, identifier, params, id, gas=0) {
41+ super()
2142 this.private = privateFunc
2243 this.identifier = identifier
44+ if (!(id instanceof ID))
45+ id = new ID(id)
2346 this.destId = id
2447 this.params = params
2548 this.gas = gas
2649 }
@@ -28,20 +51,21 @@
2851 encodeCBOR (gen) {
2952 return gen.write(new cbor.Tagged(TAGS.func, [
3053 this.private,
3154 this.identifier,
32- this.destId,
33- this.params
55+ this.params,
56+ this.destId
3457 ]))
3558 }
3659
3760 set container (container) {
3861 this._container = container
3962 }
4063 }
4164
42-class ModuleRef {
65+class ModuleRef extends Serializable {
4366 constructor (ex, id) {
67+ super()
4468 this.exports = ex
4569 this.id = id
4670 }
4771
@@ -60,19 +84,18 @@
6084 exports[ex] = type
6185 }
6286 return new ModuleRef(exports, id)
6387 }
64-
65- static deserialize (serialized) {}
6688 }
6789
68-class ID {
90+class ID extends Serializable {
6991 constructor (id) {
92+ super()
7093 this.id = id
7194 }
7295
7396 encodeCBOR (gen) {
74- return gen.write(cbor.Tagged(TAGS.id, this.id))
97+ return gen.write(new cbor.Tagged(TAGS.id, this.id))
7598 }
7699 }
77100
78101 module.exports = {

Built with git-ssb-web