jacobrosenthal closed pull request #120: gopherjs test
URL: https://github.com/apache/mynewt-newt/pull/120
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/newtmgr/main.go b/newtmgr/main.go
new file mode 100644
index 00000000..1acfacbd
--- /dev/null
+++ b/newtmgr/main.go
@@ -0,0 +1,18 @@
+package main
+
+import(
+ "mynewt.apache.org/newt/newtmgr/protocol"
+ "github.com/gopherjs/gopherjs/js"
+ )
+
+func main() {
+ js.Global.Set("reset", map[string]interface{}{
+ "New": New,
+ })
+}
+
+
+
+func New() *js.Object {
+ return js.MakeWrapper(&protocol.Reset{})
+}
diff --git a/newtmgr/main.js b/newtmgr/main.js
new file mode 100644
index 00000000..dcdf9ce3
--- /dev/null
+++ b/newtmgr/main.js
@@ -0,0 +1,2466 @@
+"use strict";
+(function() {
+
+Error.stackTraceLimit = Infinity;
+
+var $global, $module;
+if (typeof window !== "undefined") { /* web page */
+ $global = window;
+} else if (typeof self !== "undefined") { /* web worker */
+ $global = self;
+} else if (typeof global !== "undefined") { /* Node.js */
+ $global = global;
+ $global.require = require;
+} else { /* others (e.g. Nashorn) */
+ $global = this;
+}
+
+if ($global === undefined || $global.Array === undefined) {
+ throw new Error("no global object found");
+}
+if (typeof module !== "undefined") {
+ $module = module;
+}
+
+var $packages = {}, $idCounter = 0;
+var $keys = function(m) { return m ? Object.keys(m) : []; };
+var $flushConsole = function() {};
+var $throwRuntimeError; /* set by package "runtime" */
+var $throwNilPointerError = function() { $throwRuntimeError("invalid memory
address or nil pointer dereference"); };
+var $call = function(fn, rcvr, args) { return fn.apply(rcvr, args); };
+var $makeFunc = function(fn) { return function() { return
$externalize(fn(this, new
($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments, []))),
$emptyInterface); }; };
+var $unused = function(v) {};
+
+var $mapArray = function(array, f) {
+ var newArray = new array.constructor(array.length);
+ for (var i = 0; i < array.length; i++) {
+ newArray[i] = f(array[i]);
+ }
+ return newArray;
+};
+
+var $methodVal = function(recv, name) {
+ var vals = recv.$methodVals || {};
+ recv.$methodVals = vals; /* noop for primitives */
+ var f = vals[name];
+ if (f !== undefined) {
+ return f;
+ }
+ var method = recv[name];
+ f = function() {
+ $stackDepthOffset--;
+ try {
+ return method.apply(recv, arguments);
+ } finally {
+ $stackDepthOffset++;
+ }
+ };
+ vals[name] = f;
+ return f;
+};
+
+var $methodExpr = function(typ, name) {
+ var method = typ.prototype[name];
+ if (method.$expr === undefined) {
+ method.$expr = function() {
+ $stackDepthOffset--;
+ try {
+ if (typ.wrapped) {
+ arguments[0] = new typ(arguments[0]);
+ }
+ return Function.call.apply(method, arguments);
+ } finally {
+ $stackDepthOffset++;
+ }
+ };
+ }
+ return method.$expr;
+};
+
+var $ifaceMethodExprs = {};
+var $ifaceMethodExpr = function(name) {
+ var expr = $ifaceMethodExprs["$" + name];
+ if (expr === undefined) {
+ expr = $ifaceMethodExprs["$" + name] = function() {
+ $stackDepthOffset--;
+ try {
+ return Function.call.apply(arguments[0][name], arguments);
+ } finally {
+ $stackDepthOffset++;
+ }
+ };
+ }
+ return expr;
+};
+
+var $subslice = function(slice, low, high, max) {
+ if (low < 0 || high < low || max < high || high > slice.$capacity || max >
slice.$capacity) {
+ $throwRuntimeError("slice bounds out of range");
+ }
+ var s = new slice.constructor(slice.$array);
+ s.$offset = slice.$offset + low;
+ s.$length = slice.$length - low;
+ s.$capacity = slice.$capacity - low;
+ if (high !== undefined) {
+ s.$length = high - low;
+ }
+ if (max !== undefined) {
+ s.$capacity = max - low;
+ }
+ return s;
+};
+
+var $substring = function(str, low, high) {
+ if (low < 0 || high < low || high > str.length) {
+ $throwRuntimeError("slice bounds out of range");
+ }
+ return str.substring(low, high);
+};
+
+var $sliceToArray = function(slice) {
+ if (slice.$array.constructor !== Array) {
+ return slice.$array.subarray(slice.$offset, slice.$offset + slice.$length);
+ }
+ return slice.$array.slice(slice.$offset, slice.$offset + slice.$length);
+};
+
+var $decodeRune = function(str, pos) {
+ var c0 = str.charCodeAt(pos);
+
+ if (c0 < 0x80) {
+ return [c0, 1];
+ }
+
+ if (c0 !== c0 || c0 < 0xC0) {
+ return [0xFFFD, 1];
+ }
+
+ var c1 = str.charCodeAt(pos + 1);
+ if (c1 !== c1 || c1 < 0x80 || 0xC0 <= c1) {
+ return [0xFFFD, 1];
+ }
+
+ if (c0 < 0xE0) {
+ var r = (c0 & 0x1F) << 6 | (c1 & 0x3F);
+ if (r <= 0x7F) {
+ return [0xFFFD, 1];
+ }
+ return [r, 2];
+ }
+
+ var c2 = str.charCodeAt(pos + 2);
+ if (c2 !== c2 || c2 < 0x80 || 0xC0 <= c2) {
+ return [0xFFFD, 1];
+ }
+
+ if (c0 < 0xF0) {
+ var r = (c0 & 0x0F) << 12 | (c1 & 0x3F) << 6 | (c2 & 0x3F);
+ if (r <= 0x7FF) {
+ return [0xFFFD, 1];
+ }
+ if (0xD800 <= r && r <= 0xDFFF) {
+ return [0xFFFD, 1];
+ }
+ return [r, 3];
+ }
+
+ var c3 = str.charCodeAt(pos + 3);
+ if (c3 !== c3 || c3 < 0x80 || 0xC0 <= c3) {
+ return [0xFFFD, 1];
+ }
+
+ if (c0 < 0xF8) {
+ var r = (c0 & 0x07) << 18 | (c1 & 0x3F) << 12 | (c2 & 0x3F) << 6 | (c3 &
0x3F);
+ if (r <= 0xFFFF || 0x10FFFF < r) {
+ return [0xFFFD, 1];
+ }
+ return [r, 4];
+ }
+
+ return [0xFFFD, 1];
+};
+
+var $encodeRune = function(r) {
+ if (r < 0 || r > 0x10FFFF || (0xD800 <= r && r <= 0xDFFF)) {
+ r = 0xFFFD;
+ }
+ if (r <= 0x7F) {
+ return String.fromCharCode(r);
+ }
+ if (r <= 0x7FF) {
+ return String.fromCharCode(0xC0 | r >> 6, 0x80 | (r & 0x3F));
+ }
+ if (r <= 0xFFFF) {
+ return String.fromCharCode(0xE0 | r >> 12, 0x80 | (r >> 6 & 0x3F), 0x80 |
(r & 0x3F));
+ }
+ return String.fromCharCode(0xF0 | r >> 18, 0x80 | (r >> 12 & 0x3F), 0x80 |
(r >> 6 & 0x3F), 0x80 | (r & 0x3F));
+};
+
+var $stringToBytes = function(str) {
+ var array = new Uint8Array(str.length);
+ for (var i = 0; i < str.length; i++) {
+ array[i] = str.charCodeAt(i);
+ }
+ return array;
+};
+
+var $bytesToString = function(slice) {
+ if (slice.$length === 0) {
+ return "";
+ }
+ var str = "";
+ for (var i = 0; i < slice.$length; i += 10000) {
+ str += String.fromCharCode.apply(undefined,
slice.$array.subarray(slice.$offset + i, slice.$offset +
Math.min(slice.$length, i + 10000)));
+ }
+ return str;
+};
+
+var $stringToRunes = function(str) {
+ var array = new Int32Array(str.length);
+ var rune, j = 0;
+ for (var i = 0; i < str.length; i += rune[1], j++) {
+ rune = $decodeRune(str, i);
+ array[j] = rune[0];
+ }
+ return array.subarray(0, j);
+};
+
+var $runesToString = function(slice) {
+ if (slice.$length === 0) {
+ return "";
+ }
+ var str = "";
+ for (var i = 0; i < slice.$length; i++) {
+ str += $encodeRune(slice.$array[slice.$offset + i]);
+ }
+ return str;
+};
+
+var $copyString = function(dst, src) {
+ var n = Math.min(src.length, dst.$length);
+ for (var i = 0; i < n; i++) {
+ dst.$array[dst.$offset + i] = src.charCodeAt(i);
+ }
+ return n;
+};
+
+var $copySlice = function(dst, src) {
+ var n = Math.min(src.$length, dst.$length);
+ $copyArray(dst.$array, src.$array, dst.$offset, src.$offset, n,
dst.constructor.elem);
+ return n;
+};
+
+var $copyArray = function(dst, src, dstOffset, srcOffset, n, elem) {
+ if (n === 0 || (dst === src && dstOffset === srcOffset)) {
+ return;
+ }
+
+ if (src.subarray) {
+ dst.set(src.subarray(srcOffset, srcOffset + n), dstOffset);
+ return;
+ }
+
+ switch (elem.kind) {
+ case $kindArray:
+ case $kindStruct:
+ if (dst === src && dstOffset > srcOffset) {
+ for (var i = n - 1; i >= 0; i--) {
+ elem.copy(dst[dstOffset + i], src[srcOffset + i]);
+ }
+ return;
+ }
+ for (var i = 0; i < n; i++) {
+ elem.copy(dst[dstOffset + i], src[srcOffset + i]);
+ }
+ return;
+ }
+
+ if (dst === src && dstOffset > srcOffset) {
+ for (var i = n - 1; i >= 0; i--) {
+ dst[dstOffset + i] = src[srcOffset + i];
+ }
+ return;
+ }
+ for (var i = 0; i < n; i++) {
+ dst[dstOffset + i] = src[srcOffset + i];
+ }
+};
+
+var $clone = function(src, type) {
+ var clone = type.zero();
+ type.copy(clone, src);
+ return clone;
+};
+
+var $pointerOfStructConversion = function(obj, type) {
+ if(obj.$proxies === undefined) {
+ obj.$proxies = {};
+ obj.$proxies[obj.constructor.string] = obj;
+ }
+ var proxy = obj.$proxies[type.string];
+ if (proxy === undefined) {
+ var properties = {};
+ for (var i = 0; i < type.elem.fields.length; i++) {
+ (function(fieldProp) {
+ properties[fieldProp] = {
+ get: function() { return obj[fieldProp]; },
+ set: function(value) { obj[fieldProp] = value; }
+ };
+ })(type.elem.fields[i].prop);
+ }
+ proxy = Object.create(type.prototype, properties);
+ proxy.$val = proxy;
+ obj.$proxies[type.string] = proxy;
+ proxy.$proxies = obj.$proxies;
+ }
+ return proxy;
+};
+
+var $append = function(slice) {
+ return $internalAppend(slice, arguments, 1, arguments.length - 1);
+};
+
+var $appendSlice = function(slice, toAppend) {
+ if (toAppend.constructor === String) {
+ var bytes = $stringToBytes(toAppend);
+ return $internalAppend(slice, bytes, 0, bytes.length);
+ }
+ return $internalAppend(slice, toAppend.$array, toAppend.$offset,
toAppend.$length);
+};
+
+var $internalAppend = function(slice, array, offset, length) {
+ if (length === 0) {
+ return slice;
+ }
+
+ var newArray = slice.$array;
+ var newOffset = slice.$offset;
+ var newLength = slice.$length + length;
+ var newCapacity = slice.$capacity;
+
+ if (newLength > newCapacity) {
+ newOffset = 0;
+ newCapacity = Math.max(newLength, slice.$capacity < 1024 ? slice.$capacity
* 2 : Math.floor(slice.$capacity * 5 / 4));
+
+ if (slice.$array.constructor === Array) {
+ newArray = slice.$array.slice(slice.$offset, slice.$offset +
slice.$length);
+ newArray.length = newCapacity;
+ var zero = slice.constructor.elem.zero;
+ for (var i = slice.$length; i < newCapacity; i++) {
+ newArray[i] = zero();
+ }
+ } else {
+ newArray = new slice.$array.constructor(newCapacity);
+ newArray.set(slice.$array.subarray(slice.$offset, slice.$offset +
slice.$length));
+ }
+ }
+
+ $copyArray(newArray, array, newOffset + slice.$length, offset, length,
slice.constructor.elem);
+
+ var newSlice = new slice.constructor(newArray);
+ newSlice.$offset = newOffset;
+ newSlice.$length = newLength;
+ newSlice.$capacity = newCapacity;
+ return newSlice;
+};
+
+var $equal = function(a, b, type) {
+ if (type === $jsObjectPtr) {
+ return a === b;
+ }
+ switch (type.kind) {
+ case $kindComplex64:
+ case $kindComplex128:
+ return a.$real === b.$real && a.$imag === b.$imag;
+ case $kindInt64:
+ case $kindUint64:
+ return a.$high === b.$high && a.$low === b.$low;
+ case $kindArray:
+ if (a.length !== b.length) {
+ return false;
+ }
+ for (var i = 0; i < a.length; i++) {
+ if (!$equal(a[i], b[i], type.elem)) {
+ return false;
+ }
+ }
+ return true;
+ case $kindStruct:
+ for (var i = 0; i < type.fields.length; i++) {
+ var f = type.fields[i];
+ if (!$equal(a[f.prop], b[f.prop], f.typ)) {
+ return false;
+ }
+ }
+ return true;
+ case $kindInterface:
+ return $interfaceIsEqual(a, b);
+ default:
+ return a === b;
+ }
+};
+
+var $interfaceIsEqual = function(a, b) {
+ if (a === $ifaceNil || b === $ifaceNil) {
+ return a === b;
+ }
+ if (a.constructor !== b.constructor) {
+ return false;
+ }
+ if (a.constructor === $jsObjectPtr) {
+ return a.object === b.object;
+ }
+ if (!a.constructor.comparable) {
+ $throwRuntimeError("comparing uncomparable type " + a.constructor.string);
+ }
+ return $equal(a.$val, b.$val, a.constructor);
+};
+
+var $min = Math.min;
+var $mod = function(x, y) { return x % y; };
+var $parseInt = parseInt;
+var $parseFloat = function(f) {
+ if (f !== undefined && f !== null && f.constructor === Number) {
+ return f;
+ }
+ return parseFloat(f);
+};
+
+var $froundBuf = new Float32Array(1);
+var $fround = Math.fround || function(f) {
+ $froundBuf[0] = f;
+ return $froundBuf[0];
+};
+
+var $imul = Math.imul || function(a, b) {
+ var ah = (a >>> 16) & 0xffff;
+ var al = a & 0xffff;
+ var bh = (b >>> 16) & 0xffff;
+ var bl = b & 0xffff;
+ return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) >> 0);
+};
+
+var $floatKey = function(f) {
+ if (f !== f) {
+ $idCounter++;
+ return "NaN$" + $idCounter;
+ }
+ return String(f);
+};
+
+var $flatten64 = function(x) {
+ return x.$high * 4294967296 + x.$low;
+};
+
+var $shiftLeft64 = function(x, y) {
+ if (y === 0) {
+ return x;
+ }
+ if (y < 32) {
+ return new x.constructor(x.$high << y | x.$low >>> (32 - y), (x.$low << y)
>>> 0);
+ }
+ if (y < 64) {
+ return new x.constructor(x.$low << (y - 32), 0);
+ }
+ return new x.constructor(0, 0);
+};
+
+var $shiftRightInt64 = function(x, y) {
+ if (y === 0) {
+ return x;
+ }
+ if (y < 32) {
+ return new x.constructor(x.$high >> y, (x.$low >>> y | x.$high << (32 -
y)) >>> 0);
+ }
+ if (y < 64) {
+ return new x.constructor(x.$high >> 31, (x.$high >> (y - 32)) >>> 0);
+ }
+ if (x.$high < 0) {
+ return new x.constructor(-1, 4294967295);
+ }
+ return new x.constructor(0, 0);
+};
+
+var $shiftRightUint64 = function(x, y) {
+ if (y === 0) {
+ return x;
+ }
+ if (y < 32) {
+ return new x.constructor(x.$high >>> y, (x.$low >>> y | x.$high << (32 -
y)) >>> 0);
+ }
+ if (y < 64) {
+ return new x.constructor(0, x.$high >>> (y - 32));
+ }
+ return new x.constructor(0, 0);
+};
+
+var $mul64 = function(x, y) {
+ var high = 0, low = 0;
+ if ((y.$low & 1) !== 0) {
+ high = x.$high;
+ low = x.$low;
+ }
+ for (var i = 1; i < 32; i++) {
+ if ((y.$low & 1<<i) !== 0) {
+ high += x.$high << i | x.$low >>> (32 - i);
+ low += (x.$low << i) >>> 0;
+ }
+ }
+ for (var i = 0; i < 32; i++) {
+ if ((y.$high & 1<<i) !== 0) {
+ high += x.$low << i;
+ }
+ }
+ return new x.constructor(high, low);
+};
+
+var $div64 = function(x, y, returnRemainder) {
+ if (y.$high === 0 && y.$low === 0) {
+ $throwRuntimeError("integer divide by zero");
+ }
+
+ var s = 1;
+ var rs = 1;
+
+ var xHigh = x.$high;
+ var xLow = x.$low;
+ if (xHigh < 0) {
+ s = -1;
+ rs = -1;
+ xHigh = -xHigh;
+ if (xLow !== 0) {
+ xHigh--;
+ xLow = 4294967296 - xLow;
+ }
+ }
+
+ var yHigh = y.$high;
+ var yLow = y.$low;
+ if (y.$high < 0) {
+ s *= -1;
+ yHigh = -yHigh;
+ if (yLow !== 0) {
+ yHigh--;
+ yLow = 4294967296 - yLow;
+ }
+ }
+
+ var high = 0, low = 0, n = 0;
+ while (yHigh < 2147483648 && ((xHigh > yHigh) || (xHigh === yHigh && xLow >
yLow))) {
+ yHigh = (yHigh << 1 | yLow >>> 31) >>> 0;
+ yLow = (yLow << 1) >>> 0;
+ n++;
+ }
+ for (var i = 0; i <= n; i++) {
+ high = high << 1 | low >>> 31;
+ low = (low << 1) >>> 0;
+ if ((xHigh > yHigh) || (xHigh === yHigh && xLow >= yLow)) {
+ xHigh = xHigh - yHigh;
+ xLow = xLow - yLow;
+ if (xLow < 0) {
+ xHigh--;
+ xLow += 4294967296;
+ }
+ low++;
+ if (low === 4294967296) {
+ high++;
+ low = 0;
+ }
+ }
+ yLow = (yLow >>> 1 | yHigh << (32 - 1)) >>> 0;
+ yHigh = yHigh >>> 1;
+ }
+
+ if (returnRemainder) {
+ return new x.constructor(xHigh * rs, xLow * rs);
+ }
+ return new x.constructor(high * s, low * s);
+};
+
+var $divComplex = function(n, d) {
+ var ninf = n.$real === Infinity || n.$real === -Infinity || n.$imag ===
Infinity || n.$imag === -Infinity;
+ var dinf = d.$real === Infinity || d.$real === -Infinity || d.$imag ===
Infinity || d.$imag === -Infinity;
+ var nnan = !ninf && (n.$real !== n.$real || n.$imag !== n.$imag);
+ var dnan = !dinf && (d.$real !== d.$real || d.$imag !== d.$imag);
+ if(nnan || dnan) {
+ return new n.constructor(NaN, NaN);
+ }
+ if (ninf && !dinf) {
+ return new n.constructor(Infinity, Infinity);
+ }
+ if (!ninf && dinf) {
+ return new n.constructor(0, 0);
+ }
+ if (d.$real === 0 && d.$imag === 0) {
+ if (n.$real === 0 && n.$imag === 0) {
+ return new n.constructor(NaN, NaN);
+ }
+ return new n.constructor(Infinity, Infinity);
+ }
+ var a = Math.abs(d.$real);
+ var b = Math.abs(d.$imag);
+ if (a <= b) {
+ var ratio = d.$real / d.$imag;
+ var denom = d.$real * ratio + d.$imag;
+ return new n.constructor((n.$real * ratio + n.$imag) / denom, (n.$imag *
ratio - n.$real) / denom);
+ }
+ var ratio = d.$imag / d.$real;
+ var denom = d.$imag * ratio + d.$real;
+ return new n.constructor((n.$imag * ratio + n.$real) / denom, (n.$imag -
n.$real * ratio) / denom);
+};
+
+var $kindBool = 1;
+var $kindInt = 2;
+var $kindInt8 = 3;
+var $kindInt16 = 4;
+var $kindInt32 = 5;
+var $kindInt64 = 6;
+var $kindUint = 7;
+var $kindUint8 = 8;
+var $kindUint16 = 9;
+var $kindUint32 = 10;
+var $kindUint64 = 11;
+var $kindUintptr = 12;
+var $kindFloat32 = 13;
+var $kindFloat64 = 14;
+var $kindComplex64 = 15;
+var $kindComplex128 = 16;
+var $kindArray = 17;
+var $kindChan = 18;
+var $kindFunc = 19;
+var $kindInterface = 20;
+var $kindMap = 21;
+var $kindPtr = 22;
+var $kindSlice = 23;
+var $kindString = 24;
+var $kindStruct = 25;
+var $kindUnsafePointer = 26;
+
+var $methodSynthesizers = [];
+var $addMethodSynthesizer = function(f) {
+ if ($methodSynthesizers === null) {
+ f();
+ return;
+ }
+ $methodSynthesizers.push(f);
+};
+var $synthesizeMethods = function() {
+ $methodSynthesizers.forEach(function(f) { f(); });
+ $methodSynthesizers = null;
+};
+
+var $ifaceKeyFor = function(x) {
+ if (x === $ifaceNil) {
+ return 'nil';
+ }
+ var c = x.constructor;
+ return c.string + '$' + c.keyFor(x.$val);
+};
+
+var $identity = function(x) { return x; };
+
+var $typeIDCounter = 0;
+
+var $idKey = function(x) {
+ if (x.$id === undefined) {
+ $idCounter++;
+ x.$id = $idCounter;
+ }
+ return String(x.$id);
+};
+
+var $newType = function(size, kind, string, named, pkg, exported, constructor)
{
+ var typ;
+ switch(kind) {
+ case $kindBool:
+ case $kindInt:
+ case $kindInt8:
+ case $kindInt16:
+ case $kindInt32:
+ case $kindUint:
+ case $kindUint8:
+ case $kindUint16:
+ case $kindUint32:
+ case $kindUintptr:
+ case $kindUnsafePointer:
+ typ = function(v) { this.$val = v; };
+ typ.wrapped = true;
+ typ.keyFor = $identity;
+ break;
+
+ case $kindString:
+ typ = function(v) { this.$val = v; };
+ typ.wrapped = true;
+ typ.keyFor = function(x) { return "$" + x; };
+ break;
+
+ case $kindFloat32:
+ case $kindFloat64:
+ typ = function(v) { this.$val = v; };
+ typ.wrapped = true;
+ typ.keyFor = function(x) { return $floatKey(x); };
+ break;
+
+ case $kindInt64:
+ typ = function(high, low) {
+ this.$high = (high + Math.floor(Math.ceil(low) / 4294967296)) >> 0;
+ this.$low = low >>> 0;
+ this.$val = this;
+ };
+ typ.keyFor = function(x) { return x.$high + "$" + x.$low; };
+ break;
+
+ case $kindUint64:
+ typ = function(high, low) {
+ this.$high = (high + Math.floor(Math.ceil(low) / 4294967296)) >>> 0;
+ this.$low = low >>> 0;
+ this.$val = this;
+ };
+ typ.keyFor = function(x) { return x.$high + "$" + x.$low; };
+ break;
+
+ case $kindComplex64:
+ typ = function(real, imag) {
+ this.$real = $fround(real);
+ this.$imag = $fround(imag);
+ this.$val = this;
+ };
+ typ.keyFor = function(x) { return x.$real + "$" + x.$imag; };
+ break;
+
+ case $kindComplex128:
+ typ = function(real, imag) {
+ this.$real = real;
+ this.$imag = imag;
+ this.$val = this;
+ };
+ typ.keyFor = function(x) { return x.$real + "$" + x.$imag; };
+ break;
+
+ case $kindArray:
+ typ = function(v) { this.$val = v; };
+ typ.wrapped = true;
+ typ.ptr = $newType(4, $kindPtr, "*" + string, false, "", false,
function(array) {
+ this.$get = function() { return array; };
+ this.$set = function(v) { typ.copy(this, v); };
+ this.$val = array;
+ });
+ typ.init = function(elem, len) {
+ typ.elem = elem;
+ typ.len = len;
+ typ.comparable = elem.comparable;
+ typ.keyFor = function(x) {
+ return Array.prototype.join.call($mapArray(x, function(e) {
+ return String(elem.keyFor(e)).replace(/\\/g, "\\\\").replace(/\$/g,
"\\$");
+ }), "$");
+ };
+ typ.copy = function(dst, src) {
+ $copyArray(dst, src, 0, 0, src.length, elem);
+ };
+ typ.ptr.init(typ);
+ Object.defineProperty(typ.ptr.nil, "nilCheck", { get:
$throwNilPointerError });
+ };
+ break;
+
+ case $kindChan:
+ typ = function(v) { this.$val = v; };
+ typ.wrapped = true;
+ typ.keyFor = $idKey;
+ typ.init = function(elem, sendOnly, recvOnly) {
+ typ.elem = elem;
+ typ.sendOnly = sendOnly;
+ typ.recvOnly = recvOnly;
+ };
+ break;
+
+ case $kindFunc:
+ typ = function(v) { this.$val = v; };
+ typ.wrapped = true;
+ typ.init = function(params, results, variadic) {
+ typ.params = params;
+ typ.results = results;
+ typ.variadic = variadic;
+ typ.comparable = false;
+ };
+ break;
+
+ case $kindInterface:
+ typ = { implementedBy: {}, missingMethodFor: {} };
+ typ.keyFor = $ifaceKeyFor;
+ typ.init = function(methods) {
+ typ.methods = methods;
+ methods.forEach(function(m) {
+ $ifaceNil[m.prop] = $throwNilPointerError;
+ });
+ };
+ break;
+
+ case $kindMap:
+ typ = function(v) { this.$val = v; };
+ typ.wrapped = true;
+ typ.init = function(key, elem) {
+ typ.key = key;
+ typ.elem = elem;
+ typ.comparable = false;
+ };
+ break;
+
+ case $kindPtr:
+ typ = constructor || function(getter, setter, target) {
+ this.$get = getter;
+ this.$set = setter;
+ this.$target = target;
+ this.$val = this;
+ };
+ typ.keyFor = $idKey;
+ typ.init = function(elem) {
+ typ.elem = elem;
+ typ.wrapped = (elem.kind === $kindArray);
+ typ.nil = new typ($throwNilPointerError, $throwNilPointerError);
+ };
+ break;
+
+ case $kindSlice:
+ typ = function(array) {
+ if (array.constructor !== typ.nativeArray) {
+ array = new typ.nativeArray(array);
+ }
+ this.$array = array;
+ this.$offset = 0;
+ this.$length = array.length;
+ this.$capacity = array.length;
+ this.$val = this;
+ };
+ typ.init = function(elem) {
+ typ.elem = elem;
+ typ.comparable = false;
+ typ.nativeArray = $nativeArray(elem.kind);
+ typ.nil = new typ([]);
+ };
+ break;
+
+ case $kindStruct:
+ typ = function(v) { this.$val = v; };
+ typ.wrapped = true;
+ typ.ptr = $newType(4, $kindPtr, "*" + string, false, pkg, exported,
constructor);
+ typ.ptr.elem = typ;
+ typ.ptr.prototype.$get = function() { return this; };
+ typ.ptr.prototype.$set = function(v) { typ.copy(this, v); };
+ typ.init = function(pkgPath, fields) {
+ typ.pkgPath = pkgPath;
+ typ.fields = fields;
+ fields.forEach(function(f) {
+ if (!f.typ.comparable) {
+ typ.comparable = false;
+ }
+ });
+ typ.keyFor = function(x) {
+ var val = x.$val;
+ return $mapArray(fields, function(f) {
+ return String(f.typ.keyFor(val[f.prop])).replace(/\\/g,
"\\\\").replace(/\$/g, "\\$");
+ }).join("$");
+ };
+ typ.copy = function(dst, src) {
+ for (var i = 0; i < fields.length; i++) {
+ var f = fields[i];
+ switch (f.typ.kind) {
+ case $kindArray:
+ case $kindStruct:
+ f.typ.copy(dst[f.prop], src[f.prop]);
+ continue;
+ default:
+ dst[f.prop] = src[f.prop];
+ continue;
+ }
+ }
+ };
+ /* nil value */
+ var properties = {};
+ fields.forEach(function(f) {
+ properties[f.prop] = { get: $throwNilPointerError, set:
$throwNilPointerError };
+ });
+ typ.ptr.nil = Object.create(constructor.prototype, properties);
+ typ.ptr.nil.$val = typ.ptr.nil;
+ /* methods for embedded fields */
+ $addMethodSynthesizer(function() {
+ var synthesizeMethod = function(target, m, f) {
+ if (target.prototype[m.prop] !== undefined) { return; }
+ target.prototype[m.prop] = function() {
+ var v = this.$val[f.prop];
+ if (f.typ === $jsObjectPtr) {
+ v = new $jsObjectPtr(v);
+ }
+ if (v.$val === undefined) {
+ v = new f.typ(v);
+ }
+ return v[m.prop].apply(v, arguments);
+ };
+ };
+ fields.forEach(function(f) {
+ if (f.anonymous) {
+ $methodSet(f.typ).forEach(function(m) {
+ synthesizeMethod(typ, m, f);
+ synthesizeMethod(typ.ptr, m, f);
+ });
+ $methodSet($ptrType(f.typ)).forEach(function(m) {
+ synthesizeMethod(typ.ptr, m, f);
+ });
+ }
+ });
+ });
+ };
+ break;
+
+ default:
+ $panic(new $String("invalid kind: " + kind));
+ }
+
+ switch (kind) {
+ case $kindBool:
+ case $kindMap:
+ typ.zero = function() { return false; };
+ break;
+
+ case $kindInt:
+ case $kindInt8:
+ case $kindInt16:
+ case $kindInt32:
+ case $kindUint:
+ case $kindUint8 :
+ case $kindUint16:
+ case $kindUint32:
+ case $kindUintptr:
+ case $kindUnsafePointer:
+ case $kindFloat32:
+ case $kindFloat64:
+ typ.zero = function() { return 0; };
+ break;
+
+ case $kindString:
+ typ.zero = function() { return ""; };
+ break;
+
+ case $kindInt64:
+ case $kindUint64:
+ case $kindComplex64:
+ case $kindComplex128:
+ var zero = new typ(0, 0);
+ typ.zero = function() { return zero; };
+ break;
+
+ case $kindPtr:
+ case $kindSlice:
+ typ.zero = function() { return typ.nil; };
+ break;
+
+ case $kindChan:
+ typ.zero = function() { return $chanNil; };
+ break;
+
+ case $kindFunc:
+ typ.zero = function() { return $throwNilPointerError; };
+ break;
+
+ case $kindInterface:
+ typ.zero = function() { return $ifaceNil; };
+ break;
+
+ case $kindArray:
+ typ.zero = function() {
+ var arrayClass = $nativeArray(typ.elem.kind);
+ if (arrayClass !== Array) {
+ return new arrayClass(typ.len);
+ }
+ var array = new Array(typ.len);
+ for (var i = 0; i < typ.len; i++) {
+ array[i] = typ.elem.zero();
+ }
+ return array;
+ };
+ break;
+
+ case $kindStruct:
+ typ.zero = function() { return new typ.ptr(); };
+ break;
+
+ default:
+ $panic(new $String("invalid kind: " + kind));
+ }
+
+ typ.id = $typeIDCounter;
+ $typeIDCounter++;
+ typ.size = size;
+ typ.kind = kind;
+ typ.string = string;
+ typ.named = named;
+ typ.pkg = pkg;
+ typ.exported = exported;
+ typ.methods = [];
+ typ.methodSetCache = null;
+ typ.comparable = true;
+ return typ;
+};
+
+var $methodSet = function(typ) {
+ if (typ.methodSetCache !== null) {
+ return typ.methodSetCache;
+ }
+ var base = {};
+
+ var isPtr = (typ.kind === $kindPtr);
+ if (isPtr && typ.elem.kind === $kindInterface) {
+ typ.methodSetCache = [];
+ return [];
+ }
+
+ var current = [{typ: isPtr ? typ.elem : typ, indirect: isPtr}];
+
+ var seen = {};
+
+ while (current.length > 0) {
+ var next = [];
+ var mset = [];
+
+ current.forEach(function(e) {
+ if (seen[e.typ.string]) {
+ return;
+ }
+ seen[e.typ.string] = true;
+
+ if (e.typ.named) {
+ mset = mset.concat(e.typ.methods);
+ if (e.indirect) {
+ mset = mset.concat($ptrType(e.typ).methods);
+ }
+ }
+
+ switch (e.typ.kind) {
+ case $kindStruct:
+ e.typ.fields.forEach(function(f) {
+ if (f.anonymous) {
+ var fTyp = f.typ;
+ var fIsPtr = (fTyp.kind === $kindPtr);
+ next.push({typ: fIsPtr ? fTyp.elem : fTyp, indirect: e.indirect ||
fIsPtr});
+ }
+ });
+ break;
+
+ case $kindInterface:
+ mset = mset.concat(e.typ.methods);
+ break;
+ }
+ });
+
+ mset.forEach(function(m) {
+ if (base[m.name] === undefined) {
+ base[m.name] = m;
+ }
+ });
+
+ current = next;
+ }
+
+ typ.methodSetCache = [];
+ Object.keys(base).sort().forEach(function(name) {
+ typ.methodSetCache.push(base[name]);
+ });
+ return typ.methodSetCache;
+};
+
+var $Bool = $newType( 1, $kindBool, "bool", true,
"", false, null);
+var $Int = $newType( 4, $kindInt, "int", true,
"", false, null);
+var $Int8 = $newType( 1, $kindInt8, "int8", true,
"", false, null);
+var $Int16 = $newType( 2, $kindInt16, "int16", true,
"", false, null);
+var $Int32 = $newType( 4, $kindInt32, "int32", true,
"", false, null);
+var $Int64 = $newType( 8, $kindInt64, "int64", true,
"", false, null);
+var $Uint = $newType( 4, $kindUint, "uint", true,
"", false, null);
+var $Uint8 = $newType( 1, $kindUint8, "uint8", true,
"", false, null);
+var $Uint16 = $newType( 2, $kindUint16, "uint16", true,
"", false, null);
+var $Uint32 = $newType( 4, $kindUint32, "uint32", true,
"", false, null);
+var $Uint64 = $newType( 8, $kindUint64, "uint64", true,
"", false, null);
+var $Uintptr = $newType( 4, $kindUintptr, "uintptr", true,
"", false, null);
+var $Float32 = $newType( 4, $kindFloat32, "float32", true,
"", false, null);
+var $Float64 = $newType( 8, $kindFloat64, "float64", true,
"", false, null);
+var $Complex64 = $newType( 8, $kindComplex64, "complex64", true,
"", false, null);
+var $Complex128 = $newType(16, $kindComplex128, "complex128", true,
"", false, null);
+var $String = $newType( 8, $kindString, "string", true,
"", false, null);
+var $UnsafePointer = $newType( 4, $kindUnsafePointer, "unsafe.Pointer", true,
"", false, null);
+
+var $nativeArray = function(elemKind) {
+ switch (elemKind) {
+ case $kindInt:
+ return Int32Array;
+ case $kindInt8:
+ return Int8Array;
+ case $kindInt16:
+ return Int16Array;
+ case $kindInt32:
+ return Int32Array;
+ case $kindUint:
+ return Uint32Array;
+ case $kindUint8:
+ return Uint8Array;
+ case $kindUint16:
+ return Uint16Array;
+ case $kindUint32:
+ return Uint32Array;
+ case $kindUintptr:
+ return Uint32Array;
+ case $kindFloat32:
+ return Float32Array;
+ case $kindFloat64:
+ return Float64Array;
+ default:
+ return Array;
+ }
+};
+var $toNativeArray = function(elemKind, array) {
+ var nativeArray = $nativeArray(elemKind);
+ if (nativeArray === Array) {
+ return array;
+ }
+ return new nativeArray(array);
+};
+var $arrayTypes = {};
+var $arrayType = function(elem, len) {
+ var typeKey = elem.id + "$" + len;
+ var typ = $arrayTypes[typeKey];
+ if (typ === undefined) {
+ typ = $newType(12, $kindArray, "[" + len + "]" + elem.string, false, "",
false, null);
+ $arrayTypes[typeKey] = typ;
+ typ.init(elem, len);
+ }
+ return typ;
+};
+
+var $chanType = function(elem, sendOnly, recvOnly) {
+ var string = (recvOnly ? "<-" : "") + "chan" + (sendOnly ? "<- " : " ") +
elem.string;
+ var field = sendOnly ? "SendChan" : (recvOnly ? "RecvChan" : "Chan");
+ var typ = elem[field];
+ if (typ === undefined) {
+ typ = $newType(4, $kindChan, string, false, "", false, null);
+ elem[field] = typ;
+ typ.init(elem, sendOnly, recvOnly);
+ }
+ return typ;
+};
+var $Chan = function(elem, capacity) {
+ if (capacity < 0 || capacity > 2147483647) {
+ $throwRuntimeError("makechan: size out of range");
+ }
+ this.$elem = elem;
+ this.$capacity = capacity;
+ this.$buffer = [];
+ this.$sendQueue = [];
+ this.$recvQueue = [];
+ this.$closed = false;
+};
+var $chanNil = new $Chan(null, 0);
+$chanNil.$sendQueue = $chanNil.$recvQueue = { length: 0, push: function() {},
shift: function() { return undefined; }, indexOf: function() { return -1; } };
+
+var $funcTypes = {};
+var $funcType = function(params, results, variadic) {
+ var typeKey = $mapArray(params, function(p) { return p.id; }).join(",") +
"$" + $mapArray(results, function(r) { return r.id; }).join(",") + "$" +
variadic;
+ var typ = $funcTypes[typeKey];
+ if (typ === undefined) {
+ var paramTypes = $mapArray(params, function(p) { return p.string; });
+ if (variadic) {
+ paramTypes[paramTypes.length - 1] = "..." + paramTypes[paramTypes.length
- 1].substr(2);
+ }
+ var string = "func(" + paramTypes.join(", ") + ")";
+ if (results.length === 1) {
+ string += " " + results[0].string;
+ } else if (results.length > 1) {
+ string += " (" + $mapArray(results, function(r) { return r.string;
}).join(", ") + ")";
+ }
+ typ = $newType(4, $kindFunc, string, false, "", false, null);
+ $funcTypes[typeKey] = typ;
+ typ.init(params, results, variadic);
+ }
+ return typ;
+};
+
+var $interfaceTypes = {};
+var $interfaceType = function(methods) {
+ var typeKey = $mapArray(methods, function(m) { return m.pkg + "," + m.name +
"," + m.typ.id; }).join("$");
+ var typ = $interfaceTypes[typeKey];
+ if (typ === undefined) {
+ var string = "interface {}";
+ if (methods.length !== 0) {
+ string = "interface { " + $mapArray(methods, function(m) {
+ return (m.pkg !== "" ? m.pkg + "." : "") + m.name +
m.typ.string.substr(4);
+ }).join("; ") + " }";
+ }
+ typ = $newType(8, $kindInterface, string, false, "", false, null);
+ $interfaceTypes[typeKey] = typ;
+ typ.init(methods);
+ }
+ return typ;
+};
+var $emptyInterface = $interfaceType([]);
+var $ifaceNil = {};
+var $error = $newType(8, $kindInterface, "error", true, "", false, null);
+$error.init([{prop: "Error", name: "Error", pkg: "", typ: $funcType([],
[$String], false)}]);
+
+var $mapTypes = {};
+var $mapType = function(key, elem) {
+ var typeKey = key.id + "$" + elem.id;
+ var typ = $mapTypes[typeKey];
+ if (typ === undefined) {
+ typ = $newType(4, $kindMap, "map[" + key.string + "]" + elem.string,
false, "", false, null);
+ $mapTypes[typeKey] = typ;
+ typ.init(key, elem);
+ }
+ return typ;
+};
+var $makeMap = function(keyForFunc, entries) {
+ var m = {};
+ for (var i = 0; i < entries.length; i++) {
+ var e = entries[i];
+ m[keyForFunc(e.k)] = e;
+ }
+ return m;
+};
+
+var $ptrType = function(elem) {
+ var typ = elem.ptr;
+ if (typ === undefined) {
+ typ = $newType(4, $kindPtr, "*" + elem.string, false, "", elem.exported,
null);
+ elem.ptr = typ;
+ typ.init(elem);
+ }
+ return typ;
+};
+
+var $newDataPointer = function(data, constructor) {
+ if (constructor.elem.kind === $kindStruct) {
+ return data;
+ }
+ return new constructor(function() { return data; }, function(v) { data = v;
});
+};
+
+var $indexPtr = function(array, index, constructor) {
+ array.$ptr = array.$ptr || {};
+ return array.$ptr[index] || (array.$ptr[index] = new constructor(function()
{ return array[index]; }, function(v) { array[index] = v; }));
+};
+
+var $sliceType = function(elem) {
+ var typ = elem.slice;
+ if (typ === undefined) {
+ typ = $newType(12, $kindSlice, "[]" + elem.string, false, "", false, null);
+ elem.slice = typ;
+ typ.init(elem);
+ }
+ return typ;
+};
+var $makeSlice = function(typ, length, capacity) {
+ capacity = capacity || length;
+ if (length < 0 || length > 2147483647) {
+ $throwRuntimeError("makeslice: len out of range");
+ }
+ if (capacity < 0 || capacity < length || capacity > 2147483647) {
+ $throwRuntimeError("makeslice: cap out of range");
+ }
+ var array = new typ.nativeArray(capacity);
+ if (typ.nativeArray === Array) {
+ for (var i = 0; i < capacity; i++) {
+ array[i] = typ.elem.zero();
+ }
+ }
+ var slice = new typ(array);
+ slice.$length = length;
+ return slice;
+};
+
+var $structTypes = {};
+var $structType = function(pkgPath, fields) {
+ var typeKey = $mapArray(fields, function(f) { return f.name + "," + f.typ.id
+ "," + f.tag; }).join("$");
+ var typ = $structTypes[typeKey];
+ if (typ === undefined) {
+ var string = "struct { " + $mapArray(fields, function(f) {
+ return f.name + " " + f.typ.string + (f.tag !== "" ? (" \"" +
f.tag.replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"") : "");
+ }).join("; ") + " }";
+ if (fields.length === 0) {
+ string = "struct {}";
+ }
+ typ = $newType(0, $kindStruct, string, false, "", false, function() {
+ this.$val = this;
+ for (var i = 0; i < fields.length; i++) {
+ var f = fields[i];
+ var arg = arguments[i];
+ this[f.prop] = arg !== undefined ? arg : f.typ.zero();
+ }
+ });
+ $structTypes[typeKey] = typ;
+ typ.init(pkgPath, fields);
+ }
+ return typ;
+};
+
+var $assertType = function(value, type, returnTuple) {
+ var isInterface = (type.kind === $kindInterface), ok, missingMethod = "";
+ if (value === $ifaceNil) {
+ ok = false;
+ } else if (!isInterface) {
+ ok = value.constructor === type;
+ } else {
+ var valueTypeString = value.constructor.string;
+ ok = type.implementedBy[valueTypeString];
+ if (ok === undefined) {
+ ok = true;
+ var valueMethodSet = $methodSet(value.constructor);
+ var interfaceMethods = type.methods;
+ for (var i = 0; i < interfaceMethods.length; i++) {
+ var tm = interfaceMethods[i];
+ var found = false;
+ for (var j = 0; j < valueMethodSet.length; j++) {
+ var vm = valueMethodSet[j];
+ if (vm.name === tm.name && vm.pkg === tm.pkg && vm.typ === tm.typ) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ ok = false;
+ type.missingMethodFor[valueTypeString] = tm.name;
+ break;
+ }
+ }
+ type.implementedBy[valueTypeString] = ok;
+ }
+ if (!ok) {
+ missingMethod = type.missingMethodFor[valueTypeString];
+ }
+ }
+
+ if (!ok) {
+ if (returnTuple) {
+ return [type.zero(), false];
+ }
+ $panic(new $packages["runtime"].TypeAssertionError.ptr("", (value ===
$ifaceNil ? "" : value.constructor.string), type.string, missingMethod));
+ }
+
+ if (!isInterface) {
+ value = value.$val;
+ }
+ if (type === $jsObjectPtr) {
+ value = value.object;
+ }
+ return returnTuple ? [value, true] : value;
+};
+
+var $stackDepthOffset = 0;
+var $getStackDepth = function() {
+ var err = new Error();
+ if (err.stack === undefined) {
+ return undefined;
+ }
+ return $stackDepthOffset + err.stack.split("\n").length;
+};
+
+var $panicStackDepth = null, $panicValue;
+var $callDeferred = function(deferred, jsErr, fromPanic) {
+ if (!fromPanic && deferred !== null && deferred.index >=
$curGoroutine.deferStack.length) {
+ throw jsErr;
+ }
+ if (jsErr !== null) {
+ var newErr = null;
+ try {
+ $curGoroutine.deferStack.push(deferred);
+ $panic(new $jsErrorPtr(jsErr));
+ } catch (err) {
+ newErr = err;
+ }
+ $curGoroutine.deferStack.pop();
+ $callDeferred(deferred, newErr);
+ return;
+ }
+ if ($curGoroutine.asleep) {
+ return;
+ }
+
+ $stackDepthOffset--;
+ var outerPanicStackDepth = $panicStackDepth;
+ var outerPanicValue = $panicValue;
+
+ var localPanicValue = $curGoroutine.panicStack.pop();
+ if (localPanicValue !== undefined) {
+ $panicStackDepth = $getStackDepth();
+ $panicValue = localPanicValue;
+ }
+
+ try {
+ while (true) {
+ if (deferred === null) {
+ deferred = $curGoroutine.deferStack[$curGoroutine.deferStack.length -
1];
+ if (deferred === undefined) {
+ /* The panic reached the top of the stack. Clear it and throw it as
a JavaScript error. */
+ $panicStackDepth = null;
+ if (localPanicValue.Object instanceof Error) {
+ throw localPanicValue.Object;
+ }
+ var msg;
+ if (localPanicValue.constructor === $String) {
+ msg = localPanicValue.$val;
+ } else if (localPanicValue.Error !== undefined) {
+ msg = localPanicValue.Error();
+ } else if (localPanicValue.String !== undefined) {
+ msg = localPanicValue.String();
+ } else {
+ msg = localPanicValue;
+ }
+ throw new Error(msg);
+ }
+ }
+ var call = deferred.pop();
+ if (call === undefined) {
+ $curGoroutine.deferStack.pop();
+ if (localPanicValue !== undefined) {
+ deferred = null;
+ continue;
+ }
+ return;
+ }
+ var r = call[0].apply(call[2], call[1]);
+ if (r && r.$blk !== undefined) {
+ deferred.push([r.$blk, [], r]);
+ if (fromPanic) {
+ throw null;
+ }
+ return;
+ }
+
+ if (localPanicValue !== undefined && $panicStackDepth === null) {
+ throw null; /* error was recovered */
+ }
+ }
+ } finally {
+ if (localPanicValue !== undefined) {
+ if ($panicStackDepth !== null) {
+ $curGoroutine.panicStack.push(localPanicValue);
+ }
+ $panicStackDepth = outerPanicStackDepth;
+ $panicValue = outerPanicValue;
+ }
+ $stackDepthOffset++;
+ }
+};
+
+var $panic = function(value) {
+ $curGoroutine.panicStack.push(value);
+ $callDeferred(null, null, true);
+};
+var $recover = function() {
+ if ($panicStackDepth === null || ($panicStackDepth !== undefined &&
$panicStackDepth !== $getStackDepth() - 2)) {
+ return $ifaceNil;
+ }
+ $panicStackDepth = null;
+ return $panicValue;
+};
+var $throw = function(err) { throw err; };
+
+var $noGoroutine = { asleep: false, exit: false, deferStack: [], panicStack:
[] };
+var $curGoroutine = $noGoroutine, $totalGoroutines = 0, $awakeGoroutines = 0,
$checkForDeadlock = true;
+var $mainFinished = false;
+var $go = function(fun, args) {
+ $totalGoroutines++;
+ $awakeGoroutines++;
+ var $goroutine = function() {
+ try {
+ $curGoroutine = $goroutine;
+ var r = fun.apply(undefined, args);
+ if (r && r.$blk !== undefined) {
+ fun = function() { return r.$blk(); };
+ args = [];
+ return;
+ }
+ $goroutine.exit = true;
+ } catch (err) {
+ if (!$goroutine.exit) {
+ throw err;
+ }
+ } finally {
+ $curGoroutine = $noGoroutine;
+ if ($goroutine.exit) { /* also set by runtime.Goexit() */
+ $totalGoroutines--;
+ $goroutine.asleep = true;
+ }
+ if ($goroutine.asleep) {
+ $awakeGoroutines--;
+ if (!$mainFinished && $awakeGoroutines === 0 && $checkForDeadlock) {
+ console.error("fatal error: all goroutines are asleep - deadlock!");
+ if ($global.process !== undefined) {
+ $global.process.exit(2);
+ }
+ }
+ }
+ }
+ };
+ $goroutine.asleep = false;
+ $goroutine.exit = false;
+ $goroutine.deferStack = [];
+ $goroutine.panicStack = [];
+ $schedule($goroutine);
+};
+
+var $scheduled = [];
+var $runScheduled = function() {
+ try {
+ var r;
+ while ((r = $scheduled.shift()) !== undefined) {
+ r();
+ }
+ } finally {
+ if ($scheduled.length > 0) {
+ setTimeout($runScheduled, 0);
+ }
+ }
+};
+
+var $schedule = function(goroutine) {
+ if (goroutine.asleep) {
+ goroutine.asleep = false;
+ $awakeGoroutines++;
+ }
+ $scheduled.push(goroutine);
+ if ($curGoroutine === $noGoroutine) {
+ $runScheduled();
+ }
+};
+
+var $setTimeout = function(f, t) {
+ $awakeGoroutines++;
+ return setTimeout(function() {
+ $awakeGoroutines--;
+ f();
+ }, t);
+};
+
+var $block = function() {
+ if ($curGoroutine === $noGoroutine) {
+ $throwRuntimeError("cannot block in JavaScript callback, fix by wrapping
code in goroutine");
+ }
+ $curGoroutine.asleep = true;
+};
+
+var $send = function(chan, value) {
+ if (chan.$closed) {
+ $throwRuntimeError("send on closed channel");
+ }
+ var queuedRecv = chan.$recvQueue.shift();
+ if (queuedRecv !== undefined) {
+ queuedRecv([value, true]);
+ return;
+ }
+ if (chan.$buffer.length < chan.$capacity) {
+ chan.$buffer.push(value);
+ return;
+ }
+
+ var thisGoroutine = $curGoroutine;
+ var closedDuringSend;
+ chan.$sendQueue.push(function(closed) {
+ closedDuringSend = closed;
+ $schedule(thisGoroutine);
+ return value;
+ });
+ $block();
+ return {
+ $blk: function() {
+ if (closedDuringSend) {
+ $throwRuntimeError("send on closed channel");
+ }
+ }
+ };
+};
+var $recv = function(chan) {
+ var queuedSend = chan.$sendQueue.shift();
+ if (queuedSend !== undefined) {
+ chan.$buffer.push(queuedSend(false));
+ }
+ var bufferedValue = chan.$buffer.shift();
+ if (bufferedValue !== undefined) {
+ return [bufferedValue, true];
+ }
+ if (chan.$closed) {
+ return [chan.$elem.zero(), false];
+ }
+
+ var thisGoroutine = $curGoroutine;
+ var f = { $blk: function() { return this.value; } };
+ var queueEntry = function(v) {
+ f.value = v;
+ $schedule(thisGoroutine);
+ };
+ chan.$recvQueue.push(queueEntry);
+ $block();
+ return f;
+};
+var $close = function(chan) {
+ if (chan.$closed) {
+ $throwRuntimeError("close of closed channel");
+ }
+ chan.$closed = true;
+ while (true) {
+ var queuedSend = chan.$sendQueue.shift();
+ if (queuedSend === undefined) {
+ break;
+ }
+ queuedSend(true); /* will panic */
+ }
+ while (true) {
+ var queuedRecv = chan.$recvQueue.shift();
+ if (queuedRecv === undefined) {
+ break;
+ }
+ queuedRecv([chan.$elem.zero(), false]);
+ }
+};
+var $select = function(comms) {
+ var ready = [];
+ var selection = -1;
+ for (var i = 0; i < comms.length; i++) {
+ var comm = comms[i];
+ var chan = comm[0];
+ switch (comm.length) {
+ case 0: /* default */
+ selection = i;
+ break;
+ case 1: /* recv */
+ if (chan.$sendQueue.length !== 0 || chan.$buffer.length !== 0 ||
chan.$closed) {
+ ready.push(i);
+ }
+ break;
+ case 2: /* send */
+ if (chan.$closed) {
+ $throwRuntimeError("send on closed channel");
+ }
+ if (chan.$recvQueue.length !== 0 || chan.$buffer.length <
chan.$capacity) {
+ ready.push(i);
+ }
+ break;
+ }
+ }
+
+ if (ready.length !== 0) {
+ selection = ready[Math.floor(Math.random() * ready.length)];
+ }
+ if (selection !== -1) {
+ var comm = comms[selection];
+ switch (comm.length) {
+ case 0: /* default */
+ return [selection];
+ case 1: /* recv */
+ return [selection, $recv(comm[0])];
+ case 2: /* send */
+ $send(comm[0], comm[1]);
+ return [selection];
+ }
+ }
+
+ var entries = [];
+ var thisGoroutine = $curGoroutine;
+ var f = { $blk: function() { return this.selection; } };
+ var removeFromQueues = function() {
+ for (var i = 0; i < entries.length; i++) {
+ var entry = entries[i];
+ var queue = entry[0];
+ var index = queue.indexOf(entry[1]);
+ if (index !== -1) {
+ queue.splice(index, 1);
+ }
+ }
+ };
+ for (var i = 0; i < comms.length; i++) {
+ (function(i) {
+ var comm = comms[i];
+ switch (comm.length) {
+ case 1: /* recv */
+ var queueEntry = function(value) {
+ f.selection = [i, value];
+ removeFromQueues();
+ $schedule(thisGoroutine);
+ };
+ entries.push([comm[0].$recvQueue, queueEntry]);
+ comm[0].$recvQueue.push(queueEntry);
+ break;
+ case 2: /* send */
+ var queueEntry = function() {
+ if (comm[0].$closed) {
+ $throwRuntimeError("send on closed channel");
+ }
+ f.selection = [i];
+ removeFromQueues();
+ $schedule(thisGoroutine);
+ return comm[1];
+ };
+ entries.push([comm[0].$sendQueue, queueEntry]);
+ comm[0].$sendQueue.push(queueEntry);
+ break;
+ }
+ })(i);
+ }
+ $block();
+ return f;
+};
+
+var $jsObjectPtr, $jsErrorPtr;
+
+var $needsExternalization = function(t) {
+ switch (t.kind) {
+ case $kindBool:
+ case $kindInt:
+ case $kindInt8:
+ case $kindInt16:
+ case $kindInt32:
+ case $kindUint:
+ case $kindUint8:
+ case $kindUint16:
+ case $kindUint32:
+ case $kindUintptr:
+ case $kindFloat32:
+ case $kindFloat64:
+ return false;
+ default:
+ return t !== $jsObjectPtr;
+ }
+};
+
+var $externalize = function(v, t) {
+ if (t === $jsObjectPtr) {
+ return v;
+ }
+ switch (t.kind) {
+ case $kindBool:
+ case $kindInt:
+ case $kindInt8:
+ case $kindInt16:
+ case $kindInt32:
+ case $kindUint:
+ case $kindUint8:
+ case $kindUint16:
+ case $kindUint32:
+ case $kindUintptr:
+ case $kindFloat32:
+ case $kindFloat64:
+ return v;
+ case $kindInt64:
+ case $kindUint64:
+ return $flatten64(v);
+ case $kindArray:
+ if ($needsExternalization(t.elem)) {
+ return $mapArray(v, function(e) { return $externalize(e, t.elem); });
+ }
+ return v;
+ case $kindFunc:
+ return $externalizeFunction(v, t, false);
+ case $kindInterface:
+ if (v === $ifaceNil) {
+ return null;
+ }
+ if (v.constructor === $jsObjectPtr) {
+ return v.$val.object;
+ }
+ return $externalize(v.$val, v.constructor);
+ case $kindMap:
+ var m = {};
+ var keys = $keys(v);
+ for (var i = 0; i < keys.length; i++) {
+ var entry = v[keys[i]];
+ m[$externalize(entry.k, t.key)] = $externalize(entry.v, t.elem);
+ }
+ return m;
+ case $kindPtr:
+ if (v === t.nil) {
+ return null;
+ }
+ return $externalize(v.$get(), t.elem);
+ case $kindSlice:
+ if ($needsExternalization(t.elem)) {
+ return $mapArray($sliceToArray(v), function(e) { return $externalize(e,
t.elem); });
+ }
+ return $sliceToArray(v);
+ case $kindString:
+ if ($isASCII(v)) {
+ return v;
+ }
+ var s = "", r;
+ for (var i = 0; i < v.length; i += r[1]) {
+ r = $decodeRune(v, i);
+ var c = r[0];
+ if (c > 0xFFFF) {
+ var h = Math.floor((c - 0x10000) / 0x400) + 0xD800;
+ var l = (c - 0x10000) % 0x400 + 0xDC00;
+ s += String.fromCharCode(h, l);
+ continue;
+ }
+ s += String.fromCharCode(c);
+ }
+ return s;
+ case $kindStruct:
+ var timePkg = $packages["time"];
+ if (timePkg !== undefined && v.constructor === timePkg.Time.ptr) {
+ var milli = $div64(v.UnixNano(), new $Int64(0, 1000000));
+ return new Date($flatten64(milli));
+ }
+
+ var noJsObject = {};
+ var searchJsObject = function(v, t) {
+ if (t === $jsObjectPtr) {
+ return v;
+ }
+ switch (t.kind) {
+ case $kindPtr:
+ if (v === t.nil) {
+ return noJsObject;
+ }
+ return searchJsObject(v.$get(), t.elem);
+ case $kindStruct:
+ var f = t.fields[0];
+ return searchJsObject(v[f.prop], f.typ);
+ case $kindInterface:
+ return searchJsObject(v.$val, v.constructor);
+ default:
+ return noJsObject;
+ }
+ };
+ var o = searchJsObject(v, t);
+ if (o !== noJsObject) {
+ return o;
+ }
+
+ o = {};
+ for (var i = 0; i < t.fields.length; i++) {
+ var f = t.fields[i];
+ if (!f.exported) {
+ continue;
+ }
+ o[f.name] = $externalize(v[f.prop], f.typ);
+ }
+ return o;
+ }
+ $throwRuntimeError("cannot externalize " + t.string);
+};
+
+var $externalizeFunction = function(v, t, passThis) {
+ if (v === $throwNilPointerError) {
+ return null;
+ }
+ if (v.$externalizeWrapper === undefined) {
+ $checkForDeadlock = false;
+ v.$externalizeWrapper = function() {
+ var args = [];
+ for (var i = 0; i < t.params.length; i++) {
+ if (t.variadic && i === t.params.length - 1) {
+ var vt = t.params[i].elem, varargs = [];
+ for (var j = i; j < arguments.length; j++) {
+ varargs.push($internalize(arguments[j], vt));
+ }
+ args.push(new (t.params[i])(varargs));
+ break;
+ }
+ args.push($internalize(arguments[i], t.params[i]));
+ }
+ var result = v.apply(passThis ? this : undefined, args);
+ switch (t.results.length) {
+ case 0:
+ return;
+ case 1:
+ return $externalize(result, t.results[0]);
+ default:
+ for (var i = 0; i < t.results.length; i++) {
+ result[i] = $externalize(result[i], t.results[i]);
+ }
+ return result;
+ }
+ };
+ }
+ return v.$externalizeWrapper;
+};
+
+var $internalize = function(v, t, recv) {
+ if (t === $jsObjectPtr) {
+ return v;
+ }
+ if (t === $jsObjectPtr.elem) {
+ $throwRuntimeError("cannot internalize js.Object, use *js.Object instead");
+ }
+ if (v && v.__internal_object__ !== undefined) {
+ return $assertType(v.__internal_object__, t, false);
+ }
+ var timePkg = $packages["time"];
+ if (timePkg !== undefined && t === timePkg.Time) {
+ if (!(v !== null && v !== undefined && v.constructor === Date)) {
+ $throwRuntimeError("cannot internalize time.Time from " + typeof v + ",
must be Date");
+ }
+ return timePkg.Unix(new $Int64(0, 0), new $Int64(0, v.getTime() *
1000000));
+ }
+ switch (t.kind) {
+ case $kindBool:
+ return !!v;
+ case $kindInt:
+ return parseInt(v);
+ case $kindInt8:
+ return parseInt(v) << 24 >> 24;
+ case $kindInt16:
+ return parseInt(v) << 16 >> 16;
+ case $kindInt32:
+ return parseInt(v) >> 0;
+ case $kindUint:
+ return parseInt(v);
+ case $kindUint8:
+ return parseInt(v) << 24 >>> 24;
+ case $kindUint16:
+ return parseInt(v) << 16 >>> 16;
+ case $kindUint32:
+ case $kindUintptr:
+ return parseInt(v) >>> 0;
+ case $kindInt64:
+ case $kindUint64:
+ return new t(0, v);
+ case $kindFloat32:
+ case $kindFloat64:
+ return parseFloat(v);
+ case $kindArray:
+ if (v.length !== t.len) {
+ $throwRuntimeError("got array with wrong size from JavaScript native");
+ }
+ return $mapArray(v, function(e) { return $internalize(e, t.elem); });
+ case $kindFunc:
+ return function() {
+ var args = [];
+ for (var i = 0; i < t.params.length; i++) {
+ if (t.variadic && i === t.params.length - 1) {
+ var vt = t.params[i].elem, varargs = arguments[i];
+ for (var j = 0; j < varargs.$length; j++) {
+ args.push($externalize(varargs.$array[varargs.$offset + j], vt));
+ }
+ break;
+ }
+ args.push($externalize(arguments[i], t.params[i]));
+ }
+ var result = v.apply(recv, args);
+ switch (t.results.length) {
+ case 0:
+ return;
+ case 1:
+ return $internalize(result, t.results[0]);
+ default:
+ for (var i = 0; i < t.results.length; i++) {
+ result[i] = $internalize(result[i], t.results[i]);
+ }
+ return result;
+ }
+ };
+ case $kindInterface:
+ if (t.methods.length !== 0) {
+ $throwRuntimeError("cannot internalize " + t.string);
+ }
+ if (v === null) {
+ return $ifaceNil;
+ }
+ if (v === undefined) {
+ return new $jsObjectPtr(undefined);
+ }
+ switch (v.constructor) {
+ case Int8Array:
+ return new ($sliceType($Int8))(v);
+ case Int16Array:
+ return new ($sliceType($Int16))(v);
+ case Int32Array:
+ return new ($sliceType($Int))(v);
+ case Uint8Array:
+ return new ($sliceType($Uint8))(v);
+ case Uint16Array:
+ return new ($sliceType($Uint16))(v);
+ case Uint32Array:
+ return new ($sliceType($Uint))(v);
+ case Float32Array:
+ return new ($sliceType($Float32))(v);
+ case Float64Array:
+ return new ($sliceType($Float64))(v);
+ case Array:
+ return $internalize(v, $sliceType($emptyInterface));
+ case Boolean:
+ return new $Bool(!!v);
+ case Date:
+ if (timePkg === undefined) {
+ /* time package is not present, internalize as &js.Object{Date} so it
can be externalized into original Date. */
+ return new $jsObjectPtr(v);
+ }
+ return new timePkg.Time($internalize(v, timePkg.Time));
+ case Function:
+ var funcType = $funcType([$sliceType($emptyInterface)], [$jsObjectPtr],
true);
+ return new funcType($internalize(v, funcType));
+ case Number:
+ return new $Float64(parseFloat(v));
+ case String:
+ return new $String($internalize(v, $String));
+ default:
+ if ($global.Node && v instanceof $global.Node) {
+ return new $jsObjectPtr(v);
+ }
+ var mapType = $mapType($String, $emptyInterface);
+ return new mapType($internalize(v, mapType));
+ }
+ case $kindMap:
+ var m = {};
+ var keys = $keys(v);
+ for (var i = 0; i < keys.length; i++) {
+ var k = $internalize(keys[i], t.key);
+ m[t.key.keyFor(k)] = { k: k, v: $internalize(v[keys[i]], t.elem) };
+ }
+ return m;
+ case $kindPtr:
+ if (t.elem.kind === $kindStruct) {
+ return $internalize(v, t.elem);
+ }
+ case $kindSlice:
+ return new t($mapArray(v, function(e) { return $internalize(e, t.elem);
}));
+ case $kindString:
+ v = String(v);
+ if ($isASCII(v)) {
+ return v;
+ }
+ var s = "";
+ var i = 0;
+ while (i < v.length) {
+ var h = v.charCodeAt(i);
+ if (0xD800 <= h && h <= 0xDBFF) {
+ var l = v.charCodeAt(i + 1);
+ var c = (h - 0xD800) * 0x400 + l - 0xDC00 + 0x10000;
+ s += $encodeRune(c);
+ i += 2;
+ continue;
+ }
+ s += $encodeRune(h);
+ i++;
+ }
+ return s;
+ case $kindStruct:
+ var noJsObject = {};
+ var searchJsObject = function(t) {
+ if (t === $jsObjectPtr) {
+ return v;
+ }
+ if (t === $jsObjectPtr.elem) {
+ $throwRuntimeError("cannot internalize js.Object, use *js.Object
instead");
+ }
+ switch (t.kind) {
+ case $kindPtr:
+ return searchJsObject(t.elem);
+ case $kindStruct:
+ var f = t.fields[0];
+ var o = searchJsObject(f.typ);
+ if (o !== noJsObject) {
+ var n = new t.ptr();
+ n[f.prop] = o;
+ return n;
+ }
+ return noJsObject;
+ default:
+ return noJsObject;
+ }
+ };
+ var o = searchJsObject(t);
+ if (o !== noJsObject) {
+ return o;
+ }
+ }
+ $throwRuntimeError("cannot internalize " + t.string);
+};
+
+/* $isASCII reports whether string s contains only ASCII characters. */
+var $isASCII = function(s) {
+ for (var i = 0; i < s.length; i++) {
+ if (s.charCodeAt(i) >= 128) {
+ return false;
+ }
+ }
+ return true;
+};
+
+$packages["github.com/gopherjs/gopherjs/js"] = (function() {
+ var $pkg = {}, $init, Object, Error, sliceType, ptrType, sliceType$2,
funcType, ptrType$1, MakeWrapper, init;
+ Object = $pkg.Object = $newType(0, $kindStruct, "js.Object", true,
"github.com/gopherjs/gopherjs/js", true, function(object_) {
+ this.$val = this;
+ if (arguments.length === 0) {
+ this.object = null;
+ return;
+ }
+ this.object = object_;
+ });
+ Error = $pkg.Error = $newType(0, $kindStruct, "js.Error", true,
"github.com/gopherjs/gopherjs/js", true, function(Object_) {
+ this.$val = this;
+ if (arguments.length === 0) {
+ this.Object = null;
+ return;
+ }
+ this.Object = Object_;
+ });
+ sliceType = $sliceType($emptyInterface);
+ ptrType = $ptrType(Object);
+ sliceType$2 = $sliceType(ptrType);
+ funcType = $funcType([sliceType$2], [ptrType], true);
+ ptrType$1 = $ptrType(Error);
+ Object.ptr.prototype.Get = function(key) {
+ var key, o;
+ o = this;
+ return o.object[$externalize(key, $String)];
+ };
+ Object.prototype.Get = function(key) { return this.$val.Get(key); };
+ Object.ptr.prototype.Set = function(key, value) {
+ var key, o, value;
+ o = this;
+ o.object[$externalize(key, $String)] = $externalize(value,
$emptyInterface);
+ };
+ Object.prototype.Set = function(key, value) { return this.$val.Set(key,
value); };
+ Object.ptr.prototype.Delete = function(key) {
+ var key, o;
+ o = this;
+ delete o.object[$externalize(key, $String)];
+ };
+ Object.prototype.Delete = function(key) { return this.$val.Delete(key);
};
+ Object.ptr.prototype.Length = function() {
+ var o;
+ o = this;
+ return $parseInt(o.object.length);
+ };
+ Object.prototype.Length = function() { return this.$val.Length(); };
+ Object.ptr.prototype.Index = function(i) {
+ var i, o;
+ o = this;
+ return o.object[i];
+ };
+ Object.prototype.Index = function(i) { return this.$val.Index(i); };
+ Object.ptr.prototype.SetIndex = function(i, value) {
+ var i, o, value;
+ o = this;
+ o.object[i] = $externalize(value, $emptyInterface);
+ };
+ Object.prototype.SetIndex = function(i, value) { return
this.$val.SetIndex(i, value); };
+ Object.ptr.prototype.Call = function(name, args) {
+ var args, name, o, obj;
+ o = this;
+ return (obj = o.object, obj[$externalize(name,
$String)].apply(obj, $externalize(args, sliceType)));
+ };
+ Object.prototype.Call = function(name, args) { return
this.$val.Call(name, args); };
+ Object.ptr.prototype.Invoke = function(args) {
+ var args, o;
+ o = this;
+ return o.object.apply(undefined, $externalize(args, sliceType));
+ };
+ Object.prototype.Invoke = function(args) { return
this.$val.Invoke(args); };
+ Object.ptr.prototype.New = function(args) {
+ var args, o;
+ o = this;
+ return new ($global.Function.prototype.bind.apply(o.object,
[undefined].concat($externalize(args, sliceType))));
+ };
+ Object.prototype.New = function(args) { return this.$val.New(args); };
+ Object.ptr.prototype.Bool = function() {
+ var o;
+ o = this;
+ return !!(o.object);
+ };
+ Object.prototype.Bool = function() { return this.$val.Bool(); };
+ Object.ptr.prototype.String = function() {
+ var o;
+ o = this;
+ return $internalize(o.object, $String);
+ };
+ Object.prototype.String = function() { return this.$val.String(); };
+ Object.ptr.prototype.Int = function() {
+ var o;
+ o = this;
+ return $parseInt(o.object) >> 0;
+ };
+ Object.prototype.Int = function() { return this.$val.Int(); };
+ Object.ptr.prototype.Int64 = function() {
+ var o;
+ o = this;
+ return $internalize(o.object, $Int64);
+ };
+ Object.prototype.Int64 = function() { return this.$val.Int64(); };
+ Object.ptr.prototype.Uint64 = function() {
+ var o;
+ o = this;
+ return $internalize(o.object, $Uint64);
+ };
+ Object.prototype.Uint64 = function() { return this.$val.Uint64(); };
+ Object.ptr.prototype.Float = function() {
+ var o;
+ o = this;
+ return $parseFloat(o.object);
+ };
+ Object.prototype.Float = function() { return this.$val.Float(); };
+ Object.ptr.prototype.Interface = function() {
+ var o;
+ o = this;
+ return $internalize(o.object, $emptyInterface);
+ };
+ Object.prototype.Interface = function() { return this.$val.Interface();
};
+ Object.ptr.prototype.Unsafe = function() {
+ var o;
+ o = this;
+ return o.object;
+ };
+ Object.prototype.Unsafe = function() { return this.$val.Unsafe(); };
+ Error.ptr.prototype.Error = function() {
+ var err;
+ err = this;
+ return "JavaScript error: " + $internalize(err.Object.message,
$String);
+ };
+ Error.prototype.Error = function() { return this.$val.Error(); };
+ Error.ptr.prototype.Stack = function() {
+ var err;
+ err = this;
+ return $internalize(err.Object.stack, $String);
+ };
+ Error.prototype.Stack = function() { return this.$val.Stack(); };
+ MakeWrapper = function(i) {
+ var i, i$1, m, methods, o, v;
+ v = i;
+ o = new ($global.Object)();
+ o.__internal_object__ = v;
+ methods = v.constructor.methods;
+ i$1 = 0;
+ while (true) {
+ if (!(i$1 < $parseInt(methods.length))) { break; }
+ m = [m];
+ m[0] = methods[i$1];
+ if (!($internalize(m[0].pkg, $String) === "")) {
+ i$1 = i$1 + (1) >> 0;
+ continue;
+ }
+ o[$externalize($internalize(m[0].name, $String),
$String)] = $externalize((function(m) { return function(args) {
+ var args;
+ return
$externalizeFunction(v[$externalize($internalize(m[0].prop, $String),
$String)], m[0].typ, $externalize(true, $Bool)).apply(v, $externalize(args,
sliceType$2));
+ }; })(m), funcType);
+ i$1 = i$1 + (1) >> 0;
+ }
+ return o;
+ };
+ $pkg.MakeWrapper = MakeWrapper;
+ init = function() {
+ var e;
+ e = new Error.ptr(null);
+ $unused(e);
+ };
+ ptrType.methods = [{prop: "Get", name: "Get", pkg: "", typ:
$funcType([$String], [ptrType], false)}, {prop: "Set", name: "Set", pkg: "",
typ: $funcType([$String, $emptyInterface], [], false)}, {prop: "Delete", name:
"Delete", pkg: "", typ: $funcType([$String], [], false)}, {prop: "Length",
name: "Length", pkg: "", typ: $funcType([], [$Int], false)}, {prop: "Index",
name: "Index", pkg: "", typ: $funcType([$Int], [ptrType], false)}, {prop:
"SetIndex", name: "SetIndex", pkg: "", typ: $funcType([$Int, $emptyInterface],
[], false)}, {prop: "Call", name: "Call", pkg: "", typ: $funcType([$String,
sliceType], [ptrType], true)}, {prop: "Invoke", name: "Invoke", pkg: "", typ:
$funcType([sliceType], [ptrType], true)}, {prop: "New", name: "New", pkg: "",
typ: $funcType([sliceType], [ptrType], true)}, {prop: "Bool", name: "Bool",
pkg: "", typ: $funcType([], [$Bool], false)}, {prop: "String", name: "String",
pkg: "", typ: $funcType([], [$String], false)}, {prop: "Int", name: "Int", pkg:
"", typ: $funcType([], [$Int], false)}, {prop: "Int64", name: "Int64", pkg: "",
typ: $funcType([], [$Int64], false)}, {prop: "Uint64", name: "Uint64", pkg: "",
typ: $funcType([], [$Uint64], false)}, {prop: "Float", name: "Float", pkg: "",
typ: $funcType([], [$Float64], false)}, {prop: "Interface", name: "Interface",
pkg: "", typ: $funcType([], [$emptyInterface], false)}, {prop: "Unsafe", name:
"Unsafe", pkg: "", typ: $funcType([], [$Uintptr], false)}];
+ ptrType$1.methods = [{prop: "Error", name: "Error", pkg: "", typ:
$funcType([], [$String], false)}, {prop: "Stack", name: "Stack", pkg: "", typ:
$funcType([], [$String], false)}];
+ Object.init("github.com/gopherjs/gopherjs/js", [{prop: "object", name:
"object", anonymous: false, exported: false, typ: ptrType, tag: ""}]);
+ Error.init("", [{prop: "Object", name: "Object", anonymous: true,
exported: true, typ: ptrType, tag: ""}]);
+ $init = function() {
+ $pkg.$init = function() {};
+ /* */ var $f, $c = false, $s = 0, $r; if (this !== undefined &&
this.$blk !== undefined) { $f = this; $c = true; $s = $f.$s; $r = $f.$r; } s:
while (true) { switch ($s) { case 0:
+ init();
+ /* */ } return; } if ($f === undefined) { $f = { $blk: $init };
} $f.$s = $s; $f.$r = $r; return $f;
+ };
+ $pkg.$init = $init;
+ return $pkg;
+})();
+$packages["runtime/internal/sys"] = (function() {
+ var $pkg = {}, $init;
+ $init = function() {
+ $pkg.$init = function() {};
+ /* */ var $f, $c = false, $s = 0, $r; if (this !== undefined &&
this.$blk !== undefined) { $f = this; $c = true; $s = $f.$s; $r = $f.$r; } s:
while (true) { switch ($s) { case 0:
+ /* */ } return; } if ($f === undefined) { $f = { $blk: $init };
} $f.$s = $s; $f.$r = $r; return $f;
+ };
+ $pkg.$init = $init;
+ return $pkg;
+})();
+$packages["runtime"] = (function() {
+ var $pkg = {}, $init, js, sys, TypeAssertionError, errorString,
ptrType$4, init, throw$1;
+ js = $packages["github.com/gopherjs/gopherjs/js"];
+ sys = $packages["runtime/internal/sys"];
+ TypeAssertionError = $pkg.TypeAssertionError = $newType(0, $kindStruct,
"runtime.TypeAssertionError", true, "runtime", true, function(interfaceString_,
concreteString_, assertedString_, missingMethod_) {
+ this.$val = this;
+ if (arguments.length === 0) {
+ this.interfaceString = "";
+ this.concreteString = "";
+ this.assertedString = "";
+ this.missingMethod = "";
+ return;
+ }
+ this.interfaceString = interfaceString_;
+ this.concreteString = concreteString_;
+ this.assertedString = assertedString_;
+ this.missingMethod = missingMethod_;
+ });
+ errorString = $pkg.errorString = $newType(8, $kindString,
"runtime.errorString", true, "runtime", false, null);
+ ptrType$4 = $ptrType(TypeAssertionError);
+ init = function() {
+ var e, jsPkg;
+ jsPkg =
$packages[$externalize("github.com/gopherjs/gopherjs/js", $String)];
+ $jsObjectPtr = jsPkg.Object.ptr;
+ $jsErrorPtr = jsPkg.Error.ptr;
+ $throwRuntimeError = throw$1;
+ e = $ifaceNil;
+ e = new TypeAssertionError.ptr("", "", "", "");
+ $unused(e);
+ };
+ throw$1 = function(s) {
+ var s;
+ $panic(new errorString((s)));
+ };
+ TypeAssertionError.ptr.prototype.RuntimeError = function() {
+ };
+ TypeAssertionError.prototype.RuntimeError = function() { return
this.$val.RuntimeError(); };
+ TypeAssertionError.ptr.prototype.Error = function() {
+ var e, inter;
+ e = this;
+ inter = e.interfaceString;
+ if (inter === "") {
+ inter = "interface";
+ }
+ if (e.concreteString === "") {
+ return "interface conversion: " + inter + " is nil, not
" + e.assertedString;
+ }
+ if (e.missingMethod === "") {
+ return "interface conversion: " + inter + " is " +
e.concreteString + ", not " + e.assertedString;
+ }
+ return "interface conversion: " + e.concreteString + " is not "
+ e.assertedString + ": missing method " + e.missingMethod;
+ };
+ TypeAssertionError.prototype.Error = function() { return
this.$val.Error(); };
+ errorString.prototype.RuntimeError = function() {
+ var e;
+ e = this.$val;
+ };
+ $ptrType(errorString).prototype.RuntimeError = function() { return new
errorString(this.$get()).RuntimeError(); };
+ errorString.prototype.Error = function() {
+ var e;
+ e = this.$val;
+ return "runtime error: " + (e);
+ };
+ $ptrType(errorString).prototype.Error = function() { return new
errorString(this.$get()).Error(); };
+ ptrType$4.methods = [{prop: "RuntimeError", name: "RuntimeError", pkg:
"", typ: $funcType([], [], false)}, {prop: "Error", name: "Error", pkg: "",
typ: $funcType([], [$String], false)}];
+ errorString.methods = [{prop: "RuntimeError", name: "RuntimeError",
pkg: "", typ: $funcType([], [], false)}, {prop: "Error", name: "Error", pkg:
"", typ: $funcType([], [$String], false)}];
+ TypeAssertionError.init("runtime", [{prop: "interfaceString", name:
"interfaceString", anonymous: false, exported: false, typ: $String, tag: ""},
{prop: "concreteString", name: "concreteString", anonymous: false, exported:
false, typ: $String, tag: ""}, {prop: "assertedString", name: "assertedString",
anonymous: false, exported: false, typ: $String, tag: ""}, {prop:
"missingMethod", name: "missingMethod", anonymous: false, exported: false, typ:
$String, tag: ""}]);
+ $init = function() {
+ $pkg.$init = function() {};
+ /* */ var $f, $c = false, $s = 0, $r; if (this !== undefined &&
this.$blk !== undefined) { $f = this; $c = true; $s = $f.$s; $r = $f.$r; } s:
while (true) { switch ($s) { case 0:
+ $r = js.$init(); /* */ $s = 1; case 1: if($c) { $c = false; $r
= $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
+ $r = sys.$init(); /* */ $s = 2; case 2: if($c) { $c = false; $r
= $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
+ init();
+ /* */ } return; } if ($f === undefined) { $f = { $blk: $init };
} $f.$s = $s; $f.$r = $r; return $f;
+ };
+ $pkg.$init = $init;
+ return $pkg;
+})();
+$packages["mynewt.apache.org/newt/newtmgr/protocol"] = (function() {
+ var $pkg = {}, $init, NmgrReq, Reset, sliceType, ptrType, ptrType$1,
NewNmgrReq;
+ NmgrReq = $pkg.NmgrReq = $newType(0, $kindStruct, "protocol.NmgrReq",
true, "mynewt.apache.org/newt/newtmgr/protocol", true, function(Op_, Flags_,
Len_, Group_, Seq_, Id_, Data_) {
+ this.$val = this;
+ if (arguments.length === 0) {
+ this.Op = 0;
+ this.Flags = 0;
+ this.Len = 0;
+ this.Group = 0;
+ this.Seq = 0;
+ this.Id = 0;
+ this.Data = sliceType.nil;
+ return;
+ }
+ this.Op = Op_;
+ this.Flags = Flags_;
+ this.Len = Len_;
+ this.Group = Group_;
+ this.Seq = Seq_;
+ this.Id = Id_;
+ this.Data = Data_;
+ });
+ Reset = $pkg.Reset = $newType(0, $kindStruct, "protocol.Reset", true,
"mynewt.apache.org/newt/newtmgr/protocol", true, function() {
+ this.$val = this;
+ if (arguments.length === 0) {
+ return;
+ }
+ });
+ sliceType = $sliceType($Uint8);
+ ptrType = $ptrType(NmgrReq);
+ ptrType$1 = $ptrType(Reset);
+ NewNmgrReq = function() {
+ var nmr;
+ nmr = new NmgrReq.ptr(0, 0, 0, 0, 0, 0, sliceType.nil);
+ nmr.Data = new sliceType([]);
+ return [nmr, $ifaceNil];
+ };
+ $pkg.NewNmgrReq = NewNmgrReq;
+ NmgrReq.ptr.prototype.SerializeRequest = function(data) {
+ var data, nmr;
+ nmr = this;
+ data = $append(data, (nmr.Op));
+ data = $append(data, (nmr.Flags));
+ data = $append(data, (nmr.Seq));
+ data = $append(data, (nmr.Id));
+ data = $appendSlice(data, nmr.Data);
+ return [data, $ifaceNil];
+ };
+ NmgrReq.prototype.SerializeRequest = function(data) { return
this.$val.SerializeRequest(data); };
+ Reset.ptr.prototype.EncodeWriteRequest = function() {
+ var _tuple, data, err, msg, nmr, r;
+ r = this;
+ msg = "{}";
+ data = (new sliceType($stringToBytes(msg)));
+ _tuple = NewNmgrReq();
+ nmr = _tuple[0];
+ err = _tuple[1];
+ if (!($interfaceIsEqual(err, $ifaceNil))) {
+ return [ptrType.nil, err];
+ }
+ nmr.Op = 2;
+ nmr.Flags = 0;
+ nmr.Group = 0;
+ nmr.Id = 5;
+ nmr.Len = ((data.$length << 16 >>> 16));
+ nmr.Data = data;
+ return [nmr, $ifaceNil];
+ };
+ Reset.prototype.EncodeWriteRequest = function() { return
this.$val.EncodeWriteRequest(); };
+ ptrType.methods = [{prop: "SerializeRequest", name: "SerializeRequest",
pkg: "", typ: $funcType([sliceType], [sliceType, $error], false)}];
+ ptrType$1.methods = [{prop: "EncodeWriteRequest", name:
"EncodeWriteRequest", pkg: "", typ: $funcType([], [ptrType, $error], false)}];
+ NmgrReq.init("", [{prop: "Op", name: "Op", anonymous: false, exported:
true, typ: $Uint8, tag: ""}, {prop: "Flags", name: "Flags", anonymous: false,
exported: true, typ: $Uint8, tag: ""}, {prop: "Len", name: "Len", anonymous:
false, exported: true, typ: $Uint16, tag: ""}, {prop: "Group", name: "Group",
anonymous: false, exported: true, typ: $Uint16, tag: ""}, {prop: "Seq", name:
"Seq", anonymous: false, exported: true, typ: $Uint8, tag: ""}, {prop: "Id",
name: "Id", anonymous: false, exported: true, typ: $Uint8, tag: ""}, {prop:
"Data", name: "Data", anonymous: false, exported: true, typ: sliceType, tag:
""}]);
+ Reset.init("", []);
+ $init = function() {
+ $pkg.$init = function() {};
+ /* */ var $f, $c = false, $s = 0, $r; if (this !== undefined &&
this.$blk !== undefined) { $f = this; $c = true; $s = $f.$s; $r = $f.$r; } s:
while (true) { switch ($s) { case 0:
+ /* */ } return; } if ($f === undefined) { $f = { $blk: $init };
} $f.$s = $s; $f.$r = $r; return $f;
+ };
+ $pkg.$init = $init;
+ return $pkg;
+})();
+$packages["main"] = (function() {
+ var $pkg = {}, $init, js, protocol, ptrType, funcType, mapType, main,
New;
+ js = $packages["github.com/gopherjs/gopherjs/js"];
+ protocol = $packages["mynewt.apache.org/newt/newtmgr/protocol"];
+ ptrType = $ptrType(js.Object);
+ funcType = $funcType([], [ptrType], false);
+ mapType = $mapType($String, $emptyInterface);
+ main = function() {
+ $global.reset = $externalize($makeMap($String.keyFor, [{ k:
"New", v: new funcType(New) }]), mapType);
+ };
+ New = function() {
+ return js.MakeWrapper(new protocol.Reset.ptr());
+ };
+ $pkg.New = New;
+ $init = function() {
+ $pkg.$init = function() {};
+ /* */ var $f, $c = false, $s = 0, $r; if (this !== undefined &&
this.$blk !== undefined) { $f = this; $c = true; $s = $f.$s; $r = $f.$r; } s:
while (true) { switch ($s) { case 0:
+ $r = js.$init(); /* */ $s = 1; case 1: if($c) { $c = false; $r
= $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
+ $r = protocol.$init(); /* */ $s = 2; case 2: if($c) { $c =
false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
+ if ($pkg === $mainPkg) {
+ main();
+ $mainFinished = true;
+ }
+ /* */ } return; } if ($f === undefined) { $f = { $blk: $init };
} $f.$s = $s; $f.$r = $r; return $f;
+ };
+ $pkg.$init = $init;
+ return $pkg;
+})();
+$synthesizeMethods();
+var $mainPkg = $packages["main"];
+$packages["runtime"].$init();
+$go($mainPkg.$init, []);
+$flushConsole();
+
+}).call(this);
+//# sourceMappingURL=main.js.map
diff --git a/newtmgr/main.js.map b/newtmgr/main.js.map
new file mode 100644
index 00000000..1e830374
--- /dev/null
+++ b/newtmgr/main.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"main.js","sources":["/github.com/gopherjs/gopherjs/js/js.go","runtime.go","/runtime/error.go","/mynewt.apache.org/newt/newtmgr/protocol/nmgr.go","/mynewt.apache.org/newt/newtmgr/protocol/reset.go","/mynewt.apache.org/newt/newtmgr/main.go"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B4C;A;;;;;AAGW;A;;;;;AAGhB;A;;;;;AAGN;A;;;;;AAGQ;A;;;;;AAGc;A;;;;;AAGY;A;;;;;AAGX;A;;;;;AAGH;A;;;;;AAGrB;A;;;;;AAGI;A;;;;;AAGN;A;;;;;AAGI;A;;;;;AAGE;A;;;;;AAGA;A;;;;;AAGQ;A;;;;;AAGP;A;;;;;AASnC;A;;;;;AAKA;A;;;;AAwCA;AACA;AACA;AACA;AACI;;;;AACH;A;AADiC;A;A;AAKjC;;AACC;A;AANgC;A;AASlC;A;;;;AAmBA;AACA;A;;;;;;;;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5IA;AACA;AACA;AACA;AAEI;AACJ;AACA;A;;;AAyLA;A;;A;;;;;AC5LA;A;AAEC;A;A;AAGA;A;A;AAGA;A;AAGD;A;;;;;A;;;;;AAUA;A;;;;;;;;A;A;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACMA;AACA;AAEA;A;;;;;AAgCA;AACA;AAQA;AACA;AAEA;AAGA;A;;;;;AC7EA;AAEA;AAEA;;;A;AAEC;A;AAGD;AACA;AACA;AACA;AACA;AACA;AAEA;A;;;;;;;;;;;;;;;;;;;;;;ACtCA;A;;AAQA;A;;;;;A;A;A;A;A;A"}
diff --git a/newtmgr/protocol/cmdrunner.go b/newtmgr/protocol/cmdrunner.go
deleted file mode 100644
index 42d35ebf..00000000
--- a/newtmgr/protocol/cmdrunner.go
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "encoding/hex"
-
- log "github.com/Sirupsen/logrus"
-
- "mynewt.apache.org/newt/newtmgr/transport"
-)
-
-type CmdRunner struct {
- Conn transport.Conn
-}
-
-func (cr *CmdRunner) ReadResp() (*NmgrReq, error) {
- var nmr NmgrReq
- var nmrfrag *NmgrReq
- var nonmgrhdr bool
-
- nonmgrhdr = false
-
- for {
- pkt, err := cr.Conn.ReadPacket()
- if err != nil {
- return nil, err
- }
-
- bytes := pkt.GetBytes()
- log.Debugf("Rx packet dump:\n%s", hex.Dump(bytes))
-
- if nonmgrhdr == false {
- if cr.Conn.GetOICEncoded() == true {
- nmrfrag, err = DeserializeOmgrReq(bytes)
- } else {
- nmrfrag, err = DeserializeNmgrReq(bytes)
- }
- if err != nil {
- return nil, err
- }
- if nmrfrag == nil {
- continue
- }
- }
- if nmrfrag.Op == NMGR_OP_READ_RSP || nmrfrag.Op ==
NMGR_OP_WRITE_RSP {
- if nonmgrhdr == false {
- nmr.Data = append(nmr.Data, nmrfrag.Data...)
- nmr.Len += uint16(len(nmrfrag.Data))
- } else {
- nmr.Data = append(nmr.Data, bytes...)
- nmr.Len += uint16(len(bytes))
- }
- if nmr.Len >= nmrfrag.Len {
- return &nmr, nil
- } else {
- nonmgrhdr = true
- }
- }
- }
-}
-
-func (cr *CmdRunner) WriteReq(nmr *NmgrReq) error {
- data := []byte{}
- var err error
-
- log.Debugf("Writing newtmgr request %+v", nmr)
-
- if cr.Conn.GetOICEncoded() == true {
- data, err = nmr.SerializeOmgrRequest(data)
- } else {
- data, err = nmr.SerializeRequest(data)
- }
- if err != nil {
- return err
- }
-
- log.Debugf("Tx packet dump:\n%s", hex.Dump(data))
-
- pkt, err := transport.NewPacket(uint16(len(data)))
- if err != nil {
- return err
- }
-
- pkt.AddBytes(data)
-
- if err := cr.Conn.WritePacket(pkt); err != nil {
- return err
- }
-
- return nil
-}
-
-func NewCmdRunner(conn transport.Conn) (*CmdRunner, error) {
- cmd := &CmdRunner{
- Conn: conn,
- }
-
- return cmd, nil
-}
diff --git a/newtmgr/protocol/config.go b/newtmgr/protocol/config.go
deleted file mode 100644
index 94066655..00000000
--- a/newtmgr/protocol/config.go
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type Config struct {
- Name string `codec:"name"`
- Value string `codec:"val"`
-}
-
-func NewConfig() (*Config, error) {
- c := &Config{}
- return c, nil
-}
-
-func (c *Config) EncodeRequest() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_CONFIG
- nmr.Id = 0
- nmr.Len = 0
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
-
- if c.Value == "" {
- type ConfigReadReq struct {
- Name string `codec:"name"`
- }
-
- readReq := &ConfigReadReq{
- Name: c.Name,
- }
-
- enc.Encode(readReq)
-
- nmr.Data = data
- nmr.Op = NMGR_OP_READ
- } else {
- enc.Encode(c)
- nmr.Data = data
- }
- nmr.Len = uint16(len(nmr.Data))
- return nmr, nil
-}
-
-func DecodeConfigResponse(data []byte) (*Config, error) {
- c := &Config{}
-
- if len(data) == 0 {
- return c, nil
- }
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&c)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- return c, nil
-}
diff --git a/newtmgr/protocol/coreerase.go b/newtmgr/protocol/coreerase.go
deleted file mode 100644
index 1dab8b0c..00000000
--- a/newtmgr/protocol/coreerase.go
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type CoreErase struct {
- ErrCode uint32 `codec:"rc"`
-}
-
-func NewCoreErase() (*CoreErase, error) {
- ce := &CoreErase{}
-
- return ce, nil
-}
-
-func (ce *CoreErase) EncodeWriteRequest() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_IMAGE
- nmr.Id = IMGMGR_NMGR_ID_CORELOAD
- nmr.Len = 0
-
- return nmr, nil
-}
-
-func DecodeCoreEraseResponse(data []byte) (*CoreErase, error) {
- ce := &CoreErase{}
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&ce)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- return ce, nil
-}
diff --git a/newtmgr/protocol/corelist.go b/newtmgr/protocol/corelist.go
deleted file mode 100644
index 9bd60f5f..00000000
--- a/newtmgr/protocol/corelist.go
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type CoreList struct {
- ErrCode uint32 `codec:"rc"`
-}
-
-func NewCoreList() (*CoreList, error) {
- ce := &CoreList{}
-
- return ce, nil
-}
-
-func (ce *CoreList) EncodeWriteRequest() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_IMAGE
- nmr.Id = IMGMGR_NMGR_ID_CORELIST
- nmr.Len = 0
-
- return nmr, nil
-}
-
-func DecodeCoreListResponse(data []byte) (*CoreList, error) {
- cl := &CoreList{}
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&cl)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- return cl, nil
-}
diff --git a/newtmgr/protocol/coreload.go b/newtmgr/protocol/coreload.go
deleted file mode 100644
index 82f6d529..00000000
--- a/newtmgr/protocol/coreload.go
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
- "io"
- "os"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type CoreDownload struct {
- File *os.File
- Runner *CmdRunner
- Size int
-}
-
-type coreLoadReq struct {
- Off uint32 `codec:"off"`
-}
-
-type coreLoadResp struct {
- ErrCode uint32 `codec:"rc"`
- Off uint32 `codec:"off"`
- Data []byte `codec:"data"`
-}
-
-func NewCoreDownload() (*CoreDownload, error) {
- f := &CoreDownload{}
-
- return f, nil
-}
-
-func (cl *CoreDownload) Download(off, size uint32) error {
- if cl.File == nil {
- return util.NewNewtError("Missing target file")
- }
- if cl.Runner == nil {
- return util.NewNewtError("Missing target")
- }
-
- imageDone := 0
- var bytesWritten uint32 = 0
-
- nmr, err := NewNmgrReq()
- if err != nil {
- return err
- }
- req := &coreLoadReq{}
-
- for imageDone != 1 {
- req.Off = off
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_IMAGE
- nmr.Id = IMGMGR_NMGR_ID_CORELOAD
- nmr.Len = uint16(len(data))
- nmr.Data = data
-
- if err := cl.Runner.WriteReq(nmr); err != nil {
- return err
- }
-
- nmRsp, err := cl.Runner.ReadResp()
- if err != nil {
- return err
- }
-
- fmt.Printf("Got response: %d bytes\n", len(nmRsp.Data))
- clRsp := coreLoadResp{}
- dec := codec.NewDecoderBytes(nmRsp.Data, new(codec.CborHandle))
- if err = dec.Decode(&clRsp); err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- if clRsp.ErrCode == NMGR_ERR_ENOENT {
- return util.NewNewtError("No corefile present")
- }
- if clRsp.ErrCode != 0 {
- return util.NewNewtError(fmt.Sprintf("Download failed:
%d",
- clRsp.ErrCode))
- }
-
- fmt.Printf("rc:%d off: %d dlen:%d\n", clRsp.ErrCode, clRsp.Off,
- len(clRsp.Data))
- if off != clRsp.Off {
- return util.NewNewtError(
- fmt.Sprintf("Invalid data offset %d, expected
%d",
- clRsp.Off, off))
- }
-
- data = clRsp.Data
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid incoming
json: %s",
- err.Error()))
- }
- if len(data) > 0 {
- if size > 0 && uint32(len(data))+bytesWritten >= size {
- data = data[:size-bytesWritten]
- imageDone = 1
- }
- n, err := cl.File.Write(data)
- if err == nil && n < len(data) {
- err = io.ErrShortWrite
- }
- if err != nil {
- return util.NewNewtError(
- fmt.Sprintf("Cannot write to file: %s",
- err.Error()))
- }
- off += uint32(len(data))
- bytesWritten += uint32(len(data))
- } else {
- imageDone = 1
- }
- }
- return nil
-}
diff --git a/newtmgr/protocol/crash.go b/newtmgr/protocol/crash.go
deleted file mode 100644
index 60db8f7a..00000000
--- a/newtmgr/protocol/crash.go
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type Crash struct {
- CrashType string `codec:"t"`
- Err int `codec:"rc,omitempty"`
-}
-
-func NewCrash(crashType string) (*Crash, error) {
- c := &Crash{
- CrashType: crashType,
- }
- return c, nil
-}
-
-func (c *Crash) EncodeWriteRequest() (*NmgrReq, error) {
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(c)
-
- fmt.Printf("crashtype:%s\n", c.CrashType)
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_CRASH
- nmr.Id = 0
- nmr.Len = uint16(len(data))
- nmr.Data = data
-
- return nmr, nil
-}
-
-func DecodeCrashResponse(data []byte) (*Crash, error) {
- c := &Crash{}
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- if err := dec.Decode(&c); err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid response:
%s",
- err.Error()))
- }
- return c, nil
-}
diff --git a/newtmgr/protocol/datetime.go b/newtmgr/protocol/datetime.go
deleted file mode 100644
index 3f213f66..00000000
--- a/newtmgr/protocol/datetime.go
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type DateTime struct {
- DateTime string `codec:"datetime"`
- Return uint64 `codec:"rc,omitempty"`
-}
-
-func NewDateTime() (*DateTime, error) {
- dt := &DateTime{}
- return dt, nil
-}
-
-func (i *DateTime) EncodeRequest() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Len = 0
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_DEFAULT
- nmr.Id = NMGR_ID_DATETIME_STR
-
- if i.DateTime != "" {
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(i)
- nmr.Data = data
- nmr.Len = uint16(len(data))
- } else {
- nmr.Op = NMGR_OP_READ
- nmr.Len = 0
- }
- return nmr, nil
-}
-
-func DecodeDateTimeResponse(data []byte) (*DateTime, error) {
- i := &DateTime{}
-
- if len(data) == 0 {
- return i, nil
- }
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&i)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- return i, nil
-}
diff --git a/newtmgr/protocol/echo.go b/newtmgr/protocol/echo.go
deleted file mode 100644
index 8e86231f..00000000
--- a/newtmgr/protocol/echo.go
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
- "strconv"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type Echo struct {
- Message string `codec:"d"`
- Response string `codec:"r,omitempty"`
-}
-
-func NewEcho() (*Echo, error) {
- s := &Echo{}
- return s, nil
-}
-
-func (e *Echo) EncodeWriteRequest() (*NmgrReq, error) {
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- if err := enc.Encode(e); err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Failed to encode
message %s",
- err.Error()))
- }
-
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_DEFAULT
- nmr.Id = NMGR_ID_ECHO
- nmr.Len = uint16(len(data))
- nmr.Data = data
-
- return nmr, nil
-}
-
-func (e *Echo) EncodeEchoCtrl() (*NmgrReq, error) {
- type SerialEchoCtl struct {
- Echo int `codec:"echo"`
- }
-
- integer, err := strconv.Atoi(e.Message)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid echo ctrl
setting %s",
- err.Error()))
- }
- echoCtl := &SerialEchoCtl{
- Echo: integer,
- }
-
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_DEFAULT
- nmr.Id = NMGR_ID_CONS_ECHO_CTRL
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- if err := enc.Encode(echoCtl); err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Failed to encode
message %s",
- err.Error()))
- }
- nmr.Len = uint16(len(data))
- nmr.Data = data
-
- return nmr, nil
-}
-
-func DecodeEchoResponse(data []byte) (*Echo, error) {
- e := &Echo{}
-
- cborCodec := new(codec.CborHandle)
- dec := codec.NewDecoderBytes(data, cborCodec)
-
- if err := dec.Decode(e); err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid response\n"))
- }
- return e, nil
-}
diff --git a/newtmgr/protocol/fsdefs.go b/newtmgr/protocol/fsdefs.go
deleted file mode 100644
index 601b28e2..00000000
--- a/newtmgr/protocol/fsdefs.go
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-const (
- FS_NMGR_ID_FILE = 0
-)
diff --git a/newtmgr/protocol/fsdownload.go b/newtmgr/protocol/fsdownload.go
deleted file mode 100644
index 24c134d1..00000000
--- a/newtmgr/protocol/fsdownload.go
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type FileDownload struct {
- Offset uint32
- Size uint32
- Name string
- Data []byte
-}
-
-func NewFileDownload() (*FileDownload, error) {
- f := &FileDownload{}
- f.Offset = 0
- f.Data = make([]byte, 0)
-
- return f, nil
-}
-
-func (f *FileDownload) EncodeWriteRequest() (*NmgrReq, error) {
- type DownloadReq struct {
- Off uint32 `codec:"off"`
- Name string `codec:"name"`
- }
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_FS
- nmr.Id = FS_NMGR_ID_FILE
-
- downloadReq := &DownloadReq{
- Off: f.Offset,
- Name: f.Name,
- }
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(downloadReq)
- nmr.Len = uint16(len(data))
- nmr.Data = data
-
- return nmr, nil
-}
-
-func DecodeFileDownloadResponse(data []byte) (*FileDownload, error) {
- type DownloadResp struct {
- Off uint32 `json:"off"`
- Size uint32 `json:"len"`
- Data []byte `json:"data"`
- ReturnCode int `json:"rc"`
- }
- resp := &DownloadResp{}
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- if resp.ReturnCode != 0 {
- return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
- resp.ReturnCode))
- }
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
json: %s",
- err.Error()))
- }
- f := &FileDownload{
- Offset: resp.Off,
- Data: resp.Data,
- Size: resp.Size,
- }
- return f, nil
-}
diff --git a/newtmgr/protocol/fsupload.go b/newtmgr/protocol/fsupload.go
deleted file mode 100644
index 96589523..00000000
--- a/newtmgr/protocol/fsupload.go
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type FileUpload struct {
- Offset uint32 `codec:"off"`
- Name string
- Size uint32
- Data []byte
- ReturnCode int `codec:"rc"`
-}
-
-func NewFileUpload() (*FileUpload, error) {
- f := &FileUpload{}
- f.Offset = 0
-
- return f, nil
-}
-
-func (f *FileUpload) EncodeWriteRequest() (*NmgrReq, error) {
- type UploadReq struct {
- Off uint32 `codec:"off"`
- Data []byte `codec:"data"`
- }
- type UploadFirstReq struct {
- Off uint32 `codec:"off"`
- Size uint32 `codec:"len"`
- Name string `codec:"name"`
- Data []byte `codec:"data"`
- }
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_FS
- nmr.Id = FS_NMGR_ID_FILE
-
- data := []byte{}
-
- if f.Offset == 0 {
- uploadReq := &UploadFirstReq{
- Off: f.Offset,
- Size: f.Size,
- Name: f.Name,
- Data: f.Data,
- }
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(uploadReq)
- } else {
- uploadReq := &UploadReq{
- Off: f.Offset,
- Data: f.Data,
- }
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(uploadReq)
- }
- nmr.Len = uint16(len(data))
- nmr.Data = data
-
- return nmr, nil
-}
-
-func DecodeFileUploadResponse(data []byte) (*FileUpload, error) {
- f := &FileUpload{}
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&f)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- if f.ReturnCode != 0 {
- return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
- f.ReturnCode))
- }
- return f, nil
-}
diff --git a/newtmgr/protocol/imagedefs.go b/newtmgr/protocol/imagedefs.go
deleted file mode 100644
index 5820ce78..00000000
--- a/newtmgr/protocol/imagedefs.go
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "encoding/base64"
- "encoding/hex"
- "fmt"
-
- "mynewt.apache.org/newt/util"
-)
-
-const (
- IMGMGR_NMGR_ID_STATE = 0
- IMGMGR_NMGR_ID_UPLOAD = 1
- IMGMGR_NMGR_ID_CORELIST = 3
- IMGMGR_NMGR_ID_CORELOAD = 4
- IMGMGR_NMGR_ID_ERASE = 5
-)
-
-type SplitStatus int
-
-const (
- NOT_APPLICABLE SplitStatus = iota
- NOT_MATCHING
- MATCHING
-)
-
-/* returns the enum as a string */
-func (sm SplitStatus) String() string {
- names := map[SplitStatus]string{
- NOT_APPLICABLE: "N/A",
- NOT_MATCHING: "non-matching",
- MATCHING: "matching",
- }
-
- str := names[sm]
- if str == "" {
- return "Unknown!"
- }
- return str
-}
-
-func HashDecode(src string) (string, error) {
- imgHex, err := base64.StdEncoding.DecodeString(src)
- if err != nil {
- return "", util.NewNewtError(fmt.Sprintf("Hash decode error:
%s",
- err.Error()))
- }
- return hex.EncodeToString(imgHex), nil
-}
-
-func HashEncode(src string) (string, error) {
- imgHex, err := hex.DecodeString(src)
- if err != nil {
- return "", util.NewNewtError(fmt.Sprintf("Hash encode error:
%s",
- err.Error()))
- }
- return base64.StdEncoding.EncodeToString(imgHex), nil
-}
diff --git a/newtmgr/protocol/imageerase.go b/newtmgr/protocol/imageerase.go
deleted file mode 100644
index 533bdbb2..00000000
--- a/newtmgr/protocol/imageerase.go
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type ImageErase struct {
- ErrCode uint32 `codec:"rc"`
-}
-
-func NewImageErase() (*ImageErase, error) {
- ie := &ImageErase{}
-
- return ie, nil
-}
-
-func (ie *ImageErase) EncodeWriteRequest() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_IMAGE
- nmr.Id = IMGMGR_NMGR_ID_ERASE
- nmr.Len = 0
-
- return nmr, nil
-}
-
-func DecodeImageEraseResponse(data []byte) (*ImageErase, error) {
- ie := &ImageErase{}
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&ie)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- return ie, nil
-}
diff --git a/newtmgr/protocol/imagestate.go b/newtmgr/protocol/imagestate.go
deleted file mode 100644
index d6482e5e..00000000
--- a/newtmgr/protocol/imagestate.go
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type ImageStateEntry struct {
- Slot int `codec:"slot"`
- Version string `codec:"version"`
- Hash []byte `codec:"hash"`
- Bootable bool `codec:"bootable"`
- Pending bool `codec:"pending"`
- Confirmed bool `codec:"confirmed"`
- Active bool `codec:"active"`
- Permanent bool `codec:"permanent"`
-}
-
-type ImageStateRsp struct {
- ReturnCode int `codec:"rc"`
- Images []ImageStateEntry `codec:"images"`
- SplitStatus SplitStatus `codec:"splitStatus"`
-}
-
-type ImageStateReadReq struct {
-}
-
-type ImageStateWriteReq struct {
- Hash []byte `codec:"hash"`
- Confirm bool `codec:"confirm"`
-}
-
-func NewImageStateReadReq() (*ImageStateReadReq, error) {
- s := &ImageStateReadReq{}
- return s, nil
-}
-
-func NewImageStateWriteReq() (*ImageStateWriteReq, error) {
- s := &ImageStateWriteReq{}
- return s, nil
-}
-
-func NewImageStateRsp() (*ImageStateRsp, error) {
- s := &ImageStateRsp{}
- return s, nil
-}
-
-func (i *ImageStateReadReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_IMAGE
- nmr.Id = IMGMGR_NMGR_ID_STATE
- nmr.Len = 0
-
- return nmr, nil
-}
-
-func (i *ImageStateWriteReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- clone, err := NewImageStateWriteReq()
- if err != nil {
- return nil, err
- }
-
- clone.Confirm = i.Confirm
-
- if len(i.Hash) != 0 {
- clone.Hash = i.Hash
- if err != nil {
- return nil, err
- }
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_IMAGE
- nmr.Id = IMGMGR_NMGR_ID_STATE
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(clone)
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeImageStateResponse(data []byte) (*ImageStateRsp, error) {
- rsp := &ImageStateRsp{}
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&rsp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- return rsp, nil
-}
diff --git a/newtmgr/protocol/imageupload.go b/newtmgr/protocol/imageupload.go
deleted file mode 100644
index b9743070..00000000
--- a/newtmgr/protocol/imageupload.go
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type ImageUpload struct {
- Offset uint32 `codec:"off"`
- Size uint32
- Data []byte
- ReturnCode int `codec:"rc"`
-}
-
-func NewImageUpload() (*ImageUpload, error) {
- s := &ImageUpload{}
- s.Offset = 0
-
- return s, nil
-}
-
-func (i *ImageUpload) EncodeWriteRequest() (*NmgrReq, error) {
- type UploadReq struct {
- Off uint32 `codec:"off"`
- Data []byte `codec:"data"`
- }
- type UploadFirstReq struct {
- Off uint32 `codec:"off"`
- Size uint32 `codec:"len"`
- Data []byte `codec:"data"`
- }
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_IMAGE
- nmr.Id = IMGMGR_NMGR_ID_UPLOAD
-
- data := []byte{}
-
- if i.Offset == 0 {
- uploadReq := &UploadFirstReq{
- Off: i.Offset,
- Size: i.Size,
- Data: i.Data,
- }
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(uploadReq)
- } else {
- uploadReq := &UploadReq{
- Off: i.Offset,
- Data: i.Data,
- }
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(uploadReq)
- }
- nmr.Len = uint16(len(data))
- nmr.Data = data
-
- return nmr, nil
-}
-
-func DecodeImageUploadResponse(data []byte) (*ImageUpload, error) {
- i := &ImageUpload{}
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&i)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- if i.ReturnCode != 0 {
- return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
- i.ReturnCode))
- }
- return i, nil
-}
diff --git a/newtmgr/protocol/logs.go b/newtmgr/protocol/logs.go
deleted file mode 100644
index 0dda278c..00000000
--- a/newtmgr/protocol/logs.go
+++ /dev/null
@@ -1,342 +0,0 @@
-/*
- Copyright 2015 Runtime Inc.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-const (
- LOGS_NMGR_OP_READ = 0
- LOGS_NMGR_OP_CLEAR = 1
- LOGS_NMGR_OP_APPEND = 2
- LOGS_NMGR_OP_MODULE_LIST = 3
- LOGS_NMGR_OP_LEVEL_LIST = 4
- LOGS_NMGR_OP_LOGS_LIST = 5
-)
-
-type LogsShowReq struct {
- Name string `codec:"log_name"`
- Timestamp int64 `codec:"ts"`
- Index uint64 `codec:"index"`
-}
-
-type LogsModuleListReq struct {
-}
-
-type LogsLevelListReq struct {
-}
-
-type LogsListReq struct {
-}
-
-type LogEntry struct {
- Timestamp int64 `codec:"ts"`
- Msg string `codec:"msg"`
- Level uint64 `codec:"level"`
- Index uint64 `codec:"index"`
- Module uint64 `codec:"module"`
-}
-
-type LogsShowLog struct {
- Name string `codec:"name"`
- Type uint64 `codec:"type"`
- Entries []LogEntry `codec:"entries"`
-}
-
-type LogsShowRsp struct {
- ReturnCode int `codec:"rc"`
- Logs []LogsShowLog `codec:"logs"`
-}
-
-type LogsModuleListRsp struct {
- ReturnCode int `codec:"rc"`
- Map map[string]int `codec:"module_map"`
-}
-
-type LogsLevelListRsp struct {
- ReturnCode int `codec:"rc"`
- Map map[string]int `codec:"level_map"`
-}
-
-type LogsListRsp struct {
- ReturnCode int `codec:"rc"`
- List []string `codec:"log_list"`
-}
-
-func NewLogsShowReq() (*LogsShowReq, error) {
- s := &LogsShowReq{}
-
- return s, nil
-}
-
-func NewLogsModuleListReq() (*LogsModuleListReq, error) {
- s := &LogsModuleListReq{}
-
- return s, nil
-}
-
-func NewLogsLevelListReq() (*LogsLevelListReq, error) {
- s := &LogsLevelListReq{}
-
- return s, nil
-}
-
-func NewLogsListReq() (*LogsListReq, error) {
- s := &LogsListReq{}
-
- return s, nil
-}
-
-func (sr *LogsModuleListReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_LOGS
- nmr.Id = LOGS_NMGR_OP_MODULE_LIST
-
- req := &LogsModuleListReq{}
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
-
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeLogsListResponse(data []byte) (*LogsListRsp, error) {
- var resp LogsListRsp
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &resp, nil
-}
-
-func (sr *LogsListReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_LOGS
- nmr.Id = LOGS_NMGR_OP_LOGS_LIST
-
- req := &LogsListReq{}
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
-
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeLogsLevelListResponse(data []byte) (*LogsLevelListRsp, error) {
- var resp LogsLevelListRsp
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &resp, nil
-}
-
-func (sr *LogsLevelListReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_LOGS
- nmr.Id = LOGS_NMGR_OP_LEVEL_LIST
-
- req := &LogsLevelListReq{}
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeLogsModuleListResponse(data []byte) (*LogsModuleListRsp, error) {
- var resp LogsModuleListRsp
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &resp, nil
-}
-
-func (sr *LogsShowReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_LOGS
- nmr.Id = LOGS_NMGR_OP_READ
- req := &LogsShowReq{
- Name: sr.Name,
- Timestamp: sr.Timestamp,
- Index: sr.Index,
- }
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeLogsShowResponse(data []byte) (*LogsShowRsp, error) {
- var resp LogsShowRsp
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &resp, nil
-}
-
-type LogsClearReq struct {
-}
-
-type LogsClearRsp struct {
- ReturnCode int `json:"rc"`
-}
-
-func NewLogsClearReq() (*LogsClearReq, error) {
- s := &LogsClearReq{}
-
- return s, nil
-}
-
-func (sr *LogsClearReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_LOGS
- nmr.Id = LOGS_NMGR_OP_CLEAR
-
- req := &LogsClearReq{}
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeLogsClearResponse(data []byte) (*LogsClearRsp, error) {
- var resp LogsClearRsp
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &resp, nil
-}
-
-type LogsAppendReq struct {
- Msg string `codec:"msg"`
- Level uint `codec:"level"`
-}
-
-type LogsAppendRsp struct {
- ReturnCode int `codec:"rc"`
-}
-
-func NewLogsAppendReq() (*LogsAppendReq, error) {
- s := &LogsAppendReq{}
-
- return s, nil
-}
-
-func (sr *LogsAppendReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_LOGS
- nmr.Id = LOGS_NMGR_OP_APPEND
-
- req := &LogsAppendReq{}
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeLogsAppendResponse(data []byte) (*LogsAppendRsp, error) {
- var resp LogsAppendRsp
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &resp, nil
-}
diff --git a/newtmgr/protocol/mpstats.go b/newtmgr/protocol/mpstats.go
deleted file mode 100644
index 9c531ccd..00000000
--- a/newtmgr/protocol/mpstats.go
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type MempoolStatsReadReq struct {
-}
-
-type MempoolStatsReadRsp struct {
- ReturnCode int `codec:"rc"`
- MPools map[string]map[string]interface{} `codec:"mpools"`
-}
-
-func NewMempoolStatsReadReq() (*MempoolStatsReadReq, error) {
- s := &MempoolStatsReadReq{}
-
- return s, nil
-}
-
-func (tsr *MempoolStatsReadReq) EncodeWriteRequest() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_DEFAULT
- nmr.Id = NMGR_ID_MPSTATS
-
- nmr.Len = 0
-
- return nmr, nil
-}
-
-func DecodeMempoolStatsReadResponse(data []byte) (*MempoolStatsReadRsp, error)
{
- var tsr MempoolStatsReadRsp
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&tsr)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &tsr, nil
-}
diff --git a/newtmgr/protocol/nmgr.go b/newtmgr/protocol/nmgr.go
index bc24a348..406f95a2 100644
--- a/newtmgr/protocol/nmgr.go
+++ b/newtmgr/protocol/nmgr.go
@@ -20,12 +20,12 @@
package protocol
import (
- "encoding/binary"
- "fmt"
+ // "encoding/binary"
+ // "fmt"
- log "github.com/Sirupsen/logrus"
+ // log "github.com/Sirupsen/logrus"
- "mynewt.apache.org/newt/util"
+ // "mynewt.apache.org/newt/util"
)
type NmgrReq struct {
@@ -62,46 +62,48 @@ func NewNmgrReq() (*NmgrReq, error) {
}
func DeserializeNmgrReq(data []byte) (*NmgrReq, error) {
- if len(data) < 8 {
- return nil, util.NewNewtError(fmt.Sprintf(
- "Newtmgr request buffer too small %d bytes", len(data)))
- }
+ // if len(data) < 8 {
+ // return nil, NewNewtError("Newtmgr request buffer too small
bytes")
+
+ // // return nil, NewNewtError(fmt.Sprintf(
+ // // "Newtmgr request buffer too small %d bytes", len(data)))
+ // }
nmr := &NmgrReq{}
nmr.Op = uint8(data[0])
nmr.Flags = uint8(data[1])
- nmr.Len = binary.BigEndian.Uint16(data[2:4])
- nmr.Group = binary.BigEndian.Uint16(data[4:6])
+ // nmr.Len = binary.BigEndian.Uint16(data[2:4])
+ // nmr.Group = binary.BigEndian.Uint16(data[4:6])
nmr.Seq = uint8(data[6])
nmr.Id = uint8(data[7])
data = data[8:]
nmr.Data = data
- log.Debugf("Deserialized response %+v", nmr)
+ // log.Debugf("Deserialized response %+v", nmr)
return nmr, nil
}
func (nmr *NmgrReq) SerializeRequest(data []byte) ([]byte, error) {
- u16b := make([]byte, 2)
+ // u16b := make([]byte, 2)
data = append(data, byte(nmr.Op))
data = append(data, byte(nmr.Flags))
- binary.BigEndian.PutUint16(u16b, nmr.Len)
- data = append(data, u16b...)
+ // binary.BigEndian.PutUint16(u16b, nmr.Len)
+ // data = append(data, u16b...)
- binary.BigEndian.PutUint16(u16b, nmr.Group)
- data = append(data, u16b...)
+ // binary.BigEndian.PutUint16(u16b, nmr.Group)
+ // data = append(data, u16b...)
data = append(data, byte(nmr.Seq))
data = append(data, byte(nmr.Id))
data = append(data, nmr.Data...)
- log.Debugf("Serializing request %+v into buffer %+v", nmr, data)
+ // log.Debugf("Serializing request %+v into buffer %+v", nmr, data)
return data, nil
}
diff --git a/newtmgr/protocol/omgr.go b/newtmgr/protocol/omgr.go
deleted file mode 100644
index 8e9b5ebf..00000000
--- a/newtmgr/protocol/omgr.go
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- log "github.com/Sirupsen/logrus"
- "github.com/dustin/go-coap"
- "github.com/ugorji/go/codec"
-
- "mynewt.apache.org/newt/util"
-)
-
-type OicRsp struct {
- Read interface{} `codec:"r"`
- Write interface{} `codec:"w"`
-}
-
-/*
- * Not able to install custom decoder for indefite length objects with the
codec.
- * So we need to decode the whole response, and then re-encode the newtmgr
response
- * part.
- */
-func DeserializeOmgrReq(data []byte) (*NmgrReq, error) {
- req := coap.Message{}
- err := req.UnmarshalBinary(data)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf(
- "Oicmgr request invalid %s", err.Error()))
- }
- if req.Code == coap.GET || req.Code == coap.PUT {
- return nil, nil
- }
- if req.Code != coap.Created && req.Code != coap.Deleted &&
- req.Code != coap.Valid && req.Code != coap.Changed &&
- req.Code != coap.Content {
- return nil, util.NewNewtError(fmt.Sprintf(
- "OIC error rsp: %s", req.Code.String()))
- }
-
- var rsp OicRsp
- err = codec.NewDecoderBytes(req.Payload,
new(codec.CborHandle)).Decode(&rsp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
- log.Debugf("Deserialized response %+v", rsp)
-
- nmr := &NmgrReq{}
-
- var ndata []byte = make([]byte, 0)
-
- if rsp.Read != nil {
- err = codec.NewEncoderBytes(&ndata,
- new(codec.CborHandle)).Encode(rsp.Read)
- nmr.Op = NMGR_OP_READ_RSP
- } else {
- err = codec.NewEncoderBytes(&ndata,
- new(codec.CborHandle)).Encode(rsp.Write)
- nmr.Op = NMGR_OP_WRITE_RSP
- }
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Internal error: %s",
- err.Error()))
- }
-
- nmr.Len = uint16(len(ndata))
- nmr.Flags = 0
- nmr.Group = 0
- nmr.Seq = 0
- nmr.Id = 0
-
- nmr.Data = ndata
-
- log.Debugf("Deserialized response %+v", nmr)
-
- return nmr, nil
-}
-
-func (nmr *NmgrReq) SerializeOmgrRequest(data []byte) ([]byte, error) {
- req := coap.Message{
- Type: coap.Confirmable,
- MessageID: uint16(nmr.Seq),
- }
- if nmr.Op == NMGR_OP_READ {
- req.Code = coap.GET
- } else {
- req.Code = coap.PUT
- }
- req.SetPathString("/omgr")
- req.AddOption(coap.URIQuery, fmt.Sprintf("gr=%d", nmr.Group))
- req.AddOption(coap.URIQuery, fmt.Sprintf("id=%d", nmr.Id))
-
- req.Payload = nmr.Data
-
- log.Debugf("Serializing request %+v into buffer %+v", nmr, data)
-
- data, err := req.MarshalBinary()
- if err != nil {
- return nil, util.NewNewtError(
- fmt.Sprintf("Failed to encode: %s\n", err.Error()))
- }
- return data, nil
-}
diff --git a/newtmgr/protocol/runtest.go b/newtmgr/protocol/runtest.go
deleted file mode 100644
index 218ef866..00000000
--- a/newtmgr/protocol/runtest.go
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-const (
- RUN_NMGR_OP_TEST = 0
- RUN_NMGR_OP_LIST = 1
-)
-
-/*
- * run test [all | testname] [token]
- * max testname and token size is 32 bytes
- *
- * This is written with the idea to provide a more extensible RPC mechanism
however
- * the "test" commands constrains the remote calls to those registered to
- * test infrastructure.
- */
-type RunTestReq struct {
- Testname string `codec:"testname"`
- Token string `codec:"token"`
-}
-
-func NewRunTestReq() (*RunTestReq, error) {
- s := &RunTestReq{}
-
- return s, nil
-}
-
-func (sr *RunTestReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_WRITE
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_RUN
- nmr.Id = RUN_NMGR_OP_TEST
- req := &RunTestReq{
- Testname: sr.Testname,
- Token: sr.Token,
- }
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
-
- enc.Encode(req)
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-type RunTestRsp struct {
- ReturnCode int `codec:"rc"`
-}
-
-func DecodeRunTestResponse(data []byte) (*RunTestRsp, error) {
- var resp RunTestRsp
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid response:
%s",
- err.Error()))
- }
-
- return &resp, nil
-}
-
-/*
- * run list
- * Returns the list of tests that have been registered on the device.
- */
-type RunListReq struct {
-}
-
-type RunListRsp struct {
- ReturnCode int `codec:"rc"`
- List []string `codec:"run_list"`
-}
-
-func NewRunListReq() (*RunListReq, error) {
- s := &RunListReq{}
-
- return s, nil
-}
-
-func (sr *RunListReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_RUN
- nmr.Id = RUN_NMGR_OP_LIST
-
- req := &RunListReq{}
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
-
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeRunListResponse(data []byte) (*RunListRsp, error) {
- var resp RunListRsp
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil,
- util.NewNewtError(fmt.Sprintf("Invalid incoming cbor: %s",
- err.Error()))
- }
-
- return &resp, nil
-}
diff --git a/newtmgr/protocol/stats.go b/newtmgr/protocol/stats.go
deleted file mode 100644
index b1a7eb44..00000000
--- a/newtmgr/protocol/stats.go
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-const (
- STATS_NMGR_OP_READ = 0
- STATS_NMGR_OP_LIST = 1
-)
-
-type StatsReadReq struct {
- Name string `codec:"name"`
-}
-
-type StatsListReq struct {
-}
-
-type StatsListRsp struct {
- ReturnCode int `codec:"rc"`
- List []string `codec:"stat_list"`
-}
-
-type StatsReadRsp struct {
- ReturnCode int `codec:"rc"`
- Name string `codec:"name"`
- Group string `codec:"group"`
- Fields map[string]interface{} `codec:"fields"`
-}
-
-func NewStatsListReq() (*StatsListReq, error) {
- s := &StatsListReq{}
-
- return s, nil
-}
-
-func NewStatsReadReq() (*StatsReadReq, error) {
- s := &StatsReadReq{}
- s.Name = ""
-
- return s, nil
-}
-
-func DecodeStatsListResponse(data []byte) (*StatsListRsp, error) {
- var resp StatsListRsp
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&resp)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &resp, nil
-}
-
-func (sr *StatsListReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_STATS
- nmr.Id = STATS_NMGR_OP_LIST
-
- req := &StatsListReq{}
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(req)
-
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func (sr *StatsReadReq) Encode() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_STATS
- nmr.Id = STATS_NMGR_OP_READ
-
- srr := &StatsReadReq{
- Name: sr.Name,
- }
-
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(srr)
-
- nmr.Data = data
- nmr.Len = uint16(len(data))
-
- return nmr, nil
-}
-
-func DecodeStatsReadResponse(data []byte) (*StatsReadRsp, error) {
- var sr StatsReadRsp
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&sr)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &sr, nil
-}
diff --git a/newtmgr/protocol/taskstats.go b/newtmgr/protocol/taskstats.go
deleted file mode 100644
index 0a83238e..00000000
--- a/newtmgr/protocol/taskstats.go
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
- "fmt"
-
- "github.com/ugorji/go/codec"
- "mynewt.apache.org/newt/util"
-)
-
-type TaskStatsReadReq struct {
-}
-
-type TaskStatsReadRsp struct {
- ReturnCode int `codec:"rc"`
- Tasks map[string]map[string]interface{} `codec:"tasks"`
-}
-
-func NewTaskStatsReadReq() (*TaskStatsReadReq, error) {
- s := &TaskStatsReadReq{}
-
- return s, nil
-}
-
-func (tsr *TaskStatsReadReq) EncodeWriteRequest() (*NmgrReq, error) {
- nmr, err := NewNmgrReq()
- if err != nil {
- return nil, err
- }
-
- nmr.Op = NMGR_OP_READ
- nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_DEFAULT
- nmr.Id = NMGR_ID_TASKSTATS
-
- nmr.Len = 0
-
- return nmr, nil
-}
-
-func DecodeTaskStatsReadResponse(data []byte) (*TaskStatsReadRsp, error) {
- var tsr TaskStatsReadRsp
-
- dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- err := dec.Decode(&tsr)
- if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming
cbor: %s",
- err.Error()))
- }
-
- return &tsr, nil
-}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services