diff --git a/README.md b/README.md index a988ccb..0c5050e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ A NodeJS library for making more efficient data transfers by separating the stru [![Coverage Status](https://coveralls.io/repos/github/calebsander/structure-bytes/badge.svg?branch=master)](https://coveralls.io/github/calebsander/structure-bytes?branch=master) ## Concept -Most data nowadays is stored in files or transfered over HTTP as either text files which can represent a wide variety of data structures (e.g. JSON or YAML) or in a format created to represent only one specific sort of data (e.g. MP3). The idea with this project is to get the advantages of both sorts of formats. To accomplish this, the project was designed with several principles in mind: +A lot of data, especially data designed to be used in many different languages, is stored in files or transfered over HTTP as either text files which can represent a wide variety of data structures (e.g. JSON) or in a format created to represent only one specific sort of data (e.g. MP3). The idea with this project is to get the advantages of both sorts of formats. This project is somewhat similar to Google's [Protocol Buffers](https://developers.google.com/protocol-buffers/), but was not designed to match its functionality. To accomplish this, the project was designed with several principles in mind: + - Types (user-created formats of data) are created by combining a wide variety of datatypes, both primitive and recursive. This allows for representations which accurately describe types (e.g. distinguishing between structs and mappings of strings to values, and numeric types, unlike JSON). Types are very customizable, so you can build any desired type formats. - Types are kept separate from values (instances of a type) because types are designed to be created once and used to store many different values. This allows for communications to cache the type format after the first use and only have to send the values in subsequent requests. - Redundancy in data storage is kept to a minimum. For example, in an array of structs, the field names are only specified once in the type spec rather than for each element in the array. @@ -16,18 +17,22 @@ Most data nowadays is stored in files or transfered over HTTP as either text fil - Use when you plan to have many different values for the type (either many different files storing the same sort of information, or many communications of the same sort of information). This will give you the benefit of being able to keep only a single copy of the type spec. - Use when there is a lot of repetition in the data. If you don't have any arrays, sets, or maps, you can't really benefit from the cutdown on redundancy. +## Differences from Protocol Buffers +- Types are generated programmatically rather than by reading `.proto` files. This allows for functionality like a function which turns a type into another type that either contains an error message or an instance of the original type. +- This project is designed with downloading data of known types from servers over HTTP in mind. If the client has already received data of the same type, the server only sends the value and the client reads it using its cached type. If the client doesn't know what the type looks like, the server sends it in byte form along with the value and the client caches the type. This way, the type does not need to be specified in the client-side JavaScript and repeated requests are very efficient. + ## Data types - Primitive types - `Byte` (1-byte signed integer) - `Short` (2-byte signed integer) - `Int` (4-byte signed integer) - `Long` (8-byte signed integer) - - (planned) `BigInt` (a signed integer with up to 256 bytes of precision) + - `BigInt` (a signed integer with up to 65535 bytes of precision) - `UnsignedByte` (1-byte unsigned integer) - `UnsignedShort` (2-byte unsigned integer) - `UnsignedInt` (4-byte unsigned integer) - `UnsignedLong` (8-byte unsigned integer) - - (planned) `BigUnsignedInt` (an unsigned integer with up to 256 bytes of precision) + - `BigUnsignedInt` (an unsigned integer with up to 65535 bytes of precision) - `Date` (8-byte unsigned integer representing number of milliseconds since Jan 1, 1970) - `Float` (IEEE 32-bit floating-point number) - `Double` (IEEE 64-bit floating-point number) diff --git a/compiled/download.js b/compiled/download.js index b8dd9f0..3ca0982 100644 --- a/compiled/download.js +++ b/compiled/download.js @@ -1,2 +1,2 @@ -require=function e(t,r,n){function a(o,u){if(!r[o]){if(!t[o]){var s="function"==typeof require&&require;if(!u&&s)return s(o,!0);if(i)return i(o,!0);var f=Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=r[o]={exports:{}};t[o][0].call(l.exports,function(e){var r=t[o][1][e];return a(r?r:e)},l,l.exports,e,t,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o=200&&t.status<300||304===t.status;r?e[o]=t.response:e.text=t.statusText,n(t.status,t.statusText,e,t.getAllResponseHeaders())}),t.open(i,a,s),t.responseType=o;for(var f in r)r.hasOwnProperty(f)&&t.setRequestHeader(f,r[f]);t.send(u)},abort:function(){t&&t.abort()}}}})}(jQuery)},{}],"/client-side/common.js":[function(e,t,r){"use strict";var n=e("/lib/assert.js");if(n.instanceOf(window.Map,Function),n.instanceOf(window.Set,Function),n.instanceOf(window.ArrayBuffer,Function),n.instanceOf(window.Uint8Array,Function),n.instanceOf(window.Symbol,Function),e("/client-side/binary-ajax.js"),void 0===window.sb)window.sb=e("/structure-types.js");else if(!(window.sb instanceof Object))throw Error("window.sb is already defined")},{"/client-side/binary-ajax.js":"/client-side/binary-ajax.js","/lib/assert.js":"/lib/assert.js","/structure-types.js":"/structure-types.js"}],"/config.js":[function(e,t,r){(function(r){"use strict";"/"===r&&(r="");var n=e(r+"/lib/assert.js"),a=e("base64-js"),i=7;n.between(0,i,65536);var o=2,u=new ArrayBuffer(o);new DataView(u).setUint16(0,i);var s=a.fromByteArray(new Uint8Array(u));t.exports={VERSION_STRING:s}}).call(this,"/")},{"base64-js":2}],"/lib/assert.js":[function(e,t,r){"use strict";var n=e("/lib/util-inspect.js"),a={instanceOf:function(e,t){t instanceof Array||(t=[t]);var r=!1,a=!0,i=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;if(e instanceof f||void 0!==e&&null!==e&&e.constructor===f){r=!0;break}}}catch(e){i=!0,o=e}finally{try{!a&&s.return&&s.return()}finally{if(i)throw o}}if(!r)throw new TypeError(n.inspect(e)+" is not an instance of "+t.map(function(e){return e.name}).join(" or "))},integer:function(e){if(a.instanceOf(e,Number),!Number.isSafeInteger(e))throw new RangeError(n.inspect(e)+" is not an integer")},between:function(e,t,r,a){if(t=r){var i=n.inspect(t)+" is not in ["+n.inspect(e)+","+n.inspect(r)+")";throw void 0===a?new RangeError(i):new RangeError(a+" ("+i+")")}},byteUnsignedInteger:function(e){a.integer(e),a.between(0,e,256)},fourByteUnsignedInteger:function(e){a.integer(e),a.between(0,e,4294967296)},fail:function(e){throw Error(e)},assert:function(e,t){e||a.fail(t)},throws:function(e,t){var r=!0;try{e(),r=!1}catch(e){void 0!==t&&a.message(e,t)}a.assert(r,"Should throw an error")},equal:function(e,t){var r=new RangeError("Expected "+n.inspect(t)+" but got "+n.inspect(e));if(t&&t.constructor===Object){for(var i in t)if(t.hasOwnProperty(i))try{a.equal(e[i],t[i])}catch(e){throw r}}else if(t&&t.constructor===Array){if(!e||e.constructor!==Array)throw r;try{a.equal(e.length,t.length)}catch(e){throw r}for(var o=0;o>>3},modEight:function(e){return 7&e}}},{}],"/lib/buffer-string.js":[function(e,t,r){(function(r){"use strict";var n=e(r+"/assert.js"),a=e(r+"/growable-buffer.js"),i=4096;t.exports={toString:function(e){e&&e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),n.instanceOf(e,Uint8Array);for(var t=[],r=0;r239?4:a>223?3:a>191?2:1;if(r+u<=e.length){var s=void 0,f=void 0,l=void 0,c=void 0;switch(u){case 1:a<128&&(o=a);break;case 2:s=e[r+1],128===(192&s)&&(c=(31&a)<<6|63&s,c>127&&(o=c));break;case 3:s=e[r+1],f=e[r+2],128===(192&s)&&128===(192&f)&&(c=(15&a)<<12|(63&s)<<6|63&f,c>2047&&(c<55296||c>57343)&&(o=c));break;case 4:s=e[r+1],f=e[r+2],l=e[r+3],128===(192&s)&&128===(192&f)&&128===(192&l)&&(c=(15&a)<<18|(63&s)<<12|(63&f)<<6|63&l,c>65535&&c<1114112&&(o=c))}}void 0===o?(o=65533,u=1):o>65535&&(o-=65536,t.push(o>>>10&1023|55296),o=56320|1023&o),t.push(o),r+=u}for(var y="",h=0;h>6),t.add(128|63&l)):l<55296||l>=57344?(t.add(224|l>>12),t.add(128|l>>6&63),t.add(128|63&l)):(l=65536+((1023&l)<<10|1023&l),t.add(240|l>>18),t.add(128|l>>12&63),t.add(128|l>>6&63),t.add(128|63&l))}}catch(e){i=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return t.toBuffer()},toBinaryString:function(e){n.instanceOf(e,ArrayBuffer);var t="",r=new Uint8Array(e),a=!0,i=!1,o=void 0;try{for(var u,s=r[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;t+=String.fromCharCode(f)}}catch(e){i=!0,o=e}finally{try{!a&&s.return&&s.return()}finally{if(i)throw o}}return t},fromBinaryString:function(e){n.instanceOf(e,String);for(var t=new ArrayBuffer(e.length),r=new Uint8Array(t),a=0;athis.buffer.byteLength){var t=new ArrayBuffer(e<<1);new Uint8Array(t).set(new Uint8Array(this.buffer).subarray(0,this.size)),this.buffer=t}return this}},{key:"set",value:function(e,t){i.integer(e),i.integer(t),i.between(0,e,this.size,"Index out of bounds: "+(e+"")),i.between(0,t,256,"Not a byte: "+(t+""));var r=new Uint8Array(this.buffer);return r[e]=t,this}},{key:"setAll",value:function(e,t){i.instanceOf(t,ArrayBuffer),i.integer(e),i.between(0,e,this.size-t.byteLength+1,"Index out of bounds: "+(e+"")),new Uint8Array(this.buffer).set(new Uint8Array(t),e)}},{key:"get",value:function(e){return i.integer(e),i.between(0,e,this.size,"Index out of bounds: "+(e+"")),new Uint8Array(this.buffer)[e]}},{key:"add",value:function(e){var t=this.size,r=t+1;this.grow(r),this.size=r;var n=new Uint8Array(this.buffer);return n[t]=e,this}},{key:"addAll",value:function(e){i.instanceOf(e,ArrayBuffer);var t=this.size,r=this.size+e.byteLength;return this.grow(r),this.size=r,new Uint8Array(this.buffer).set(new Uint8Array(e),t),this}},{key:"toBuffer",value:function(){return this.buffer.slice(0,this.size)}},{key:"length",get:function(){return this.size}},{key:"rawBuffer",get:function(){return this.buffer}}]),e}();t.exports=u}).call(this,"/lib")},{}],"/lib/strint.js":[function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},a={};!function(){function e(e,t){return B(e)===B(t)}function t(e,t){for(;t>0;)e+="0",t--;return e}function r(e){f(e,"string")}function i(e){r(e),s(e,B,"isPositive")}function o(e){f(e,"number")}function u(e){if(f(e,"number"),e<0)throw Error("Expected a positive number: "+e)}function s(e,t,r){if(!t.call(null,e))throw Error("Condition "+r+" failed for value "+e)}function f(e,t){if((void 0===e?"undefined":n(e))!==t)throw Error("Not a "+t+": "+e)}var l=a.subPositive=function(e,t){if(i(e),i(t),!O(e,t))throw Error("x must be greater or equal to y");for(var r=Math.max(e.length,t.length),n="",a=0,o=0,u=0;u=10;)l-=10,a++;0===l?o++:(n=l+""+V(n,o),o=0)}return a>0&&(n=a+""+V(n,o)),n},y=a.add=function(e,t){if(r(e),r(t),B(e)&&B(t))return c(e,t);if(k(e)&&k(t))return j(c(m(e),m(t)));if(T(m(e),m(t))){var n=e;e=t,t=n}var a=l(m(e),m(t));return B(e)?a:j(a)},h=a.sub=function(e,t){return r(e),r(t),y(e,j(t))},v=a.timesDigit=function(e,t){i(e),o(t);for(var r="",n=E(e),a=0,u=0,s=0;s=10;)f-=10,a++;0===f?u++:(r=f+""+V(r,u),u=0)}return a>0&&(r=a+""+V(r,u)),0===r.length?"0":r},g=a.mulPositive=function(e,r){i(e),i(r);for(var n="0",a=E(r),o=0;o=E(e)?"0":e.charAt(e.length-t-1)},E=function(e){return k(e)?e.length-1:e.length}}(),a.LONG_UPPER_SHIFT="4294967296",t.exports=a},{}],"/lib/util-inspect.js":[function(e,t,r){"use strict";r.inspect=function(e){if(void 0===e)return"undefined";if(null===e||e.constructor===Object||e.constructor===Array||e.constructor===String||e.constructor===Number||e.constructor===Boolean||e.constructor===Date)return JSON.stringify(e);if(e.constructor===Set){for(var t="Set {",n=e.values(),a=n.next();!a.done;)t+=r.inspect(a.value),a=n.next(),a.done||(t+=", ");return t+"}"}if(e.constructor===Map){for(var i="Map {",o=e.entries(),u=o.next();!u.done;)i+=r.inspect(u.value[0]),i+=" => ",i+=r.inspect(u.value[1]),u=o.next(),u.done||(i+=", ");return i+"}"}return e.constructor.name?e.constructor.name+" "+JSON.stringify(e):JSON.stringify(e)}},{}],1:[function(e,t,r){"use strict";!function(){function t(){var e={};for(var t in i)e[t]={sig:i[t].sig,type:n.fromByteArray(new Uint8Array(i[t].type.toBuffer()))};localStorage.typeCache=JSON.stringify(e)}e("/client-side/common.js");var r=e("/lib/assert.js"),n=e("base64-js"),a=e("/read.js"),i={};if(void 0===localStorage.typeCache)t();else{var o=JSON.parse(localStorage.typeCache);for(var u in o)i[u]={sig:o[u].sig,type:a.type(new Uint8Array(n.toByteArray(o[u].type)).buffer)}}window.sb.download=function(e,n){function o(e,t,r){if(s){s instanceof Array||(s=[s]);var n=!0,a=!1,i=void 0;try{for(var o,u=s[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var f=o.value;f(e,t,r)}}catch(e){a=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(a)throw i}}}}r.instanceOf(e,String),r.instanceOf(n,Object),n.processData=!1,n.dataType="arraybuffer";var u=!1;i[e]&&(u=!0,n.headers||(n.headers={}),n.headers.sig=i[e].sig);var s=n.success;n.success=function(r,n,s){var f=s.getResponseHeader("sig");if(u&&i[e].sig===f){var l=i[e].type,c=a.value({buffer:r,type:l});o(c,n,s)}else{var y=a._consumeType(r,0),h=a.value({buffer:r,offset:y.length,type:y.value}),v=y.value;i[e]={sig:f,type:v},t(),o(h,n,s)}},$.ajax(n)}}()},{"/client-side/common.js":"/client-side/common.js","/lib/assert.js":"/lib/assert.js","/read.js":"/read.js","base64-js":2}],2:[function(e,t,r){"use strict";function n(){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t0)throw Error("Invalid string. Length must be a multiple of 4");i="="===e[u-2]?2:"="===e[u-1]?1:0,o=new l(3*u/4-i),n=i>0?u-4:u;var s=0;for(t=0,r=0;t>16&255,o[s++]=a>>8&255,o[s++]=255&a;return 2===i?(a=f[e.charCodeAt(t)]<<2|f[e.charCodeAt(t+1)]>>4,o[s++]=255&a):1===i&&(a=f[e.charCodeAt(t)]<<10|f[e.charCodeAt(t+1)]<<4|f[e.charCodeAt(t+2)]>>2,o[s++]=a>>8&255,o[s++]=255&a),o}function i(e){return s[e>>18&63]+s[e>>12&63]+s[e>>6&63]+s[63&e]}function o(e,t,r){for(var n,a=[],o=t;ol?l:f+u));return 1===n?(t=e[r-1],a+=s[t>>2],a+=s[t<<4&63],a+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],a+=s[t>>10],a+=s[t>>4&63],a+=s[t<<2&63],a+="="),i.push(a),i.join("")}r.toByteArray=a,r.fromByteArray=u;var s=[],f=[],l="undefined"!=typeof Uint8Array?Uint8Array:Array;n()},{}],3:[function(e,t,r){!function(e){"use strict";function r(e){return e.map(function(e){return n(e.toString(16),2)}).join("")}function n(e,t){return e.length>t?e:Array(t-e.length+1).join("0")+e}var a={bytesToHex:function(e){return r(e)},hexToBytes:function(e){if(e.length%2===1)throw Error("hexToBytes can't have a string with an odd number of characters.");return 0===e.indexOf("0x")&&(e=e.slice(2)),e.match(/../g).map(function(e){return parseInt(e,16)})}};void 0!==t&&t.exports?t.exports=a:e.convertHex=a}(this)},{}],4:[function(e,t,r){!function(e){"use strict";var r={bytesToString:function(e){return e.map(function(e){return String.fromCharCode(e)}).join("")},stringToBytes:function(e){return e.split("").map(function(e){return e.charCodeAt(0)})}};r.UTF8={bytesToString:function(e){return decodeURIComponent(escape(r.bytesToString(e)))},stringToBytes:function(e){return r.stringToBytes(unescape(encodeURIComponent(e)))}},void 0!==t&&t.exports?t.exports=r:e.convertString=r}(this)},{}],5:[function(e,t,r){!function(r){"use strict";function n(e,t){e.constructor===String&&(e=a.convertString.UTF8.stringToBytes(e));var r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=o(e),i=8*e.length;n[i>>5]|=128<<24-i%32,n[(i+64>>9<<4)+15]=i;for(var s=0;s>>5]|=e[r]<<24-n%32;return t},u=function(e){for(var t=[],r=0;r<32*e.length;r+=8)t.push(e[r>>>5]>>>24-r%32&255);return t},s=[],f=function(e,t,r){for(var n=e[0],a=e[1],o=e[2],u=e[3],f=e[4],l=e[5],c=e[6],y=e[7],h=0;h<64;h++){if(h<16)s[h]=0|t[r+h];else{var v=s[h-15],g=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,d=s[h-2],p=(d<<15|d>>>17)^(d<<13|d>>>19)^d>>>10;s[h]=g+s[h-7]+p+s[h-16]}var b=f&l^~f&c,w=n&a^n&o^a&o,T=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),O=(f<<26|f>>>6)^(f<<21|f>>>11)^(f<<7|f>>>25),A=y+O+b+i[h]+s[h],k=T+w;y=c,c=l,l=f,f=u+A|0,u=o,o=a,a=n,n=A+k|0}e[0]=e[0]+n|0,e[1]=e[1]+a|0,e[2]=e[2]+o|0,e[3]=e[3]+u|0,e[4]=e[4]+f|0,e[5]=e[5]+l|0,e[6]=e[6]+c|0,e[7]=e[7]+y|0};n.x2=function(e,t){return n(n(e,{asBytes:!0}),t)}}(this)},{"convert-hex":3,"convert-string":4}],"/read.js":[function(e,t,r){(function(r){"use strict";function n(e,t){try{return{value:new DataView(e).getUint32(t),length:4}}catch(e){l.fail(d)}}function a(e,t){return e.length=0,"Offset is negative: "+(t+"")),l.assert(e.byteLength>t,d);var r=void 0,o=1;switch(new Uint8Array(e)[t]){case v.ByteType._value:r=new v.ByteType;break;case v.ShortType._value:r=new v.ShortType;break;case v.IntType._value:r=new v.IntType;break;case v.LongType._value:r=new v.LongType;break;case v.UnsignedByteType._value:r=new v.UnsignedByteType;break;case v.UnsignedShortType._value:r=new v.UnsignedShortType;break;case v.UnsignedIntType._value:r=new v.UnsignedIntType;break;case v.UnsignedLongType._value:r=new v.UnsignedLongType;break;case v.DateType._value:r=new v.DateType;break;case v.FloatType._value:r=new v.FloatType;break;case v.DoubleType._value:r=new v.DoubleType;break;case v.BooleanType._value:r=new v.BooleanType;break;case v.BooleanTupleType._value:var u=n(e,t+o);r=new v.BooleanTupleType(u.value),o+=u.length;break;case v.BooleanArrayType._value:r=new v.BooleanArrayType;break;case v.CharType._value:r=new v.CharType;break;case v.StringType._value:r=new v.StringType;break;case v.OctetsType._value:r=new v.OctetsType;break;case v.TupleType._value:var f=i(e,t+o);o+=f.length;var c=n(e,t+o);o+=c.length,r=new v.TupleType({type:f.value,length:c.value});break;case v.StructType._value:l.assert(e.byteLength>t+o,d);var h=new Uint8Array(e),g=h[t+o];o++;for(var p={},b=0;bt+o,d);var w=h[t+o];o++,l.assert(e.byteLength>=t+o+w,d);var T=y.toString(h.subarray(t+o,t+o+w));o+=w;var O=i(e,t+o);p[T]=O.value,o+=O.length}r=new v.StructType(p);break;case v.ArrayType._value:var A=i(e,t+o);o+=A.length,r=new v.ArrayType(A.value);break;case v.SetType._value:var k=i(e,t+o);o+=k.length,r=new v.SetType(k.value);break;case v.MapType._value:var B=i(e,t+o);o+=B.length;var m=i(e,t+o);o+=m.length,r=new v.MapType(B.value,m.value);break;case v.EnumType._value:var j=i(e,t+o);o+=j.length,l.assert(e.byteLength>t+o,d);var S=new Uint8Array(e)[t+o];o++;for(var U=[],_=0;_t+o,d);var V=new Uint8Array(e)[t+o];o++;for(var P=Array(V),E=0;E=t+C,d);var N=new DataView(e).getUint16(t+o),F=i(e,t+o-N);r=F.value,o=C;break;default:l.fail("No such type: 0x"+a(new Uint8Array(e)[t].toString(16),2))}return{value:r,length:o}}function o(e){var t=arguments.length<=1||void 0===arguments[1]||arguments[1];l.instanceOf(e,ArrayBuffer);var r=i(e,0),n=r.value,a=r.length;return t&&l.assert(a===e.byteLength,"Did not consume all of the buffer"),n}function u(e){var t=e.buffer,r=e.offset,n=e.count,a=Array(n),i=c.modEight(a.length),o=c.dividedByEight(a.length),u=void 0;u=i?o+1:o,l.assert(t.byteLength>=r+u,d);for(var s=new Uint8Array(t),f=0;f=r+o,d),i=new Int8Array(t)[r];break;case v.ShortType:o=2,l.assert(t.byteLength>=r+o,d);var f=new DataView(t);i=f.getInt16(r);break;case v.IntType:o=4;var c=new DataView(t);i=c.getInt32(r);break;case v.LongType:o=8,l.assert(t.byteLength>=r+o,d);var p=new DataView(t),b=p.getInt32(r),w=p.getUint32(r+4);i=h.add(h.mul(b+"",h.LONG_UPPER_SHIFT),w+"");break;case v.UnsignedByteType:o=1,l.assert(t.byteLength>=r+o,d),i=new Uint8Array(t)[r];break;case v.UnsignedShortType:o=2,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getUint16(r);break;case v.UnsignedIntType:o=4,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getUint32(r);break;case v.UnsignedLongType:case v.DateType:o=8,l.assert(t.byteLength>=r+o,d);var T=new DataView(t),O=T.getUint32(r),A=T.getUint32(r+4);i=h.add(h.mul(O+"",h.LONG_UPPER_SHIFT),A+""),a.constructor===v.DateType&&(i=new Date((+i)));break;case v.FloatType:o=4,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getFloat32(r);break;case v.DoubleType:o=8,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getFloat64(r);break;case v.BooleanType:o=1,l.assert(t.byteLength>=r+o,d);var k=new Uint8Array(t)[r];l.assert(0===k||255===k,"0x"+k.toString(16)+" is an invalid Boolean value"),i=!!k;break;case v.BooleanArrayType:var B=n(t,r);o=B.length;var m=u({buffer:t,offset:r+o,count:B.value});o+=m.length,i=m.value;break;case v.BooleanTupleType:var j=u({buffer:t,offset:r,count:a.length});i=j.value,o=j.length;break;case v.CharType:l.assert(t.byteLength>r,d),i=y.toString(new Uint8Array(t).subarray(r,r+4))[0],o=y.fromString(i).byteLength;break;case v.StringType:var S=new Uint8Array(t);for(o=0;l.assert(t.byteLength>r+o,d),S[r+o];o++);i=y.toString(new Uint8Array(t).subarray(r,r+o)),o++;break;case v.OctetsType:var U=n(t,r);o=U.length;var _=o+U.value;l.assert(t.byteLength>=r+_,d),i=t.slice(r+o,r+_),o=_;break;case v.TupleType:o=0,i=Array(a.length);for(var x=0;x=r+o,d);var Q=new Uint8Array(t)[r];i=a.values[Q],void 0===i&&l.fail("Index "+(Q+"")+" is invalid");break;case v.ChoiceType:o=1,l.assert(t.byteLength>=r+o,d);var K=new Uint8Array(t)[r],Z=s({buffer:t,offset:r+o,type:a.types[K]});o+=Z.length,i=Z.value;break;case v.OptionalType:o=1,l.assert(t.byteLength>=r+o,d);var ee=new Uint8Array(t)[r];if(l.assert(0===ee||255===ee,"0x"+ee.toString(16)+" is an invalid Optional byte"),ee){var te=s({buffer:t,offset:r+o,type:a.type});o+=te.length,i=te.value}else i=null;break;case v.PointerType:var re=n(t,r);o=re.length,i=s({buffer:t,offset:re.value,type:a.type}).value;break;default:l.fail("Not a structure type: "+g.inspect(a))}return{value:i,length:o}}function f(e){var t=e.buffer,r=e.type,n=e.offset;l.instanceOf(t,ArrayBuffer),l.instanceOf(r,v.Type),void 0===n&&(n=0),l.instanceOf(n,Number);var a=s({buffer:t,offset:n,type:r}),i=a.value;return i}"/"===r&&(r="");var l=e(r+"/lib/assert.js"),c=e(r+"/lib/bit-math.js"),y=e(r+"/lib/buffer-string.js"),h=e(r+"/lib/strint.js"),v=e(r+"/structure-types.js"),g=e("/lib/util-inspect.js"),d="Buffer is not long enough";t.exports={_consumeType:i,type:o,value:f}}).call(this,"/")},{"/lib/util-inspect.js":"/lib/util-inspect.js"}],"/structure-types.js":[function(e,t,r){(function(r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){var t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e),t}function u(e,t){if(t&&e.pointers){var r=!0,n=!1,a=void 0;try{for(var i,o=e.pointers[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=h(i.value,2),s=u[0],f=u[1],l=e.length;e.addAll(d.fromBinaryString(s));var c=new ArrayBuffer(4);new DataView(c).setUint32(0,l);var y=!0,v=!1,g=void 0;try{for(var p,b=f[Symbol.iterator]();!(y=(p=b.next()).done);y=!0){var w=p.value;e.setAll(w,c)}}catch(e){v=!0,g=e}finally{try{!y&&b.return&&b.return()}finally{if(v)throw g}}}}catch(e){n=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(n)throw a}}}}function s(e){if(e&&e.constructor===String){var t=+e;if(!isNaN(t))return t}}function f(e,t){v.instanceOf(e,w),v.instanceOf(t,String),(T.gt(t,"18446744073709551615")||T.lt(t,"0"))&&v.fail("Value out of range");var r=T.div(t,T.LONG_UPPER_SHIFT),n=T.sub(t,T.mul(r,T.LONG_UPPER_SHIFT)),a=new ArrayBuffer(8),i=new DataView(a);i.setUint32(0,+r),i.setUint32(4,+n),e.addAll(a)}function l(e,t){v.instanceOf(t,Array);var r=B(t.length),n=k(t.length),a=void 0;a=r?n+1:n;for(var i=new ArrayBuffer(a),o=new Uint8Array(i),u=0;ut[Y]?1:void 0}),r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 81}}]),y(t,[{key:"addToBuffer",value:function(e){if(c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)){e.add(this.fields.length);var r=!0,n=!1,a=void 0;try{for(var i,o=this.fields[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=i.value,s=u[Q];e.add(s.byteLength),e.addAll(s),u[$].addToBuffer(e)}}catch(e){n=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(n)throw a}}}}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Object);var n=!0,a=!1,i=void 0;try{for(var o,s=this.fields[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var f=o.value,l=t[f[Y]];void 0===l&&v.fail("Value for field "+f[Y]+" missing"),f[$].writeValue(e,l,!1)}}catch(e){a=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(a)throw i}}u(e,r)}}]),t}(S),Z=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(e,j),r.type=e,r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 82}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&this.type.addToBuffer(e)}},{key:"_writeValue",value:function(e,t,r){v.instanceOf(e,w),v.fourByteUnsignedInteger(t.length),e.addAll(o(t.length));var n=!0,a=!1,i=void 0;try{for(var s,f=t[Symbol.iterator]();!(n=(s=f.next()).done);n=!0){var l=s.value;this.type.writeValue(e,l,!1)}}catch(e){a=!0,i=e}finally{try{!n&&f.return&&f.return()}finally{if(a)throw i}}u(e,r)}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,Array),this._writeValue(e,t,r)}}]),t}(S),ee=function(e){function t(e){return i(this,t),n(this,Object.getPrototypeOf(t).call(this,e))}return a(t,e),y(t,null,[{key:"_value",get:function(){return 83}}]),y(t,[{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,Set),t.length=t.size,this._writeValue(e,t,r)}}]),t}(Z),te=function(e){function t(e,r){i(this,t);var a=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(e,j),v.instanceOf(r,j),a.keyType=e,a.valueType=r,a}return a(t,e),y(t,null,[{key:"_value",get:function(){return 84}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&(this.keyType.addToBuffer(e),this.valueType.addToBuffer(e))}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Map),v.fourByteUnsignedInteger(t.size),e.addAll(o(t.size));var n=!0,a=!1,i=void 0;try{for(var s,f=t[Symbol.iterator]();!(n=(s=f.next()).done);n=!0){var l=h(s.value,2),c=l[0],y=l[1];this.keyType.writeValue(e,c,!1),this.valueType.writeValue(e,y,!1)}}catch(e){a=!0,i=e}finally{try{!n&&f.return&&f.return()}finally{if(a)throw i}}u(e,r)}}]),t}(S),re=function(e){function t(e){var r=e.type,a=e.values;i(this,t);var o=n(this,Object.getPrototypeOf(t).call(this));v.instanceOf(r,S),v.instanceOf(a,Array);try{v.byteUnsignedInteger(a.length)}catch(e){v.fail(a.length+" values is too many")}for(var u=new Map,s=0;s=200&&t.status<300||304===t.status;r?e[o]=t.response:e.text=t.statusText,n(t.status,t.statusText,e,t.getAllResponseHeaders())}),t.open(i,a,s),t.responseType=o;for(var f in r)r.hasOwnProperty(f)&&t.setRequestHeader(f,r[f]);t.send(u)},abort:function(){t&&t.abort()}}}})}(jQuery)},{}],"/client-side/common.js":[function(e,t,r){"use strict";var n=e("/lib/assert.js");if(n.instanceOf(window.Map,Function),n.instanceOf(window.Set,Function),n.instanceOf(window.ArrayBuffer,Function),n.instanceOf(window.Uint8Array,Function),n.instanceOf(window.Symbol,Function),e("/client-side/binary-ajax.js"),void 0===window.sb)window.sb=e("/structure-types.js");else if(!(window.sb instanceof Object))throw Error("window.sb is already defined")},{"/client-side/binary-ajax.js":"/client-side/binary-ajax.js","/lib/assert.js":"/lib/assert.js","/structure-types.js":"/structure-types.js"}],"/config.js":[function(e,t,r){(function(r){"use strict";"/"===r&&(r="");var n=e(r+"/lib/assert.js"),a=e("base64-js"),i=8;n.between(0,i,65536);var o=2,u=new ArrayBuffer(o);new DataView(u).setUint16(0,i);var s=a.fromByteArray(new Uint8Array(u));t.exports={VERSION_STRING:s}}).call(this,"/")},{"base64-js":2}],"/lib/assert.js":[function(e,t,r){"use strict";var n=e("/lib/util-inspect.js"),a={instanceOf:function(e,t){t instanceof Array||(t=[t]);var r=!1,a=!0,i=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;if(e instanceof f||void 0!==e&&null!==e&&e.constructor===f){r=!0;break}}}catch(e){i=!0,o=e}finally{try{!a&&s.return&&s.return()}finally{if(i)throw o}}if(!r)throw new TypeError(n.inspect(e)+" is not an instance of "+t.map(function(e){return e.name}).join(" or "))},integer:function(e){if(a.instanceOf(e,Number),!Number.isSafeInteger(e))throw new RangeError(n.inspect(e)+" is not an integer")},between:function(e,t,r,a){if(t=r){var i=n.inspect(t)+" is not in ["+n.inspect(e)+","+n.inspect(r)+")";throw void 0===a?new RangeError(i):new RangeError(a+" ("+i+")")}},byteUnsignedInteger:function(e){a.integer(e),a.between(0,e,256)},twoByteUnsignedInteger:function(e){a.integer(e),a.between(0,e,65536)},fourByteUnsignedInteger:function(e){a.integer(e),a.between(0,e,4294967296)},fail:function(e){throw Error(e)},assert:function(e,t){e||a.fail(t)},throws:function(e,t){var r=!0;try{e(),r=!1}catch(e){void 0!==t&&a.message(e,t)}a.assert(r,"Should throw an error")},equal:function(e,t){var r=new RangeError("Expected "+n.inspect(t)+" but got "+n.inspect(e));if(t&&t.constructor===Object){for(var i in t)if(t.hasOwnProperty(i))try{a.equal(e[i],t[i])}catch(e){throw r}}else if(t&&t.constructor===Array){if(!e||e.constructor!==Array)throw r;try{a.equal(e.length,t.length)}catch(e){throw r}for(var o=0;o>>3},modEight:function(e){return 7&e}}},{}],"/lib/buffer-string.js":[function(e,t,r){(function(r){"use strict";var n=e(r+"/assert.js"),a=e(r+"/growable-buffer.js"),i=4096;t.exports={toString:function(e){e&&e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),n.instanceOf(e,Uint8Array);for(var t=[],r=0;r239?4:a>223?3:a>191?2:1;if(r+u<=e.length){var s=void 0,f=void 0,l=void 0,c=void 0;switch(u){case 1:a<128&&(o=a);break;case 2:s=e[r+1],128===(192&s)&&(c=(31&a)<<6|63&s,c>127&&(o=c));break;case 3:s=e[r+1],f=e[r+2],128===(192&s)&&128===(192&f)&&(c=(15&a)<<12|(63&s)<<6|63&f,c>2047&&(c<55296||c>57343)&&(o=c));break;case 4:s=e[r+1],f=e[r+2],l=e[r+3],128===(192&s)&&128===(192&f)&&128===(192&l)&&(c=(15&a)<<18|(63&s)<<12|(63&f)<<6|63&l,c>65535&&c<1114112&&(o=c))}}void 0===o?(o=65533,u=1):o>65535&&(o-=65536,t.push(o>>>10&1023|55296),o=56320|1023&o),t.push(o),r+=u}for(var y="",h=0;h>6),t.add(128|63&l)):l<55296||l>=57344?(t.add(224|l>>12),t.add(128|l>>6&63),t.add(128|63&l)):(l=65536+((1023&l)<<10|1023&l),t.add(240|l>>18),t.add(128|l>>12&63),t.add(128|l>>6&63),t.add(128|63&l))}}catch(e){i=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return t.toBuffer()},toBinaryString:function(e){n.instanceOf(e,ArrayBuffer);var t="",r=new Uint8Array(e),a=!0,i=!1,o=void 0;try{for(var u,s=r[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;t+=String.fromCharCode(f)}}catch(e){i=!0,o=e}finally{try{!a&&s.return&&s.return()}finally{if(i)throw o}}return t},fromBinaryString:function(e){n.instanceOf(e,String);for(var t=new ArrayBuffer(e.length),r=new Uint8Array(t),a=0;athis.buffer.byteLength){var t=new ArrayBuffer(e<<1);new Uint8Array(t).set(new Uint8Array(this.buffer).subarray(0,this.size)),this.buffer=t}return this}},{key:"set",value:function(e,t){i.integer(e),i.integer(t),i.between(0,e,this.size,"Index out of bounds: "+(e+"")),i.between(0,t,256,"Not a byte: "+(t+""));var r=new Uint8Array(this.buffer);return r[e]=t,this}},{key:"setAll",value:function(e,t){i.instanceOf(t,ArrayBuffer),i.integer(e),i.between(0,e,this.size-t.byteLength+1,"Index out of bounds: "+(e+"")),new Uint8Array(this.buffer).set(new Uint8Array(t),e)}},{key:"get",value:function(e){return i.integer(e),i.between(0,e,this.size,"Index out of bounds: "+(e+"")),new Uint8Array(this.buffer)[e]}},{key:"add",value:function(e){var t=this.size,r=t+1;this.grow(r),this.size=r;var n=new Uint8Array(this.buffer);return n[t]=e,this}},{key:"addAll",value:function(e){i.instanceOf(e,ArrayBuffer);var t=this.size,r=this.size+e.byteLength;return this.grow(r),this.size=r,new Uint8Array(this.buffer).set(new Uint8Array(e),t),this}},{key:"toBuffer",value:function(){return this.buffer.slice(0,this.size)}},{key:"length",get:function(){return this.size}},{key:"rawBuffer",get:function(){return this.buffer}}]),e}();t.exports=u}).call(this,"/lib")},{}],"/lib/strint.js":[function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},a={};!function(){function e(e,t){return k(e)===k(t)}function t(e,t){for(;t>0;)e+="0",t--;return e}function r(e){f(e,"string")}function i(e){r(e),s(e,k,"isPositive")}function o(e){f(e,"number")}function u(e){if(f(e,"number"),e<0)throw Error("Expected a positive number: "+e)}function s(e,t,r){if(!t.call(null,e))throw Error("Condition "+r+" failed for value "+e)}function f(e,t){if((void 0===e?"undefined":n(e))!==t)throw Error("Not a "+t+": "+e)}var l=a.subPositive=function(e,t){if(i(e),i(t),!O(e,t))throw Error("x must be greater or equal to y");for(var r=Math.max(e.length,t.length),n="",a=0,o=0,u=0;u=10;)l-=10,a++;0===l?o++:(n=l+""+V(n,o),o=0)}return a>0&&(n=a+""+V(n,o)),n},y=a.add=function(e,t){if(r(e),r(t),k(e)&&k(t))return c(e,t);if(B(e)&&B(t))return S(c(m(e),m(t)));if(T(m(e),m(t))){var n=e;e=t,t=n}var a=l(m(e),m(t));return k(e)?a:S(a)},h=a.sub=function(e,t){return r(e),r(t),y(e,S(t))},v=a.timesDigit=function(e,t){i(e),o(t);for(var r="",n=I(e),a=0,u=0,s=0;s=10;)f-=10,a++;0===f?u++:(r=f+""+V(r,u),u=0)}return a>0&&(r=a+""+V(r,u)),0===r.length?"0":r},g=a.mulPositive=function(e,r){i(e),i(r);for(var n="0",a=I(r),o=0;o=I(e)?"0":e.charAt(e.length-t-1)},I=function(e){return B(e)?e.length-1:e.length}}(),a.LONG_UPPER_SHIFT="4294967296",a.BYTE_SHIFT="256",t.exports=a},{}],"/lib/util-inspect.js":[function(e,t,r){"use strict";r.inspect=function(e){if(void 0===e)return"undefined";if(null===e||e.constructor===Object||e.constructor===Array||e.constructor===String||e.constructor===Number||e.constructor===Boolean||e.constructor===Date)return JSON.stringify(e);if(e.constructor===Set){for(var t="Set {",n=e.values(),a=n.next();!a.done;)t+=r.inspect(a.value),a=n.next(),a.done||(t+=", ");return t+"}"}if(e.constructor===Map){for(var i="Map {",o=e.entries(),u=o.next();!u.done;)i+=r.inspect(u.value[0]),i+=" => ",i+=r.inspect(u.value[1]),u=o.next(),u.done||(i+=", ");return i+"}"}return e.constructor.name?e.constructor.name+" "+JSON.stringify(e):JSON.stringify(e)}},{}],1:[function(e,t,r){"use strict";!function(){function t(){var e={};for(var t in i)e[t]={sig:i[t].sig,type:n.fromByteArray(new Uint8Array(i[t].type.toBuffer()))};localStorage.typeCache=JSON.stringify(e)}e("/client-side/common.js");var r=e("/lib/assert.js"),n=e("base64-js"),a=e("/read.js"),i={};if(void 0===localStorage.typeCache)t();else{var o=JSON.parse(localStorage.typeCache);for(var u in o)i[u]={sig:o[u].sig,type:a.type(new Uint8Array(n.toByteArray(o[u].type)).buffer)}}window.sb.download=function(e,n){function o(e,t,r){if(s){s instanceof Array||(s=[s]);var n=!0,a=!1,i=void 0;try{for(var o,u=s[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var f=o.value;f(e,t,r)}}catch(e){a=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(a)throw i}}}}r.instanceOf(e,String),r.instanceOf(n,Object),n.processData=!1,n.dataType="arraybuffer";var u=!1;i[e]&&(u=!0,n.headers||(n.headers={}),n.headers.sig=i[e].sig);var s=n.success;n.success=function(r,n,s){var f=s.getResponseHeader("sig");if(u&&i[e].sig===f){var l=i[e].type,c=a.value({buffer:r,type:l});o(c,n,s)}else{var y=a._consumeType(r,0),h=a.value({buffer:r,offset:y.length,type:y.value}),v=y.value;i[e]={sig:f,type:v},t(),o(h,n,s)}},$.ajax(n)}}()},{"/client-side/common.js":"/client-side/common.js","/lib/assert.js":"/lib/assert.js","/read.js":"/read.js","base64-js":2}],2:[function(e,t,r){"use strict";function n(){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t0)throw Error("Invalid string. Length must be a multiple of 4");i="="===e[u-2]?2:"="===e[u-1]?1:0,o=new l(3*u/4-i),n=i>0?u-4:u;var s=0;for(t=0,r=0;t>16&255,o[s++]=a>>8&255,o[s++]=255&a;return 2===i?(a=f[e.charCodeAt(t)]<<2|f[e.charCodeAt(t+1)]>>4,o[s++]=255&a):1===i&&(a=f[e.charCodeAt(t)]<<10|f[e.charCodeAt(t+1)]<<4|f[e.charCodeAt(t+2)]>>2,o[s++]=a>>8&255,o[s++]=255&a),o}function i(e){return s[e>>18&63]+s[e>>12&63]+s[e>>6&63]+s[63&e]}function o(e,t,r){for(var n,a=[],o=t;ol?l:f+u));return 1===n?(t=e[r-1],a+=s[t>>2],a+=s[t<<4&63],a+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],a+=s[t>>10],a+=s[t>>4&63],a+=s[t<<2&63],a+="="),i.push(a),i.join("")}r.toByteArray=a,r.fromByteArray=u;var s=[],f=[],l="undefined"!=typeof Uint8Array?Uint8Array:Array;n()},{}],3:[function(e,t,r){!function(e){"use strict";function r(e){return e.map(function(e){return n(e.toString(16),2)}).join("")}function n(e,t){return e.length>t?e:Array(t-e.length+1).join("0")+e}var a={bytesToHex:function(e){return r(e)},hexToBytes:function(e){if(e.length%2===1)throw Error("hexToBytes can't have a string with an odd number of characters.");return 0===e.indexOf("0x")&&(e=e.slice(2)),e.match(/../g).map(function(e){return parseInt(e,16)})}};void 0!==t&&t.exports?t.exports=a:e.convertHex=a}(this)},{}],4:[function(e,t,r){!function(e){"use strict";var r={bytesToString:function(e){return e.map(function(e){return String.fromCharCode(e)}).join("")},stringToBytes:function(e){return e.split("").map(function(e){return e.charCodeAt(0)})}};r.UTF8={bytesToString:function(e){return decodeURIComponent(escape(r.bytesToString(e)))},stringToBytes:function(e){return r.stringToBytes(unescape(encodeURIComponent(e)))}},void 0!==t&&t.exports?t.exports=r:e.convertString=r}(this)},{}],5:[function(e,t,r){!function(r){"use strict";function n(e,t){e.constructor===String&&(e=a.convertString.UTF8.stringToBytes(e));var r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=o(e),i=8*e.length;n[i>>5]|=128<<24-i%32,n[(i+64>>9<<4)+15]=i;for(var s=0;s>>5]|=e[r]<<24-n%32;return t},u=function(e){for(var t=[],r=0;r<32*e.length;r+=8)t.push(e[r>>>5]>>>24-r%32&255);return t},s=[],f=function(e,t,r){for(var n=e[0],a=e[1],o=e[2],u=e[3],f=e[4],l=e[5],c=e[6],y=e[7],h=0;h<64;h++){if(h<16)s[h]=0|t[r+h];else{var v=s[h-15],g=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,d=s[h-2],p=(d<<15|d>>>17)^(d<<13|d>>>19)^d>>>10;s[h]=g+s[h-7]+p+s[h-16]}var b=f&l^~f&c,w=n&a^n&o^a&o,T=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),O=(f<<26|f>>>6)^(f<<21|f>>>11)^(f<<7|f>>>25),A=y+O+b+i[h]+s[h],B=T+w;y=c,c=l,l=f,f=u+A|0,u=o,o=a,a=n,n=A+B|0}e[0]=e[0]+n|0,e[1]=e[1]+a|0,e[2]=e[2]+o|0,e[3]=e[3]+u|0,e[4]=e[4]+f|0,e[5]=e[5]+l|0,e[6]=e[6]+c|0,e[7]=e[7]+y|0};n.x2=function(e,t){return n(n(e,{asBytes:!0}),t)}}(this)},{"convert-hex":3,"convert-string":4}],"/read.js":[function(e,t,r){(function(r){"use strict";function n(e,t){try{return{value:new DataView(e).getUint32(t),length:4}}catch(e){l.fail(d)}}function a(e,t){return e.length=0,"Offset is negative: "+(t+"")),l.assert(e.byteLength>t,d);var r=void 0,o=1,u=new Uint8Array(e)[t],f=!0,c=!1,h=void 0;try{for(var g,b=p[Symbol.iterator]();!(f=(g=b.next()).done);f=!0){var w=g.value;if(u===w._value)return{value:new w,length:o}}}catch(e){c=!0,h=e}finally{try{!f&&b.return&&b.return()}finally{if(c)throw h}}switch(u){case v.BooleanTupleType._value:var T=n(e,t+o);r=new v.BooleanTupleType(T.value),o+=T.length;break;case v.TupleType._value:var O=i(e,t+o);o+=O.length;var A=n(e,t+o);o+=A.length,r=new v.TupleType({type:O.value,length:A.value});break;case v.StructType._value:l.assert(e.byteLength>t+o,d);var B=new Uint8Array(e),k=B[t+o];o++;for(var m={},S=0;St+o,d);var j=B[t+o];o++,l.assert(e.byteLength>=t+o+j,d);var U=y.toString(B.subarray(t+o,t+o+j));o+=j;var x=i(e,t+o);m[U]=x.value,o+=x.length}r=new v.StructType(m);break;case v.ArrayType._value:var _=i(e,t+o);o+=_.length,r=new v.ArrayType(_.value);break;case v.SetType._value:var V=i(e,t+o);o+=V.length,r=new v.SetType(V.value);break;case v.MapType._value:var P=i(e,t+o);o+=P.length;var I=i(e,t+o);o+=I.length,r=new v.MapType(P.value,I.value);break;case v.EnumType._value:var E=i(e,t+o);o+=E.length,l.assert(e.byteLength>t+o,d);var L=new Uint8Array(e)[t+o];o++;for(var D=[],C=0;Ct+o,d);var F=new Uint8Array(e)[t+o];o++;for(var H=Array(F),q=0;q=t+G,d);var Y=new DataView(e).getUint16(t+o),J=i(e,t+o-Y);r=J.value,o=G;break;default:l.fail("No such type: 0x"+a(new Uint8Array(e)[t].toString(16),2))}return{value:r,length:o}}function o(e){var t=arguments.length<=1||void 0===arguments[1]||arguments[1];l.instanceOf(e,ArrayBuffer);var r=i(e,0),n=r.value,a=r.length;return t&&l.assert(a===e.byteLength,"Did not consume all of the buffer"),n}function u(e){var t=e.buffer,r=e.offset,n=e.count,a=Array(n),i=c.modEight(a.length),o=c.dividedByEight(a.length),u=void 0;u=i?o+1:o,l.assert(t.byteLength>=r+u,d);for(var s=new Uint8Array(t),f=0;f=r+o,d),i=new Int8Array(t)[r];break;case v.ShortType:o=2,l.assert(t.byteLength>=r+o,d);var f=new DataView(t);i=f.getInt16(r);break;case v.IntType:o=4;var c=new DataView(t);i=c.getInt32(r);break;case v.LongType:o=8,l.assert(t.byteLength>=r+o,d);var p=new DataView(t),b=p.getInt32(r),w=p.getUint32(r+4);i=h.add(h.mul(b+"",h.LONG_UPPER_SHIFT),w+"");break;case v.BigIntType:o=2,l.assert(t.byteLength>=r+o,d);var T=new DataView(t),O=T.getUint16(r);l.assert(t.byteLength>=r+o+O,d),i=O?T.getInt8(r+o)+"":"0";for(var A=1;A=r+o,d),i=new Uint8Array(t)[r];break;case v.UnsignedShortType:o=2,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getUint16(r);break;case v.UnsignedIntType:o=4,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getUint32(r);break;case v.UnsignedLongType:case v.DateType:o=8,l.assert(t.byteLength>=r+o,d);var B=new DataView(t),k=B.getUint32(r),m=B.getUint32(r+4);i=h.add(h.mul(k+"",h.LONG_UPPER_SHIFT),m+""),a.constructor===v.DateType&&(i=new Date(+i));break;case v.BigUnsignedIntType:o=2,l.assert(t.byteLength>=r+o,d);var S=new DataView(t),j=S.getUint16(r);l.assert(t.byteLength>=r+o+j,d),i="0";for(var U=0;U=r+o,d),i=new DataView(t).getFloat32(r);break;case v.DoubleType:o=8,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getFloat64(r);break;case v.BooleanType:o=1,l.assert(t.byteLength>=r+o,d);var x=new Uint8Array(t)[r];l.assert(0===x||255===x,"0x"+x.toString(16)+" is an invalid Boolean value"),i=!!x;break;case v.BooleanArrayType:var _=n(t,r);o=_.length;var V=u({buffer:t,offset:r+o,count:_.value});o+=V.length,i=V.value;break;case v.BooleanTupleType:var P=u({buffer:t,offset:r,count:a.length});i=P.value,o=P.length;break;case v.CharType:l.assert(t.byteLength>r,d),i=y.toString(new Uint8Array(t).subarray(r,r+4))[0],o=y.fromString(i).byteLength;break;case v.StringType:var I=new Uint8Array(t);for(o=0;l.assert(t.byteLength>r+o,d),I[r+o];o++);i=y.toString(new Uint8Array(t).subarray(r,r+o)),o++;break;case v.OctetsType:var E=n(t,r);o=E.length;var L=o+E.value;l.assert(t.byteLength>=r+L,d),i=t.slice(r+o,r+L),o=L;break;case v.TupleType:o=0,i=Array(a.length);for(var D=0;D=r+o,d);var ne=new Uint8Array(t)[r];i=a.values[ne],void 0===i&&l.fail("Index "+(ne+"")+" is invalid");break;case v.ChoiceType:o=1,l.assert(t.byteLength>=r+o,d);var ae=new Uint8Array(t)[r],ie=s({buffer:t,offset:r+o,type:a.types[ae]});o+=ie.length,i=ie.value;break;case v.OptionalType:o=1,l.assert(t.byteLength>=r+o,d);var oe=new Uint8Array(t)[r];if(l.assert(0===oe||255===oe,"0x"+oe.toString(16)+" is an invalid Optional byte"),oe){var ue=s({buffer:t,offset:r+o,type:a.type});o+=ue.length,i=ue.value}else i=null;break;case v.PointerType:var se=n(t,r);o=se.length,i=s({buffer:t,offset:se.value,type:a.type}).value;break;default:l.fail("Not a structure type: "+g.inspect(a))}return{value:i,length:o}}function f(e){var t=e.buffer,r=e.type,n=e.offset;l.instanceOf(t,ArrayBuffer),l.instanceOf(r,v.Type),void 0===n&&(n=0),l.instanceOf(n,Number);var a=s({buffer:t,offset:n,type:r}),i=a.value;return i}"/"===r&&(r="");var l=e(r+"/lib/assert.js"),c=e(r+"/lib/bit-math.js"),y=e(r+"/lib/buffer-string.js"),h=e(r+"/lib/strint.js"),v=e(r+"/structure-types.js"),g=e("/lib/util-inspect.js"),d="Buffer is not long enough",p=[v.ByteType,v.ShortType,v.IntType,v.LongType,v.BigIntType,v.UnsignedByteType,v.UnsignedShortType,v.UnsignedIntType,v.UnsignedLongType,v.DateType,v.BigUnsignedIntType,v.FloatType,v.DoubleType,v.BooleanType,v.BooleanArrayType,v.CharType,v.StringType,v.OctetsType];t.exports={_consumeType:i,type:o,value:f}}).call(this,"/")},{"/lib/util-inspect.js":"/lib/util-inspect.js"}],"/structure-types.js":[function(e,t,r){(function(r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){var t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e),t}function u(e,t){if(t&&e.pointers){var r=!0,n=!1,a=void 0;try{for(var i,o=e.pointers[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=h(i.value,2),s=u[0],f=u[1],l=e.length;e.addAll(d.fromBinaryString(s));var c=new ArrayBuffer(4);new DataView(c).setUint32(0,l);var y=!0,v=!1,g=void 0;try{for(var p,b=f[Symbol.iterator]();!(y=(p=b.next()).done);y=!0){var w=p.value;e.setAll(w,c)}}catch(e){v=!0,g=e}finally{try{!y&&b.return&&b.return()}finally{if(v)throw g}}}}catch(e){n=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(n)throw a}}}}function s(e){if(e&&e.constructor===String){var t=+e;if(!isNaN(t))return t}}function f(e,t){v.instanceOf(e,w),v.instanceOf(t,String),(T.gt(t,q)||T.lt(t,"0"))&&v.fail("Value out of range");var r=T.div(t,T.LONG_UPPER_SHIFT),n=T.sub(t,T.mul(r,T.LONG_UPPER_SHIFT)),a=new ArrayBuffer(8),i=new DataView(a);i.setUint32(0,+r),i.setUint32(4,+n),e.addAll(a)}function l(e,t){v.instanceOf(t,Array);var r=k(t.length),n=B(t.length),a=void 0;a=r?n+1:n;for(var i=new ArrayBuffer(a),o=new Uint8Array(i),u=0;u-1;s--,u++)o.setUint8(u,r[s]);r.length&&o.setInt8(2,r[r.length-1]),e.addAll(i)}}],[{key:"_value",get:function(){return 6}}]),t}(x),C=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),t}(U),N=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.integer(t),v.between(0,t,256,"Value out of range");var n=new ArrayBuffer(1);new Uint8Array(n)[0]=t,e.addAll(n)}}],[{key:"_value",get:function(){return 17}}]),t}(C),F=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.integer(t),v.between(0,t,65536,"Value out of range");var n=new ArrayBuffer(2);new DataView(n).setUint16(0,t),e.addAll(n)}}],[{key:"_value",get:function(){return 18}}]),t}(C),H=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.integer(t),v.between(0,t,4294967296,"Value out of range");var n=new ArrayBuffer(4);new DataView(n).setUint32(0,t),e.addAll(n)}}],[{key:"_value",get:function(){return 19}}]),t}(C),q="18446744073709551615",R=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){f(e,t)}}],[{key:"_value",get:function(){return 20}}]),t}(C),M=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(t,Date),f(e,t.getTime()+"")}}],[{key:"_value",get:function(){return 21}}]),t}(U),z=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,String),T.isNegative(t)&&v.fail("Value out of range");var r=[];if(!T.eq(t,"0")){for(;T.ge(t,T.BYTE_SHIFT);){var n=T.quotientRemainderPositive(t,T.BYTE_SHIFT),a=h(n,2),i=a[0],o=a[1];r.push(+o),t=i}r.push(+t),v.twoByteUnsignedInteger(r.length)}var u=new ArrayBuffer(2+r.length),s=new DataView(u);s.setUint16(0,r.length);for(var f=2,l=r.length-1;l>-1;l--,f++)s.setUint8(f,r[l]);e.addAll(u)}}],[{key:"_value",get:function(){return 22}}]),t}(C),G=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),t}(U),Y=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.instanceOf(t,Number);var n=new ArrayBuffer(4);new DataView(n).setFloat32(0,t),e.addAll(n)}}],[{key:"_value",get:function(){return 32}}]),t}(G),J=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.instanceOf(t,Number);var n=new ArrayBuffer(8);new DataView(n).setFloat64(0,t),e.addAll(n)}}],[{key:"_value",get:function(){return 33}}]),t}(G),W=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,Boolean),t?e.add(255):e.add(0)}}],[{key:"_value",get:function(){return 48}}]),t}(U),X=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this));return v.fourByteUnsignedInteger(e),r.length=e,r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 49}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&e.addAll(o(this.length))}},{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,Array),t.length!==this.length&&v.fail("Length does not match"),l(e,t)}}]),t}(U),$=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(t,Array),v.fourByteUnsignedInteger(t.length),e.addAll(o(t.length)),l(e,t)}}],[{key:"_value",get:function(){return 50}}]),t}(U),Q=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,String),v.assert(1===t.length,"String must contain only 1 character"),e.addAll(d.fromString(t))}}],[{key:"_value",get:function(){return 64}}]),t}(U),K=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,String);var r=d.fromString(t);e.addAll(r),e.add(0)}}],[{key:"_value",get:function(){return 65}}]),t}(U),Z=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,ArrayBuffer),v.fourByteUnsignedInteger(t.byteLength),e.addAll(o(t.byteLength)),e.addAll(t)}}],[{key:"_value",get:function(){return 66}}]),t}(U),ee=function(e){function t(e){var r=e.type,a=e.length;i(this,t);var o=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(r,j),v.fourByteUnsignedInteger(a),o.type=r,o.length=a,o}return a(t,e),y(t,null,[{key:"_value",get:function(){return 80}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&(this.type.addToBuffer(e),e.addAll(o(this.length)))}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Array),t.length!==this.length&&v.fail("Length does not match: expected "+(this.length+"")+" but got "+t.length);var n=!0,a=!1,i=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var f=o.value;this.type.writeValue(e,f,!1)}}catch(e){a=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(a)throw i}}u(e,r)}}]),t}(U),te="name",re="type",ne="buffer",ae=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this));v.instanceOf(e,Object);var a=0;for(var o in e)a++;try{v.byteUnsignedInteger(a)}catch(e){v.fail(a+" fields is too many")}r.fields=Array(a);var u=0;for(var s in e){var f=d.fromString(s);try{v.byteUnsignedInteger(f.byteLength)}catch(e){v.fail("Field name "+s+" is too long")}var l=e[s];try{v.instanceOf(l,j)}catch(e){v.fail(l+" is not a valid field type")}var c={};c[te]=s,c[re]=l,c[ne]=f,r.fields[u]=c,u++}return r.fields.sort(function(e,t){return e[te]t[te]?1:void 0}),r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 81}}]),y(t,[{key:"addToBuffer",value:function(e){if(c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)){e.add(this.fields.length);var r=!0,n=!1,a=void 0;try{for(var i,o=this.fields[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=i.value,s=u[ne];e.add(s.byteLength),e.addAll(s),u[re].addToBuffer(e)}}catch(e){n=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(n)throw a}}}}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Object);var n=!0,a=!1,i=void 0;try{for(var o,s=this.fields[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var f=o.value,l=t[f[te]];void 0===l&&v.fail("Value for field "+f[te]+" missing"),f[re].writeValue(e,l,!1)}}catch(e){a=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(a)throw i}}u(e,r)}}]),t}(U),ie=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(e,j),r.type=e,r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 82}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&this.type.addToBuffer(e)}},{key:"_writeValue",value:function(e,t,r){v.instanceOf(e,w),v.fourByteUnsignedInteger(t.length),e.addAll(o(t.length));var n=!0,a=!1,i=void 0;try{for(var s,f=t[Symbol.iterator]();!(n=(s=f.next()).done);n=!0){var l=s.value;this.type.writeValue(e,l,!1)}}catch(e){a=!0,i=e}finally{try{!n&&f.return&&f.return()}finally{if(a)throw i}}u(e,r)}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,Array),this._writeValue(e,t,r)}}]),t}(U),oe=function(e){function t(e){return i(this,t),n(this,Object.getPrototypeOf(t).call(this,e))}return a(t,e),y(t,null,[{key:"_value",get:function(){return 83}}]),y(t,[{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,Set),t.length=t.size,this._writeValue(e,t,r)}}]),t}(ie),ue=function(e){function t(e,r){i(this,t);var a=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(e,j),v.instanceOf(r,j),a.keyType=e,a.valueType=r,a}return a(t,e),y(t,null,[{key:"_value",get:function(){return 84}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&(this.keyType.addToBuffer(e),this.valueType.addToBuffer(e))}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Map),v.fourByteUnsignedInteger(t.size),e.addAll(o(t.size));var n=!0,a=!1,i=void 0;try{for(var s,f=t[Symbol.iterator]();!(n=(s=f.next()).done);n=!0){var l=h(s.value,2),c=l[0],y=l[1];this.keyType.writeValue(e,c,!1),this.valueType.writeValue(e,y,!1)}}catch(e){a=!0,i=e}finally{try{!n&&f.return&&f.return()}finally{if(a)throw i}}u(e,r)}}]),t}(U),se=function(e){function t(e){var r=e.type,a=e.values;i(this,t);var o=n(this,Object.getPrototypeOf(t).call(this));v.instanceOf(r,U),v.instanceOf(a,Array);try{v.byteUnsignedInteger(a.length)}catch(e){v.fail(a.length+" values is too many")}for(var u=new Map,s=0;s=200&&t.status<300||304===t.status;r?e[o]=t.response:e.text=t.statusText,n(t.status,t.statusText,e,t.getAllResponseHeaders())}),t.open(i,a,s),t.responseType=o;for(var f in r)r.hasOwnProperty(f)&&t.setRequestHeader(f,r[f]);t.send(u)},abort:function(){t&&t.abort()}}}})}(jQuery)},{}],"/client-side/common.js":[function(e,t,r){"use strict";var n=e("/lib/assert.js");if(n.instanceOf(window.Map,Function),n.instanceOf(window.Set,Function),n.instanceOf(window.ArrayBuffer,Function),n.instanceOf(window.Uint8Array,Function),n.instanceOf(window.Symbol,Function),e("/client-side/binary-ajax.js"),void 0===window.sb)window.sb=e("/structure-types.js");else if(!(window.sb instanceof Object))throw Error("window.sb is already defined")},{"/client-side/binary-ajax.js":"/client-side/binary-ajax.js","/lib/assert.js":"/lib/assert.js","/structure-types.js":"/structure-types.js"}],"/config.js":[function(e,t,r){(function(r){"use strict";"/"===r&&(r="");var n=e(r+"/lib/assert.js"),a=e("base64-js"),i=7;n.between(0,i,65536);var o=2,u=new ArrayBuffer(o);new DataView(u).setUint16(0,i);var s=a.fromByteArray(new Uint8Array(u));t.exports={VERSION_STRING:s}}).call(this,"/")},{"base64-js":2}],"/lib/assert.js":[function(e,t,r){"use strict";var n=e("/lib/util-inspect.js"),a={instanceOf:function(e,t){t instanceof Array||(t=[t]);var r=!1,a=!0,i=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;if(e instanceof f||void 0!==e&&null!==e&&e.constructor===f){r=!0;break}}}catch(e){i=!0,o=e}finally{try{!a&&s.return&&s.return()}finally{if(i)throw o}}if(!r)throw new TypeError(n.inspect(e)+" is not an instance of "+t.map(function(e){return e.name}).join(" or "))},integer:function(e){if(a.instanceOf(e,Number),!Number.isSafeInteger(e))throw new RangeError(n.inspect(e)+" is not an integer")},between:function(e,t,r,a){if(t=r){var i=n.inspect(t)+" is not in ["+n.inspect(e)+","+n.inspect(r)+")";throw void 0===a?new RangeError(i):new RangeError(a+" ("+i+")")}},byteUnsignedInteger:function(e){a.integer(e),a.between(0,e,256)},fourByteUnsignedInteger:function(e){a.integer(e),a.between(0,e,4294967296)},fail:function(e){throw Error(e)},assert:function(e,t){e||a.fail(t)},throws:function(e,t){var r=!0;try{e(),r=!1}catch(e){void 0!==t&&a.message(e,t)}a.assert(r,"Should throw an error")},equal:function(e,t){var r=new RangeError("Expected "+n.inspect(t)+" but got "+n.inspect(e));if(t&&t.constructor===Object){for(var i in t)if(t.hasOwnProperty(i))try{a.equal(e[i],t[i])}catch(e){throw r}}else if(t&&t.constructor===Array){if(!e||e.constructor!==Array)throw r;try{a.equal(e.length,t.length)}catch(e){throw r}for(var o=0;o>>3},modEight:function(e){return 7&e}}},{}],"/lib/buffer-string.js":[function(e,t,r){(function(r){"use strict";var n=e(r+"/assert.js"),a=e(r+"/growable-buffer.js"),i=4096;t.exports={toString:function(e){e&&e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),n.instanceOf(e,Uint8Array);for(var t=[],r=0;r239?4:a>223?3:a>191?2:1;if(r+u<=e.length){var s=void 0,f=void 0,l=void 0,c=void 0;switch(u){case 1:a<128&&(o=a);break;case 2:s=e[r+1],128===(192&s)&&(c=(31&a)<<6|63&s,c>127&&(o=c));break;case 3:s=e[r+1],f=e[r+2],128===(192&s)&&128===(192&f)&&(c=(15&a)<<12|(63&s)<<6|63&f,c>2047&&(c<55296||c>57343)&&(o=c));break;case 4:s=e[r+1],f=e[r+2],l=e[r+3],128===(192&s)&&128===(192&f)&&128===(192&l)&&(c=(15&a)<<18|(63&s)<<12|(63&f)<<6|63&l,c>65535&&c<1114112&&(o=c))}}void 0===o?(o=65533,u=1):o>65535&&(o-=65536,t.push(o>>>10&1023|55296),o=56320|1023&o),t.push(o),r+=u}for(var y="",h=0;h>6),t.add(128|63&l)):l<55296||l>=57344?(t.add(224|l>>12),t.add(128|l>>6&63),t.add(128|63&l)):(l=65536+((1023&l)<<10|1023&l),t.add(240|l>>18),t.add(128|l>>12&63),t.add(128|l>>6&63),t.add(128|63&l))}}catch(e){i=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return t.toBuffer()},toBinaryString:function(e){n.instanceOf(e,ArrayBuffer);var t="",r=new Uint8Array(e),a=!0,i=!1,o=void 0;try{for(var u,s=r[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;t+=String.fromCharCode(f)}}catch(e){i=!0,o=e}finally{try{!a&&s.return&&s.return()}finally{if(i)throw o}}return t},fromBinaryString:function(e){n.instanceOf(e,String);for(var t=new ArrayBuffer(e.length),r=new Uint8Array(t),a=0;athis.buffer.byteLength){var t=new ArrayBuffer(e<<1);new Uint8Array(t).set(new Uint8Array(this.buffer).subarray(0,this.size)),this.buffer=t}return this}},{key:"set",value:function(e,t){i.integer(e),i.integer(t),i.between(0,e,this.size,"Index out of bounds: "+(e+"")),i.between(0,t,256,"Not a byte: "+(t+""));var r=new Uint8Array(this.buffer);return r[e]=t,this}},{key:"setAll",value:function(e,t){i.instanceOf(t,ArrayBuffer),i.integer(e),i.between(0,e,this.size-t.byteLength+1,"Index out of bounds: "+(e+"")),new Uint8Array(this.buffer).set(new Uint8Array(t),e)}},{key:"get",value:function(e){return i.integer(e),i.between(0,e,this.size,"Index out of bounds: "+(e+"")),new Uint8Array(this.buffer)[e]}},{key:"add",value:function(e){var t=this.size,r=t+1;this.grow(r),this.size=r;var n=new Uint8Array(this.buffer);return n[t]=e,this}},{key:"addAll",value:function(e){i.instanceOf(e,ArrayBuffer);var t=this.size,r=this.size+e.byteLength;return this.grow(r),this.size=r,new Uint8Array(this.buffer).set(new Uint8Array(e),t),this}},{key:"toBuffer",value:function(){return this.buffer.slice(0,this.size)}},{key:"length",get:function(){return this.size}},{key:"rawBuffer",get:function(){return this.buffer}}]),e}();t.exports=u}).call(this,"/lib")},{}],"/lib/strint.js":[function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},a={};!function(){function e(e,t){return B(e)===B(t)}function t(e,t){for(;t>0;)e+="0",t--;return e}function r(e){f(e,"string")}function i(e){r(e),s(e,B,"isPositive")}function o(e){f(e,"number")}function u(e){if(f(e,"number"),e<0)throw Error("Expected a positive number: "+e)}function s(e,t,r){if(!t.call(null,e))throw Error("Condition "+r+" failed for value "+e)}function f(e,t){if((void 0===e?"undefined":n(e))!==t)throw Error("Not a "+t+": "+e)}var l=a.subPositive=function(e,t){if(i(e),i(t),!O(e,t))throw Error("x must be greater or equal to y");for(var r=Math.max(e.length,t.length),n="",a=0,o=0,u=0;u=10;)l-=10,a++;0===l?o++:(n=l+""+P(n,o),o=0)}return a>0&&(n=a+""+P(n,o)),n},y=a.add=function(e,t){if(r(e),r(t),B(e)&&B(t))return c(e,t);if(k(e)&&k(t))return j(c(m(e),m(t)));if(T(m(e),m(t))){var n=e;e=t,t=n}var a=l(m(e),m(t));return B(e)?a:j(a)},h=a.sub=function(e,t){return r(e),r(t),y(e,j(t))},v=a.timesDigit=function(e,t){i(e),o(t);for(var r="",n=E(e),a=0,u=0,s=0;s=10;)f-=10,a++;0===f?u++:(r=f+""+P(r,u),u=0)}return a>0&&(r=a+""+P(r,u)),0===r.length?"0":r},g=a.mulPositive=function(e,r){i(e),i(r);for(var n="0",a=E(r),o=0;o=E(e)?"0":e.charAt(e.length-t-1)},E=function(e){return k(e)?e.length-1:e.length}}(),a.LONG_UPPER_SHIFT="4294967296",t.exports=a},{}],"/lib/util-inspect.js":[function(e,t,r){"use strict";r.inspect=function(e){if(void 0===e)return"undefined";if(null===e||e.constructor===Object||e.constructor===Array||e.constructor===String||e.constructor===Number||e.constructor===Boolean||e.constructor===Date)return JSON.stringify(e);if(e.constructor===Set){for(var t="Set {",n=e.values(),a=n.next();!a.done;)t+=r.inspect(a.value),a=n.next(),a.done||(t+=", ");return t+"}"}if(e.constructor===Map){for(var i="Map {",o=e.entries(),u=o.next();!u.done;)i+=r.inspect(u.value[0]),i+=" => ",i+=r.inspect(u.value[1]),u=o.next(),u.done||(i+=", ");return i+"}"}return e.constructor.name?e.constructor.name+" "+JSON.stringify(e):JSON.stringify(e)}},{}],1:[function(e,t,r){"use strict";!function(){e("/client-side/common.js");var t=e("/lib/assert.js");window.sb.upload=function(e,r){var n=e.type,a=e.value;if(t.instanceOf(n,window.sb.Type),t.instanceOf(r,Object),"POST"!==r.type&&"POST"!==r.method)throw Error("Must use POST when uploading");r.processData=!1,r.data=n.valueBuffer(a),$.ajax(r)}}(),function(){function t(){var e={};for(var t in i)e[t]={sig:i[t].sig,type:n.fromByteArray(new Uint8Array(i[t].type.toBuffer()))};localStorage.typeCache=JSON.stringify(e)}e("/client-side/common.js");var r=e("/lib/assert.js"),n=e("base64-js"),a=e("/read.js"),i={};if(void 0===localStorage.typeCache)t();else{var o=JSON.parse(localStorage.typeCache);for(var u in o)i[u]={sig:o[u].sig,type:a.type(new Uint8Array(n.toByteArray(o[u].type)).buffer)}}window.sb.download=function(e,n){function o(e,t,r){if(s){s instanceof Array||(s=[s]);var n=!0,a=!1,i=void 0;try{for(var o,u=s[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var f=o.value;f(e,t,r)}}catch(e){a=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(a)throw i}}}}r.instanceOf(e,String),r.instanceOf(n,Object),n.processData=!1,n.dataType="arraybuffer";var u=!1;i[e]&&(u=!0,n.headers||(n.headers={}),n.headers.sig=i[e].sig);var s=n.success;n.success=function(r,n,s){var f=s.getResponseHeader("sig");if(u&&i[e].sig===f){var l=i[e].type,c=a.value({buffer:r,type:l});o(c,n,s)}else{var y=a._consumeType(r,0),h=a.value({buffer:r,offset:y.length,type:y.value}),v=y.value;i[e]={sig:f,type:v},t(),o(h,n,s)}},$.ajax(n)}}()},{"/client-side/common.js":"/client-side/common.js","/lib/assert.js":"/lib/assert.js","/read.js":"/read.js","base64-js":2}],2:[function(e,t,r){"use strict";function n(){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t0)throw Error("Invalid string. Length must be a multiple of 4");i="="===e[u-2]?2:"="===e[u-1]?1:0,o=new l(3*u/4-i),n=i>0?u-4:u;var s=0;for(t=0,r=0;t>16&255,o[s++]=a>>8&255,o[s++]=255&a;return 2===i?(a=f[e.charCodeAt(t)]<<2|f[e.charCodeAt(t+1)]>>4,o[s++]=255&a):1===i&&(a=f[e.charCodeAt(t)]<<10|f[e.charCodeAt(t+1)]<<4|f[e.charCodeAt(t+2)]>>2,o[s++]=a>>8&255,o[s++]=255&a),o}function i(e){return s[e>>18&63]+s[e>>12&63]+s[e>>6&63]+s[63&e]}function o(e,t,r){for(var n,a=[],o=t;ol?l:f+u));return 1===n?(t=e[r-1],a+=s[t>>2],a+=s[t<<4&63],a+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],a+=s[t>>10],a+=s[t>>4&63],a+=s[t<<2&63],a+="="),i.push(a),i.join("")}r.toByteArray=a,r.fromByteArray=u;var s=[],f=[],l="undefined"!=typeof Uint8Array?Uint8Array:Array;n()},{}],3:[function(e,t,r){!function(e){"use strict";function r(e){return e.map(function(e){return n(e.toString(16),2)}).join("")}function n(e,t){return e.length>t?e:Array(t-e.length+1).join("0")+e}var a={bytesToHex:function(e){return r(e)},hexToBytes:function(e){if(e.length%2===1)throw Error("hexToBytes can't have a string with an odd number of characters.");return 0===e.indexOf("0x")&&(e=e.slice(2)),e.match(/../g).map(function(e){return parseInt(e,16)})}};void 0!==t&&t.exports?t.exports=a:e.convertHex=a}(this)},{}],4:[function(e,t,r){!function(e){"use strict";var r={bytesToString:function(e){return e.map(function(e){return String.fromCharCode(e)}).join("")},stringToBytes:function(e){return e.split("").map(function(e){return e.charCodeAt(0)})}};r.UTF8={bytesToString:function(e){return decodeURIComponent(escape(r.bytesToString(e)))},stringToBytes:function(e){return r.stringToBytes(unescape(encodeURIComponent(e)))}},void 0!==t&&t.exports?t.exports=r:e.convertString=r}(this)},{}],5:[function(e,t,r){!function(r){"use strict";function n(e,t){e.constructor===String&&(e=a.convertString.UTF8.stringToBytes(e));var r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=o(e),i=8*e.length;n[i>>5]|=128<<24-i%32,n[(i+64>>9<<4)+15]=i;for(var s=0;s>>5]|=e[r]<<24-n%32;return t},u=function(e){for(var t=[],r=0;r<32*e.length;r+=8)t.push(e[r>>>5]>>>24-r%32&255);return t},s=[],f=function(e,t,r){for(var n=e[0],a=e[1],o=e[2],u=e[3],f=e[4],l=e[5],c=e[6],y=e[7],h=0;h<64;h++){if(h<16)s[h]=0|t[r+h];else{var v=s[h-15],g=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,d=s[h-2],p=(d<<15|d>>>17)^(d<<13|d>>>19)^d>>>10;s[h]=g+s[h-7]+p+s[h-16]}var b=f&l^~f&c,w=n&a^n&o^a&o,T=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),O=(f<<26|f>>>6)^(f<<21|f>>>11)^(f<<7|f>>>25),A=y+O+b+i[h]+s[h],k=T+w;y=c,c=l,l=f,f=u+A|0,u=o,o=a,a=n,n=A+k|0}e[0]=e[0]+n|0,e[1]=e[1]+a|0,e[2]=e[2]+o|0,e[3]=e[3]+u|0,e[4]=e[4]+f|0,e[5]=e[5]+l|0,e[6]=e[6]+c|0,e[7]=e[7]+y|0};n.x2=function(e,t){return n(n(e,{asBytes:!0}),t)}}(this)},{"convert-hex":3,"convert-string":4}],"/read.js":[function(e,t,r){(function(r){"use strict";function n(e,t){try{return{value:new DataView(e).getUint32(t),length:4}}catch(e){l.fail(d)}}function a(e,t){return e.length=0,"Offset is negative: "+(t+"")),l.assert(e.byteLength>t,d);var r=void 0,o=1;switch(new Uint8Array(e)[t]){case v.ByteType._value:r=new v.ByteType;break;case v.ShortType._value:r=new v.ShortType;break;case v.IntType._value:r=new v.IntType;break;case v.LongType._value:r=new v.LongType;break;case v.UnsignedByteType._value:r=new v.UnsignedByteType;break;case v.UnsignedShortType._value:r=new v.UnsignedShortType;break;case v.UnsignedIntType._value:r=new v.UnsignedIntType;break;case v.UnsignedLongType._value:r=new v.UnsignedLongType;break;case v.DateType._value:r=new v.DateType;break;case v.FloatType._value:r=new v.FloatType;break;case v.DoubleType._value:r=new v.DoubleType;break;case v.BooleanType._value:r=new v.BooleanType;break;case v.BooleanTupleType._value:var u=n(e,t+o);r=new v.BooleanTupleType(u.value),o+=u.length;break;case v.BooleanArrayType._value:r=new v.BooleanArrayType;break;case v.CharType._value:r=new v.CharType;break;case v.StringType._value:r=new v.StringType;break;case v.OctetsType._value:r=new v.OctetsType;break;case v.TupleType._value:var f=i(e,t+o);o+=f.length;var c=n(e,t+o);o+=c.length,r=new v.TupleType({type:f.value,length:c.value});break;case v.StructType._value:l.assert(e.byteLength>t+o,d);var h=new Uint8Array(e),g=h[t+o];o++;for(var p={},b=0;bt+o,d);var w=h[t+o];o++,l.assert(e.byteLength>=t+o+w,d);var T=y.toString(h.subarray(t+o,t+o+w));o+=w;var O=i(e,t+o);p[T]=O.value,o+=O.length}r=new v.StructType(p);break;case v.ArrayType._value:var A=i(e,t+o);o+=A.length,r=new v.ArrayType(A.value);break;case v.SetType._value:var k=i(e,t+o);o+=k.length,r=new v.SetType(k.value);break;case v.MapType._value:var B=i(e,t+o);o+=B.length;var m=i(e,t+o);o+=m.length,r=new v.MapType(B.value,m.value);break;case v.EnumType._value:var j=i(e,t+o);o+=j.length,l.assert(e.byteLength>t+o,d);var S=new Uint8Array(e)[t+o];o++;for(var U=[],_=0;_t+o,d);var P=new Uint8Array(e)[t+o];o++;for(var V=Array(P),E=0;E=t+C,d);var N=new DataView(e).getUint16(t+o),F=i(e,t+o-N);r=F.value,o=C;break;default:l.fail("No such type: 0x"+a(new Uint8Array(e)[t].toString(16),2))}return{value:r,length:o}}function o(e){var t=arguments.length<=1||void 0===arguments[1]||arguments[1];l.instanceOf(e,ArrayBuffer);var r=i(e,0),n=r.value,a=r.length;return t&&l.assert(a===e.byteLength,"Did not consume all of the buffer"),n}function u(e){var t=e.buffer,r=e.offset,n=e.count,a=Array(n),i=c.modEight(a.length),o=c.dividedByEight(a.length),u=void 0;u=i?o+1:o,l.assert(t.byteLength>=r+u,d);for(var s=new Uint8Array(t),f=0;f=r+o,d),i=new Int8Array(t)[r];break;case v.ShortType:o=2,l.assert(t.byteLength>=r+o,d);var f=new DataView(t);i=f.getInt16(r);break;case v.IntType:o=4;var c=new DataView(t);i=c.getInt32(r);break;case v.LongType:o=8,l.assert(t.byteLength>=r+o,d);var p=new DataView(t),b=p.getInt32(r),w=p.getUint32(r+4);i=h.add(h.mul(b+"",h.LONG_UPPER_SHIFT),w+"");break;case v.UnsignedByteType:o=1,l.assert(t.byteLength>=r+o,d),i=new Uint8Array(t)[r];break;case v.UnsignedShortType:o=2,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getUint16(r);break;case v.UnsignedIntType:o=4,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getUint32(r);break;case v.UnsignedLongType:case v.DateType:o=8,l.assert(t.byteLength>=r+o,d);var T=new DataView(t),O=T.getUint32(r),A=T.getUint32(r+4);i=h.add(h.mul(O+"",h.LONG_UPPER_SHIFT),A+""),a.constructor===v.DateType&&(i=new Date((+i)));break;case v.FloatType:o=4,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getFloat32(r);break;case v.DoubleType:o=8,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getFloat64(r);break;case v.BooleanType:o=1,l.assert(t.byteLength>=r+o,d);var k=new Uint8Array(t)[r];l.assert(0===k||255===k,"0x"+k.toString(16)+" is an invalid Boolean value"),i=!!k;break;case v.BooleanArrayType:var B=n(t,r);o=B.length;var m=u({buffer:t,offset:r+o,count:B.value});o+=m.length,i=m.value;break;case v.BooleanTupleType:var j=u({buffer:t,offset:r,count:a.length});i=j.value,o=j.length;break;case v.CharType:l.assert(t.byteLength>r,d),i=y.toString(new Uint8Array(t).subarray(r,r+4))[0],o=y.fromString(i).byteLength;break;case v.StringType:var S=new Uint8Array(t);for(o=0;l.assert(t.byteLength>r+o,d),S[r+o];o++);i=y.toString(new Uint8Array(t).subarray(r,r+o)),o++;break;case v.OctetsType:var U=n(t,r);o=U.length;var _=o+U.value;l.assert(t.byteLength>=r+_,d),i=t.slice(r+o,r+_),o=_;break;case v.TupleType:o=0,i=Array(a.length);for(var x=0;x=r+o,d);var Q=new Uint8Array(t)[r];i=a.values[Q],void 0===i&&l.fail("Index "+(Q+"")+" is invalid");break;case v.ChoiceType:o=1,l.assert(t.byteLength>=r+o,d);var K=new Uint8Array(t)[r],Z=s({buffer:t,offset:r+o,type:a.types[K]});o+=Z.length,i=Z.value;break;case v.OptionalType:o=1,l.assert(t.byteLength>=r+o,d);var ee=new Uint8Array(t)[r];if(l.assert(0===ee||255===ee,"0x"+ee.toString(16)+" is an invalid Optional byte"),ee){var te=s({buffer:t,offset:r+o,type:a.type});o+=te.length,i=te.value}else i=null;break;case v.PointerType:var re=n(t,r);o=re.length,i=s({buffer:t,offset:re.value,type:a.type}).value;break;default:l.fail("Not a structure type: "+g.inspect(a))}return{value:i,length:o}}function f(e){var t=e.buffer,r=e.type,n=e.offset;l.instanceOf(t,ArrayBuffer),l.instanceOf(r,v.Type),void 0===n&&(n=0),l.instanceOf(n,Number);var a=s({buffer:t,offset:n,type:r}),i=a.value;return i}"/"===r&&(r="");var l=e(r+"/lib/assert.js"),c=e(r+"/lib/bit-math.js"),y=e(r+"/lib/buffer-string.js"),h=e(r+"/lib/strint.js"),v=e(r+"/structure-types.js"),g=e("/lib/util-inspect.js"),d="Buffer is not long enough";t.exports={_consumeType:i,type:o,value:f}}).call(this,"/")},{"/lib/util-inspect.js":"/lib/util-inspect.js"}],"/structure-types.js":[function(e,t,r){(function(r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){var t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e),t}function u(e,t){if(t&&e.pointers){var r=!0,n=!1,a=void 0;try{for(var i,o=e.pointers[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=h(i.value,2),s=u[0],f=u[1],l=e.length;e.addAll(d.fromBinaryString(s));var c=new ArrayBuffer(4);new DataView(c).setUint32(0,l);var y=!0,v=!1,g=void 0;try{for(var p,b=f[Symbol.iterator]();!(y=(p=b.next()).done);y=!0){var w=p.value;e.setAll(w,c)}}catch(e){v=!0,g=e}finally{try{!y&&b.return&&b.return()}finally{if(v)throw g}}}}catch(e){n=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(n)throw a}}}}function s(e){if(e&&e.constructor===String){var t=+e;if(!isNaN(t))return t}}function f(e,t){v.instanceOf(e,w),v.instanceOf(t,String),(T.gt(t,"18446744073709551615")||T.lt(t,"0"))&&v.fail("Value out of range");var r=T.div(t,T.LONG_UPPER_SHIFT),n=T.sub(t,T.mul(r,T.LONG_UPPER_SHIFT)),a=new ArrayBuffer(8),i=new DataView(a);i.setUint32(0,+r),i.setUint32(4,+n),e.addAll(a)}function l(e,t){v.instanceOf(t,Array);var r=B(t.length),n=k(t.length),a=void 0;a=r?n+1:n;for(var i=new ArrayBuffer(a),o=new Uint8Array(i),u=0;ut[X]?1:void 0}),r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 81}}]),y(t,[{key:"addToBuffer",value:function(e){if(c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)){e.add(this.fields.length);var r=!0,n=!1,a=void 0;try{for(var i,o=this.fields[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=i.value,s=u[Q];e.add(s.byteLength),e.addAll(s),u[Y].addToBuffer(e)}}catch(e){n=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(n)throw a}}}}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Object);var n=!0,a=!1,i=void 0;try{for(var o,s=this.fields[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var f=o.value,l=t[f[X]];void 0===l&&v.fail("Value for field "+f[X]+" missing"),f[Y].writeValue(e,l,!1)}}catch(e){a=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(a)throw i}}u(e,r)}}]),t}(S),Z=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(e,j),r.type=e,r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 82}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&this.type.addToBuffer(e)}},{key:"_writeValue",value:function(e,t,r){v.instanceOf(e,w),v.fourByteUnsignedInteger(t.length),e.addAll(o(t.length));var n=!0,a=!1,i=void 0;try{for(var s,f=t[Symbol.iterator]();!(n=(s=f.next()).done);n=!0){var l=s.value;this.type.writeValue(e,l,!1)}}catch(e){a=!0,i=e}finally{try{!n&&f.return&&f.return()}finally{if(a)throw i}}u(e,r)}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,Array),this._writeValue(e,t,r)}}]),t}(S),ee=function(e){function t(e){return i(this,t),n(this,Object.getPrototypeOf(t).call(this,e))}return a(t,e),y(t,null,[{key:"_value",get:function(){return 83}}]),y(t,[{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,Set),t.length=t.size,this._writeValue(e,t,r)}}]),t}(Z),te=function(e){function t(e,r){i(this,t);var a=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(e,j),v.instanceOf(r,j),a.keyType=e,a.valueType=r,a}return a(t,e),y(t,null,[{key:"_value",get:function(){return 84}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&(this.keyType.addToBuffer(e),this.valueType.addToBuffer(e))}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Map),v.fourByteUnsignedInteger(t.size),e.addAll(o(t.size));var n=!0,a=!1,i=void 0;try{for(var s,f=t[Symbol.iterator]();!(n=(s=f.next()).done);n=!0){var l=h(s.value,2),c=l[0],y=l[1];this.keyType.writeValue(e,c,!1),this.valueType.writeValue(e,y,!1)}}catch(e){a=!0,i=e}finally{try{!n&&f.return&&f.return()}finally{if(a)throw i}}u(e,r)}}]),t}(S),re=function(e){function t(e){var r=e.type,a=e.values;i(this,t);var o=n(this,Object.getPrototypeOf(t).call(this));v.instanceOf(r,S),v.instanceOf(a,Array);try{v.byteUnsignedInteger(a.length)}catch(e){v.fail(a.length+" values is too many")}for(var u=new Map,s=0;s=200&&t.status<300||304===t.status;r?e[o]=t.response:e.text=t.statusText,n(t.status,t.statusText,e,t.getAllResponseHeaders())}),t.open(i,a,s),t.responseType=o;for(var f in r)r.hasOwnProperty(f)&&t.setRequestHeader(f,r[f]);t.send(u)},abort:function(){t&&t.abort()}}}})}(jQuery)},{}],"/client-side/common.js":[function(e,t,r){"use strict";var n=e("/lib/assert.js");if(n.instanceOf(window.Map,Function),n.instanceOf(window.Set,Function),n.instanceOf(window.ArrayBuffer,Function),n.instanceOf(window.Uint8Array,Function),n.instanceOf(window.Symbol,Function),e("/client-side/binary-ajax.js"),void 0===window.sb)window.sb=e("/structure-types.js");else if(!(window.sb instanceof Object))throw Error("window.sb is already defined")},{"/client-side/binary-ajax.js":"/client-side/binary-ajax.js","/lib/assert.js":"/lib/assert.js","/structure-types.js":"/structure-types.js"}],"/config.js":[function(e,t,r){(function(r){"use strict";"/"===r&&(r="");var n=e(r+"/lib/assert.js"),a=e("base64-js"),i=8;n.between(0,i,65536);var o=2,u=new ArrayBuffer(o);new DataView(u).setUint16(0,i);var s=a.fromByteArray(new Uint8Array(u));t.exports={VERSION_STRING:s}}).call(this,"/")},{"base64-js":2}],"/lib/assert.js":[function(e,t,r){"use strict";var n=e("/lib/util-inspect.js"),a={instanceOf:function(e,t){t instanceof Array||(t=[t]);var r=!1,a=!0,i=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;if(e instanceof f||void 0!==e&&null!==e&&e.constructor===f){r=!0;break}}}catch(e){i=!0,o=e}finally{try{!a&&s.return&&s.return()}finally{if(i)throw o}}if(!r)throw new TypeError(n.inspect(e)+" is not an instance of "+t.map(function(e){return e.name}).join(" or "))},integer:function(e){if(a.instanceOf(e,Number),!Number.isSafeInteger(e))throw new RangeError(n.inspect(e)+" is not an integer")},between:function(e,t,r,a){if(t=r){var i=n.inspect(t)+" is not in ["+n.inspect(e)+","+n.inspect(r)+")";throw void 0===a?new RangeError(i):new RangeError(a+" ("+i+")")}},byteUnsignedInteger:function(e){a.integer(e),a.between(0,e,256)},twoByteUnsignedInteger:function(e){a.integer(e),a.between(0,e,65536)},fourByteUnsignedInteger:function(e){a.integer(e),a.between(0,e,4294967296)},fail:function(e){throw Error(e)},assert:function(e,t){e||a.fail(t)},throws:function(e,t){var r=!0;try{e(),r=!1}catch(e){void 0!==t&&a.message(e,t)}a.assert(r,"Should throw an error")},equal:function(e,t){var r=new RangeError("Expected "+n.inspect(t)+" but got "+n.inspect(e));if(t&&t.constructor===Object){for(var i in t)if(t.hasOwnProperty(i))try{a.equal(e[i],t[i])}catch(e){throw r}}else if(t&&t.constructor===Array){if(!e||e.constructor!==Array)throw r;try{a.equal(e.length,t.length)}catch(e){throw r}for(var o=0;o>>3},modEight:function(e){return 7&e}}},{}],"/lib/buffer-string.js":[function(e,t,r){(function(r){"use strict";var n=e(r+"/assert.js"),a=e(r+"/growable-buffer.js"),i=4096;t.exports={toString:function(e){e&&e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),n.instanceOf(e,Uint8Array);for(var t=[],r=0;r239?4:a>223?3:a>191?2:1;if(r+u<=e.length){var s=void 0,f=void 0,l=void 0,c=void 0;switch(u){case 1:a<128&&(o=a);break;case 2:s=e[r+1],128===(192&s)&&(c=(31&a)<<6|63&s,c>127&&(o=c));break;case 3:s=e[r+1],f=e[r+2],128===(192&s)&&128===(192&f)&&(c=(15&a)<<12|(63&s)<<6|63&f,c>2047&&(c<55296||c>57343)&&(o=c));break;case 4:s=e[r+1],f=e[r+2],l=e[r+3],128===(192&s)&&128===(192&f)&&128===(192&l)&&(c=(15&a)<<18|(63&s)<<12|(63&f)<<6|63&l,c>65535&&c<1114112&&(o=c))}}void 0===o?(o=65533,u=1):o>65535&&(o-=65536,t.push(o>>>10&1023|55296),o=56320|1023&o),t.push(o),r+=u}for(var y="",h=0;h>6),t.add(128|63&l)):l<55296||l>=57344?(t.add(224|l>>12),t.add(128|l>>6&63),t.add(128|63&l)):(l=65536+((1023&l)<<10|1023&l),t.add(240|l>>18),t.add(128|l>>12&63),t.add(128|l>>6&63),t.add(128|63&l))}}catch(e){i=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return t.toBuffer()},toBinaryString:function(e){n.instanceOf(e,ArrayBuffer);var t="",r=new Uint8Array(e),a=!0,i=!1,o=void 0;try{for(var u,s=r[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;t+=String.fromCharCode(f)}}catch(e){i=!0,o=e}finally{try{!a&&s.return&&s.return()}finally{if(i)throw o}}return t},fromBinaryString:function(e){n.instanceOf(e,String);for(var t=new ArrayBuffer(e.length),r=new Uint8Array(t),a=0;athis.buffer.byteLength){var t=new ArrayBuffer(e<<1);new Uint8Array(t).set(new Uint8Array(this.buffer).subarray(0,this.size)),this.buffer=t}return this}},{key:"set",value:function(e,t){i.integer(e),i.integer(t),i.between(0,e,this.size,"Index out of bounds: "+(e+"")),i.between(0,t,256,"Not a byte: "+(t+""));var r=new Uint8Array(this.buffer);return r[e]=t,this}},{key:"setAll",value:function(e,t){i.instanceOf(t,ArrayBuffer),i.integer(e),i.between(0,e,this.size-t.byteLength+1,"Index out of bounds: "+(e+"")),new Uint8Array(this.buffer).set(new Uint8Array(t),e)}},{key:"get",value:function(e){return i.integer(e),i.between(0,e,this.size,"Index out of bounds: "+(e+"")),new Uint8Array(this.buffer)[e]}},{key:"add",value:function(e){var t=this.size,r=t+1;this.grow(r),this.size=r;var n=new Uint8Array(this.buffer);return n[t]=e,this}},{key:"addAll",value:function(e){i.instanceOf(e,ArrayBuffer);var t=this.size,r=this.size+e.byteLength;return this.grow(r),this.size=r,new Uint8Array(this.buffer).set(new Uint8Array(e),t),this}},{key:"toBuffer",value:function(){return this.buffer.slice(0,this.size)}},{key:"length",get:function(){return this.size}},{key:"rawBuffer",get:function(){return this.buffer}}]),e}();t.exports=u}).call(this,"/lib")},{}],"/lib/strint.js":[function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},a={};!function(){function e(e,t){return m(e)===m(t)}function t(e,t){for(;t>0;)e+="0",t--;return e}function r(e){f(e,"string")}function i(e){r(e),s(e,m,"isPositive")}function o(e){f(e,"number")}function u(e){if(f(e,"number"),e<0)throw Error("Expected a positive number: "+e)}function s(e,t,r){if(!t.call(null,e))throw Error("Condition "+r+" failed for value "+e)}function f(e,t){if((void 0===e?"undefined":n(e))!==t)throw Error("Not a "+t+": "+e)}var l=a.subPositive=function(e,t){if(i(e),i(t),!O(e,t))throw Error("x must be greater or equal to y");for(var r=Math.max(e.length,t.length),n="",a=0,o=0,u=0;u=10;)l-=10,a++;0===l?o++:(n=l+""+V(n,o),o=0)}return a>0&&(n=a+""+V(n,o)),n},y=a.add=function(e,t){if(r(e),r(t),m(e)&&m(t))return c(e,t);if(B(e)&&B(t))return S(c(k(e),k(t)));if(T(k(e),k(t))){var n=e;e=t,t=n}var a=l(k(e),k(t));return m(e)?a:S(a)},h=a.sub=function(e,t){return r(e),r(t),y(e,S(t))},v=a.timesDigit=function(e,t){i(e),o(t);for(var r="",n=I(e),a=0,u=0,s=0;s=10;)f-=10,a++;0===f?u++:(r=f+""+V(r,u),u=0)}return a>0&&(r=a+""+V(r,u)),0===r.length?"0":r},g=a.mulPositive=function(e,r){i(e),i(r);for(var n="0",a=I(r),o=0;o=I(e)?"0":e.charAt(e.length-t-1)},I=function(e){return B(e)?e.length-1:e.length}}(),a.LONG_UPPER_SHIFT="4294967296",a.BYTE_SHIFT="256",t.exports=a},{}],"/lib/util-inspect.js":[function(e,t,r){"use strict";r.inspect=function(e){if(void 0===e)return"undefined";if(null===e||e.constructor===Object||e.constructor===Array||e.constructor===String||e.constructor===Number||e.constructor===Boolean||e.constructor===Date)return JSON.stringify(e);if(e.constructor===Set){for(var t="Set {",n=e.values(),a=n.next();!a.done;)t+=r.inspect(a.value),a=n.next(),a.done||(t+=", ");return t+"}"}if(e.constructor===Map){for(var i="Map {",o=e.entries(),u=o.next();!u.done;)i+=r.inspect(u.value[0]),i+=" => ",i+=r.inspect(u.value[1]),u=o.next(),u.done||(i+=", ");return i+"}"}return e.constructor.name?e.constructor.name+" "+JSON.stringify(e):JSON.stringify(e)}},{}],1:[function(e,t,r){"use strict";!function(){e("/client-side/common.js");var t=e("/lib/assert.js");window.sb.upload=function(e,r){var n=e.type,a=e.value;if(t.instanceOf(n,window.sb.Type),t.instanceOf(r,Object),"POST"!==r.type&&"POST"!==r.method)throw Error("Must use POST when uploading");r.processData=!1,r.data=n.valueBuffer(a),$.ajax(r)}}(),function(){function t(){var e={};for(var t in i)e[t]={sig:i[t].sig,type:n.fromByteArray(new Uint8Array(i[t].type.toBuffer()))};localStorage.typeCache=JSON.stringify(e)}e("/client-side/common.js");var r=e("/lib/assert.js"),n=e("base64-js"),a=e("/read.js"),i={};if(void 0===localStorage.typeCache)t();else{var o=JSON.parse(localStorage.typeCache);for(var u in o)i[u]={sig:o[u].sig,type:a.type(new Uint8Array(n.toByteArray(o[u].type)).buffer)}}window.sb.download=function(e,n){function o(e,t,r){if(s){s instanceof Array||(s=[s]);var n=!0,a=!1,i=void 0;try{for(var o,u=s[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var f=o.value;f(e,t,r)}}catch(e){a=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(a)throw i}}}}r.instanceOf(e,String),r.instanceOf(n,Object),n.processData=!1,n.dataType="arraybuffer";var u=!1;i[e]&&(u=!0,n.headers||(n.headers={}),n.headers.sig=i[e].sig);var s=n.success;n.success=function(r,n,s){var f=s.getResponseHeader("sig");if(u&&i[e].sig===f){var l=i[e].type,c=a.value({buffer:r,type:l});o(c,n,s)}else{var y=a._consumeType(r,0),h=a.value({buffer:r,offset:y.length,type:y.value}),v=y.value;i[e]={sig:f,type:v},t(),o(h,n,s)}},$.ajax(n)}}()},{"/client-side/common.js":"/client-side/common.js","/lib/assert.js":"/lib/assert.js","/read.js":"/read.js","base64-js":2}],2:[function(e,t,r){"use strict";function n(){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t0)throw Error("Invalid string. Length must be a multiple of 4");i="="===e[u-2]?2:"="===e[u-1]?1:0,o=new l(3*u/4-i),n=i>0?u-4:u;var s=0;for(t=0,r=0;t>16&255,o[s++]=a>>8&255,o[s++]=255&a;return 2===i?(a=f[e.charCodeAt(t)]<<2|f[e.charCodeAt(t+1)]>>4,o[s++]=255&a):1===i&&(a=f[e.charCodeAt(t)]<<10|f[e.charCodeAt(t+1)]<<4|f[e.charCodeAt(t+2)]>>2,o[s++]=a>>8&255,o[s++]=255&a),o}function i(e){return s[e>>18&63]+s[e>>12&63]+s[e>>6&63]+s[63&e]}function o(e,t,r){for(var n,a=[],o=t;ol?l:f+u));return 1===n?(t=e[r-1],a+=s[t>>2],a+=s[t<<4&63],a+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],a+=s[t>>10],a+=s[t>>4&63],a+=s[t<<2&63],a+="="),i.push(a),i.join("")}r.toByteArray=a,r.fromByteArray=u;var s=[],f=[],l="undefined"!=typeof Uint8Array?Uint8Array:Array;n()},{}],3:[function(e,t,r){!function(e){"use strict";function r(e){return e.map(function(e){return n(e.toString(16),2)}).join("")}function n(e,t){return e.length>t?e:Array(t-e.length+1).join("0")+e}var a={bytesToHex:function(e){return r(e)},hexToBytes:function(e){if(e.length%2===1)throw Error("hexToBytes can't have a string with an odd number of characters.");return 0===e.indexOf("0x")&&(e=e.slice(2)),e.match(/../g).map(function(e){return parseInt(e,16)})}};void 0!==t&&t.exports?t.exports=a:e.convertHex=a}(this)},{}],4:[function(e,t,r){!function(e){"use strict";var r={bytesToString:function(e){return e.map(function(e){return String.fromCharCode(e)}).join("")},stringToBytes:function(e){return e.split("").map(function(e){return e.charCodeAt(0)})}};r.UTF8={bytesToString:function(e){return decodeURIComponent(escape(r.bytesToString(e)))},stringToBytes:function(e){return r.stringToBytes(unescape(encodeURIComponent(e)))}},void 0!==t&&t.exports?t.exports=r:e.convertString=r}(this)},{}],5:[function(e,t,r){!function(r){"use strict";function n(e,t){e.constructor===String&&(e=a.convertString.UTF8.stringToBytes(e));var r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=o(e),i=8*e.length;n[i>>5]|=128<<24-i%32,n[(i+64>>9<<4)+15]=i;for(var s=0;s>>5]|=e[r]<<24-n%32;return t},u=function(e){for(var t=[],r=0;r<32*e.length;r+=8)t.push(e[r>>>5]>>>24-r%32&255);return t},s=[],f=function(e,t,r){for(var n=e[0],a=e[1],o=e[2],u=e[3],f=e[4],l=e[5],c=e[6],y=e[7],h=0;h<64;h++){if(h<16)s[h]=0|t[r+h];else{var v=s[h-15],g=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,d=s[h-2],p=(d<<15|d>>>17)^(d<<13|d>>>19)^d>>>10;s[h]=g+s[h-7]+p+s[h-16]}var b=f&l^~f&c,w=n&a^n&o^a&o,T=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),O=(f<<26|f>>>6)^(f<<21|f>>>11)^(f<<7|f>>>25),A=y+O+b+i[h]+s[h],B=T+w;y=c,c=l,l=f,f=u+A|0,u=o,o=a,a=n,n=A+B|0}e[0]=e[0]+n|0,e[1]=e[1]+a|0,e[2]=e[2]+o|0,e[3]=e[3]+u|0,e[4]=e[4]+f|0,e[5]=e[5]+l|0,e[6]=e[6]+c|0,e[7]=e[7]+y|0};n.x2=function(e,t){return n(n(e,{asBytes:!0}),t)}}(this)},{"convert-hex":3,"convert-string":4}],"/read.js":[function(e,t,r){(function(r){"use strict";function n(e,t){try{return{value:new DataView(e).getUint32(t),length:4}}catch(e){l.fail(d)}}function a(e,t){return e.length=0,"Offset is negative: "+(t+"")),l.assert(e.byteLength>t,d);var r=void 0,o=1,u=new Uint8Array(e)[t],f=!0,c=!1,h=void 0;try{for(var g,b=p[Symbol.iterator]();!(f=(g=b.next()).done);f=!0){var w=g.value;if(u===w._value)return{value:new w,length:o}}}catch(e){c=!0,h=e}finally{try{!f&&b.return&&b.return()}finally{if(c)throw h}}switch(u){case v.BooleanTupleType._value:var T=n(e,t+o);r=new v.BooleanTupleType(T.value),o+=T.length;break;case v.TupleType._value:var O=i(e,t+o);o+=O.length;var A=n(e,t+o);o+=A.length,r=new v.TupleType({type:O.value,length:A.value});break;case v.StructType._value:l.assert(e.byteLength>t+o,d);var B=new Uint8Array(e),m=B[t+o];o++;for(var k={},S=0;St+o,d);var j=B[t+o];o++,l.assert(e.byteLength>=t+o+j,d);var U=y.toString(B.subarray(t+o,t+o+j));o+=j;var x=i(e,t+o);k[U]=x.value,o+=x.length}r=new v.StructType(k);break;case v.ArrayType._value:var _=i(e,t+o);o+=_.length,r=new v.ArrayType(_.value);break;case v.SetType._value:var V=i(e,t+o);o+=V.length,r=new v.SetType(V.value);break;case v.MapType._value:var P=i(e,t+o);o+=P.length;var I=i(e,t+o);o+=I.length,r=new v.MapType(P.value,I.value);break;case v.EnumType._value:var E=i(e,t+o);o+=E.length,l.assert(e.byteLength>t+o,d);var L=new Uint8Array(e)[t+o];o++;for(var D=[],C=0;Ct+o,d);var F=new Uint8Array(e)[t+o];o++;for(var H=Array(F),q=0;q=t+G,d);var Y=new DataView(e).getUint16(t+o),J=i(e,t+o-Y);r=J.value,o=G;break;default:l.fail("No such type: 0x"+a(new Uint8Array(e)[t].toString(16),2))}return{value:r,length:o}}function o(e){var t=arguments.length<=1||void 0===arguments[1]||arguments[1];l.instanceOf(e,ArrayBuffer);var r=i(e,0),n=r.value,a=r.length;return t&&l.assert(a===e.byteLength,"Did not consume all of the buffer"),n}function u(e){var t=e.buffer,r=e.offset,n=e.count,a=Array(n),i=c.modEight(a.length),o=c.dividedByEight(a.length),u=void 0;u=i?o+1:o,l.assert(t.byteLength>=r+u,d);for(var s=new Uint8Array(t),f=0;f=r+o,d),i=new Int8Array(t)[r];break;case v.ShortType:o=2,l.assert(t.byteLength>=r+o,d);var f=new DataView(t);i=f.getInt16(r);break;case v.IntType:o=4;var c=new DataView(t);i=c.getInt32(r);break;case v.LongType:o=8,l.assert(t.byteLength>=r+o,d);var p=new DataView(t),b=p.getInt32(r),w=p.getUint32(r+4);i=h.add(h.mul(b+"",h.LONG_UPPER_SHIFT),w+"");break;case v.BigIntType:o=2,l.assert(t.byteLength>=r+o,d);var T=new DataView(t),O=T.getUint16(r);l.assert(t.byteLength>=r+o+O,d),i=O?T.getInt8(r+o)+"":"0";for(var A=1;A=r+o,d),i=new Uint8Array(t)[r];break;case v.UnsignedShortType:o=2,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getUint16(r);break;case v.UnsignedIntType:o=4,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getUint32(r);break;case v.UnsignedLongType:case v.DateType:o=8,l.assert(t.byteLength>=r+o,d);var B=new DataView(t),m=B.getUint32(r),k=B.getUint32(r+4);i=h.add(h.mul(m+"",h.LONG_UPPER_SHIFT),k+""),a.constructor===v.DateType&&(i=new Date(+i));break;case v.BigUnsignedIntType:o=2,l.assert(t.byteLength>=r+o,d);var S=new DataView(t),j=S.getUint16(r);l.assert(t.byteLength>=r+o+j,d),i="0";for(var U=0;U=r+o,d),i=new DataView(t).getFloat32(r);break;case v.DoubleType:o=8,l.assert(t.byteLength>=r+o,d),i=new DataView(t).getFloat64(r);break;case v.BooleanType:o=1,l.assert(t.byteLength>=r+o,d);var x=new Uint8Array(t)[r];l.assert(0===x||255===x,"0x"+x.toString(16)+" is an invalid Boolean value"),i=!!x;break;case v.BooleanArrayType:var _=n(t,r);o=_.length;var V=u({buffer:t,offset:r+o,count:_.value});o+=V.length,i=V.value;break;case v.BooleanTupleType:var P=u({buffer:t,offset:r,count:a.length});i=P.value,o=P.length;break;case v.CharType:l.assert(t.byteLength>r,d),i=y.toString(new Uint8Array(t).subarray(r,r+4))[0],o=y.fromString(i).byteLength;break;case v.StringType:var I=new Uint8Array(t);for(o=0;l.assert(t.byteLength>r+o,d),I[r+o];o++);i=y.toString(new Uint8Array(t).subarray(r,r+o)),o++;break;case v.OctetsType:var E=n(t,r);o=E.length;var L=o+E.value;l.assert(t.byteLength>=r+L,d),i=t.slice(r+o,r+L),o=L;break;case v.TupleType:o=0,i=Array(a.length);for(var D=0;D=r+o,d);var ne=new Uint8Array(t)[r];i=a.values[ne],void 0===i&&l.fail("Index "+(ne+"")+" is invalid");break;case v.ChoiceType:o=1,l.assert(t.byteLength>=r+o,d);var ae=new Uint8Array(t)[r],ie=s({buffer:t,offset:r+o,type:a.types[ae]});o+=ie.length,i=ie.value;break;case v.OptionalType:o=1,l.assert(t.byteLength>=r+o,d);var oe=new Uint8Array(t)[r];if(l.assert(0===oe||255===oe,"0x"+oe.toString(16)+" is an invalid Optional byte"),oe){var ue=s({buffer:t,offset:r+o,type:a.type});o+=ue.length,i=ue.value}else i=null;break;case v.PointerType:var se=n(t,r);o=se.length,i=s({buffer:t,offset:se.value,type:a.type}).value;break;default:l.fail("Not a structure type: "+g.inspect(a))}return{value:i,length:o}}function f(e){var t=e.buffer,r=e.type,n=e.offset;l.instanceOf(t,ArrayBuffer),l.instanceOf(r,v.Type),void 0===n&&(n=0),l.instanceOf(n,Number);var a=s({buffer:t,offset:n,type:r}),i=a.value;return i}"/"===r&&(r="");var l=e(r+"/lib/assert.js"),c=e(r+"/lib/bit-math.js"),y=e(r+"/lib/buffer-string.js"),h=e(r+"/lib/strint.js"),v=e(r+"/structure-types.js"),g=e("/lib/util-inspect.js"),d="Buffer is not long enough",p=[v.ByteType,v.ShortType,v.IntType,v.LongType,v.BigIntType,v.UnsignedByteType,v.UnsignedShortType,v.UnsignedIntType,v.UnsignedLongType,v.DateType,v.BigUnsignedIntType,v.FloatType,v.DoubleType,v.BooleanType,v.BooleanArrayType,v.CharType,v.StringType,v.OctetsType];t.exports={_consumeType:i,type:o,value:f}}).call(this,"/")},{"/lib/util-inspect.js":"/lib/util-inspect.js"}],"/structure-types.js":[function(e,t,r){(function(r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){var t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e),t}function u(e,t){if(t&&e.pointers){var r=!0,n=!1,a=void 0;try{for(var i,o=e.pointers[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=h(i.value,2),s=u[0],f=u[1],l=e.length;e.addAll(d.fromBinaryString(s));var c=new ArrayBuffer(4);new DataView(c).setUint32(0,l);var y=!0,v=!1,g=void 0;try{for(var p,b=f[Symbol.iterator]();!(y=(p=b.next()).done);y=!0){var w=p.value;e.setAll(w,c)}}catch(e){v=!0,g=e}finally{try{!y&&b.return&&b.return()}finally{if(v)throw g}}}}catch(e){n=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(n)throw a}}}}function s(e){if(e&&e.constructor===String){var t=+e;if(!isNaN(t))return t}}function f(e,t){v.instanceOf(e,w),v.instanceOf(t,String),(T.gt(t,q)||T.lt(t,"0"))&&v.fail("Value out of range");var r=T.div(t,T.LONG_UPPER_SHIFT),n=T.sub(t,T.mul(r,T.LONG_UPPER_SHIFT)),a=new ArrayBuffer(8),i=new DataView(a);i.setUint32(0,+r),i.setUint32(4,+n),e.addAll(a)}function l(e,t){v.instanceOf(t,Array);var r=m(t.length),n=B(t.length),a=void 0;a=r?n+1:n;for(var i=new ArrayBuffer(a),o=new Uint8Array(i),u=0;u-1;s--,u++)o.setUint8(u,r[s]);r.length&&o.setInt8(2,r[r.length-1]),e.addAll(i)}}],[{key:"_value",get:function(){return 6}}]),t}(x),C=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),t}(U),N=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.integer(t),v.between(0,t,256,"Value out of range");var n=new ArrayBuffer(1);new Uint8Array(n)[0]=t,e.addAll(n)}}],[{key:"_value",get:function(){return 17}}]),t}(C),F=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.integer(t),v.between(0,t,65536,"Value out of range");var n=new ArrayBuffer(2);new DataView(n).setUint16(0,t),e.addAll(n)}}],[{key:"_value",get:function(){return 18}}]),t}(C),H=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.integer(t),v.between(0,t,4294967296,"Value out of range");var n=new ArrayBuffer(4);new DataView(n).setUint32(0,t),e.addAll(n)}}],[{key:"_value",get:function(){return 19}}]),t}(C),q="18446744073709551615",R=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){f(e,t)}}],[{key:"_value",get:function(){return 20}}]),t}(C),M=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(t,Date),f(e,t.getTime()+"")}}],[{key:"_value",get:function(){return 21}}]),t}(U),z=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,String),T.isNegative(t)&&v.fail("Value out of range");var r=[];if(!T.eq(t,"0")){for(;T.ge(t,T.BYTE_SHIFT);){var n=T.quotientRemainderPositive(t,T.BYTE_SHIFT),a=h(n,2),i=a[0],o=a[1];r.push(+o),t=i}r.push(+t),v.twoByteUnsignedInteger(r.length)}var u=new ArrayBuffer(2+r.length),s=new DataView(u);s.setUint16(0,r.length);for(var f=2,l=r.length-1;l>-1;l--,f++)s.setUint8(f,r[l]);e.addAll(u)}}],[{key:"_value",get:function(){return 22}}]),t}(C),G=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),t}(U),Y=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.instanceOf(t,Number);var n=new ArrayBuffer(4);new DataView(n).setFloat32(0,t),e.addAll(n)}}],[{key:"_value",get:function(){return 32}}]),t}(G),J=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w);var r=s(t);void 0!==r&&(t=r),v.instanceOf(t,Number);var n=new ArrayBuffer(8);new DataView(n).setFloat64(0,t),e.addAll(n)}}],[{key:"_value",get:function(){return 33}}]),t}(G),$=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,Boolean),t?e.add(255):e.add(0)}}],[{key:"_value",get:function(){return 48}}]),t}(U),W=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this));return v.fourByteUnsignedInteger(e),r.length=e,r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 49}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&e.addAll(o(this.length))}},{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,Array),t.length!==this.length&&v.fail("Length does not match"),l(e,t)}}]),t}(U),X=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(t,Array),v.fourByteUnsignedInteger(t.length),e.addAll(o(t.length)),l(e,t)}}],[{key:"_value",get:function(){return 50}}]),t}(U),Q=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,String),v.assert(1===t.length,"String must contain only 1 character"),e.addAll(d.fromString(t))}}],[{key:"_value",get:function(){return 64}}]),t}(U),K=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,String);var r=d.fromString(t);e.addAll(r),e.add(0)}}],[{key:"_value",get:function(){return 65}}]),t}(U),Z=function(e){function t(){return i(this,t),n(this,Object.getPrototypeOf(t).apply(this,arguments))}return a(t,e),y(t,[{key:"writeValue",value:function(e,t){v.instanceOf(e,w),v.instanceOf(t,ArrayBuffer),v.fourByteUnsignedInteger(t.byteLength),e.addAll(o(t.byteLength)),e.addAll(t)}}],[{key:"_value",get:function(){return 66}}]),t}(U),ee=function(e){function t(e){var r=e.type,a=e.length;i(this,t);var o=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(r,j),v.fourByteUnsignedInteger(a),o.type=r,o.length=a,o}return a(t,e),y(t,null,[{key:"_value",get:function(){return 80}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&(this.type.addToBuffer(e),e.addAll(o(this.length)))}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Array),t.length!==this.length&&v.fail("Length does not match: expected "+(this.length+"")+" but got "+t.length);var n=!0,a=!1,i=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var f=o.value;this.type.writeValue(e,f,!1)}}catch(e){a=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(a)throw i}}u(e,r)}}]),t}(U),te="name",re="type",ne="buffer",ae=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this));v.instanceOf(e,Object);var a=0;for(var o in e)a++;try{v.byteUnsignedInteger(a)}catch(e){v.fail(a+" fields is too many")}r.fields=Array(a);var u=0;for(var s in e){var f=d.fromString(s);try{v.byteUnsignedInteger(f.byteLength)}catch(e){v.fail("Field name "+s+" is too long")}var l=e[s];try{v.instanceOf(l,j)}catch(e){v.fail(l+" is not a valid field type")}var c={};c[te]=s,c[re]=l,c[ne]=f,r.fields[u]=c,u++}return r.fields.sort(function(e,t){return e[te]t[te]?1:void 0}),r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 81}}]),y(t,[{key:"addToBuffer",value:function(e){if(c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)){e.add(this.fields.length);var r=!0,n=!1,a=void 0;try{for(var i,o=this.fields[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=i.value,s=u[ne];e.add(s.byteLength),e.addAll(s),u[re].addToBuffer(e)}}catch(e){n=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(n)throw a}}}}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Object);var n=!0,a=!1,i=void 0;try{for(var o,s=this.fields[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var f=o.value,l=t[f[te]];void 0===l&&v.fail("Value for field "+f[te]+" missing"),f[re].writeValue(e,l,!1)}}catch(e){a=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(a)throw i}}u(e,r)}}]),t}(U),ie=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(e,j),r.type=e,r}return a(t,e),y(t,null,[{key:"_value",get:function(){return 82}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&this.type.addToBuffer(e)}},{key:"_writeValue",value:function(e,t,r){v.instanceOf(e,w),v.fourByteUnsignedInteger(t.length),e.addAll(o(t.length));var n=!0,a=!1,i=void 0;try{for(var s,f=t[Symbol.iterator]();!(n=(s=f.next()).done);n=!0){var l=s.value;this.type.writeValue(e,l,!1)}}catch(e){a=!0,i=e}finally{try{!n&&f.return&&f.return()}finally{if(a)throw i}}u(e,r)}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,Array),this._writeValue(e,t,r)}}]),t}(U),oe=function(e){function t(e){return i(this,t),n(this,Object.getPrototypeOf(t).call(this,e))}return a(t,e),y(t,null,[{key:"_value",get:function(){return 83}}]),y(t,[{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,Set),t.length=t.size,this._writeValue(e,t,r)}}]),t}(ie),ue=function(e){function t(e,r){i(this,t);var a=n(this,Object.getPrototypeOf(t).call(this));return v.instanceOf(e,j),v.instanceOf(r,j),a.keyType=e,a.valueType=r,a}return a(t,e),y(t,null,[{key:"_value",get:function(){return 84}}]),y(t,[{key:"addToBuffer",value:function(e){c(Object.getPrototypeOf(t.prototype),"addToBuffer",this).call(this,e)&&(this.keyType.addToBuffer(e),this.valueType.addToBuffer(e))}},{key:"writeValue",value:function(e,t){var r=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,w),v.instanceOf(t,Map),v.fourByteUnsignedInteger(t.size),e.addAll(o(t.size));var n=!0,a=!1,i=void 0;try{for(var s,f=t[Symbol.iterator]();!(n=(s=f.next()).done);n=!0){var l=h(s.value,2),c=l[0],y=l[1];this.keyType.writeValue(e,c,!1),this.valueType.writeValue(e,y,!1)}}catch(e){a=!0,i=e}finally{try{!n&&f.return&&f.return()}finally{if(a)throw i}}u(e,r)}}]),t}(U),se=function(e){function t(e){var r=e.type,a=e.values;i(this,t);var o=n(this,Object.getPrototypeOf(t).call(this));v.instanceOf(r,U),v.instanceOf(a,Array);try{v.byteUnsignedInteger(a.length)}catch(e){v.fail(a.length+" values is too many")}for(var u=new Map,s=0;s=200&&e.status<300||304===e.status;n?t[o]=e.response:t.text=e.statusText,r(e.status,e.statusText,t,e.getAllResponseHeaders())}),e.open(a,i,f),e.responseType=o;for(var s in n)n.hasOwnProperty(s)&&e.setRequestHeader(s,n[s]);e.send(u)},abort:function(){e&&e.abort()}}}})}(jQuery)},{}],"/client-side/common.js":[function(t,e,n){"use strict";var r=t("/lib/assert.js");if(r.instanceOf(window.Map,Function),r.instanceOf(window.Set,Function),r.instanceOf(window.ArrayBuffer,Function),r.instanceOf(window.Uint8Array,Function),r.instanceOf(window.Symbol,Function),t("/client-side/binary-ajax.js"),void 0===window.sb)window.sb=t("/structure-types.js");else if(!(window.sb instanceof Object))throw Error("window.sb is already defined")},{"/client-side/binary-ajax.js":"/client-side/binary-ajax.js","/lib/assert.js":"/lib/assert.js","/structure-types.js":"/structure-types.js"}],"/config.js":[function(t,e,n){(function(n){"use strict";"/"===n&&(n="");var r=t(n+"/lib/assert.js"),i=t("base64-js"),a=7;r.between(0,a,65536);var o=2,u=new ArrayBuffer(o);new DataView(u).setUint16(0,a);var f=i.fromByteArray(new Uint8Array(u));e.exports={VERSION_STRING:f}}).call(this,"/")},{"base64-js":2}],"/lib/assert.js":[function(t,e,n){"use strict";var r=t("/lib/util-inspect.js"),i={instanceOf:function(t,e){e instanceof Array||(e=[e]);var n=!1,i=!0,a=!1,o=void 0;try{for(var u,f=e[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var s=u.value;if(t instanceof s||void 0!==t&&null!==t&&t.constructor===s){n=!0;break}}}catch(t){a=!0,o=t}finally{try{!i&&f.return&&f.return()}finally{if(a)throw o}}if(!n)throw new TypeError(r.inspect(t)+" is not an instance of "+e.map(function(t){return t.name}).join(" or "))},integer:function(t){if(i.instanceOf(t,Number),!Number.isSafeInteger(t))throw new RangeError(r.inspect(t)+" is not an integer")},between:function(t,e,n,i){if(e=n){var a=r.inspect(e)+" is not in ["+r.inspect(t)+","+r.inspect(n)+")";throw void 0===i?new RangeError(a):new RangeError(i+" ("+a+")")}},byteUnsignedInteger:function(t){i.integer(t),i.between(0,t,256)},fourByteUnsignedInteger:function(t){i.integer(t),i.between(0,t,4294967296)},fail:function(t){throw Error(t)},assert:function(t,e){t||i.fail(e)},throws:function(t,e){var n=!0;try{t(),n=!1}catch(t){void 0!==e&&i.message(t,e)}i.assert(n,"Should throw an error")},equal:function(t,e){var n=new RangeError("Expected "+r.inspect(e)+" but got "+r.inspect(t));if(e&&e.constructor===Object){for(var a in e)if(e.hasOwnProperty(a))try{i.equal(t[a],e[a])}catch(t){throw n}}else if(e&&e.constructor===Array){if(!t||t.constructor!==Array)throw n;try{i.equal(t.length,e.length)}catch(t){throw n}for(var o=0;o>>3},modEight:function(t){return 7&t}}},{}],"/lib/buffer-string.js":[function(t,e,n){(function(n){"use strict";var r=t(n+"/assert.js"),i=t(n+"/growable-buffer.js"),a=4096;e.exports={toString:function(t){t&&t.constructor===ArrayBuffer&&(t=new Uint8Array(t)),r.instanceOf(t,Uint8Array);for(var e=[],n=0;n239?4:i>223?3:i>191?2:1;if(n+u<=t.length){var f=void 0,s=void 0,c=void 0,l=void 0;switch(u){case 1:i<128&&(o=i);break;case 2:f=t[n+1],128===(192&f)&&(l=(31&i)<<6|63&f,l>127&&(o=l));break;case 3:f=t[n+1],s=t[n+2],128===(192&f)&&128===(192&s)&&(l=(15&i)<<12|(63&f)<<6|63&s,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:f=t[n+1],s=t[n+2],c=t[n+3],128===(192&f)&&128===(192&s)&&128===(192&c)&&(l=(15&i)<<18|(63&f)<<12|(63&s)<<6|63&c,l>65535&&l<1114112&&(o=l))}}void 0===o?(o=65533,u=1):o>65535&&(o-=65536,e.push(o>>>10&1023|55296),o=56320|1023&o),e.push(o),n+=u}for(var y="",h=0;h>6),e.add(128|63&c)):c<55296||c>=57344?(e.add(224|c>>12),e.add(128|c>>6&63),e.add(128|63&c)):(c=65536+((1023&c)<<10|1023&c),e.add(240|c>>18),e.add(128|c>>12&63),e.add(128|c>>6&63),e.add(128|63&c))}}catch(t){a=!0,o=t}finally{try{!n&&f.return&&f.return()}finally{if(a)throw o}}return e.toBuffer()},toBinaryString:function(t){r.instanceOf(t,ArrayBuffer);var e="",n=new Uint8Array(t),i=!0,a=!1,o=void 0;try{for(var u,f=n[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var s=u.value;e+=String.fromCharCode(s)}}catch(t){a=!0,o=t}finally{try{!i&&f.return&&f.return()}finally{if(a)throw o}}return e},fromBinaryString:function(t){r.instanceOf(t,String);for(var e=new ArrayBuffer(t.length),n=new Uint8Array(e),i=0;ithis.buffer.byteLength){var e=new ArrayBuffer(t<<1);new Uint8Array(e).set(new Uint8Array(this.buffer).subarray(0,this.size)),this.buffer=e}return this}},{key:"set",value:function(t,e){a.integer(t),a.integer(e),a.between(0,t,this.size,"Index out of bounds: "+(t+"")),a.between(0,e,256,"Not a byte: "+(e+""));var n=new Uint8Array(this.buffer);return n[t]=e,this}},{key:"setAll",value:function(t,e){a.instanceOf(e,ArrayBuffer),a.integer(t),a.between(0,t,this.size-e.byteLength+1,"Index out of bounds: "+(t+"")),new Uint8Array(this.buffer).set(new Uint8Array(e),t)}},{key:"get",value:function(t){return a.integer(t),a.between(0,t,this.size,"Index out of bounds: "+(t+"")),new Uint8Array(this.buffer)[t]}},{key:"add",value:function(t){var e=this.size,n=e+1;this.grow(n),this.size=n;var r=new Uint8Array(this.buffer);return r[e]=t,this}},{key:"addAll",value:function(t){a.instanceOf(t,ArrayBuffer);var e=this.size,n=this.size+t.byteLength;return this.grow(n),this.size=n,new Uint8Array(this.buffer).set(new Uint8Array(t),e),this}},{key:"toBuffer",value:function(){return this.buffer.slice(0,this.size)}},{key:"length",get:function(){return this.size}},{key:"rawBuffer",get:function(){return this.buffer}}]),t}();e.exports=u}).call(this,"/lib")},{}],"/lib/strint.js":[function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},i={};!function(){function t(t,e){return j(t)===j(e)}function e(t,e){for(;e>0;)t+="0",e--;return t}function n(t){s(t,"string")}function a(t){n(t),f(t,j,"isPositive")}function o(t){s(t,"number")}function u(t){if(s(t,"number"),t<0)throw Error("Expected a positive number: "+t)}function f(t,e,n){if(!e.call(null,t))throw Error("Condition "+n+" failed for value "+t)}function s(t,e){if((void 0===t?"undefined":r(t))!==e)throw Error("Not a "+e+": "+t)}var c=i.subPositive=function(t,e){if(a(t),a(e),!A(t,e))throw Error("x must be greater or equal to y");for(var n=Math.max(t.length,e.length),r="",i=0,o=0,u=0;u=10;)c-=10,i++;0===c?o++:(r=c+""+_(r,o),o=0)}return i>0&&(r=i+""+_(r,o)),r},y=i.add=function(t,e){if(n(t),n(e),j(t)&&j(e))return l(t,e);if(B(t)&&B(e))return S(l(m(t),m(e)));if(O(m(t),m(e))){var r=t;t=e,e=r}var i=c(m(t),m(e));return j(t)?i:S(i)},h=i.sub=function(t,e){return n(t),n(e),y(t,S(e))},v=i.timesDigit=function(t,e){a(t),o(e);for(var n="",r=E(t),i=0,u=0,f=0;f=10;)s-=10,i++;0===s?u++:(n=s+""+_(n,u),u=0)}return i>0&&(n=i+""+_(n,u)),0===n.length?"0":n},d=i.mulPositive=function(t,n){a(t),a(n);for(var r="0",i=E(n),o=0;o=E(t)?"0":t.charAt(t.length-e-1)},E=function(t){return B(t)?t.length-1:t.length}}(),i.LONG_UPPER_SHIFT="4294967296",e.exports=i},{}],"/lib/util-inspect.js":[function(t,e,n){"use strict";n.inspect=function(t){if(void 0===t)return"undefined";if(null===t||t.constructor===Object||t.constructor===Array||t.constructor===String||t.constructor===Number||t.constructor===Boolean||t.constructor===Date)return JSON.stringify(t);if(t.constructor===Set){for(var e="Set {",r=t.values(),i=r.next();!i.done;)e+=n.inspect(i.value),i=r.next(),i.done||(e+=", ");return e+"}"}if(t.constructor===Map){for(var a="Map {",o=t.entries(),u=o.next();!u.done;)a+=n.inspect(u.value[0]),a+=" => ",a+=n.inspect(u.value[1]),u=o.next(),u.done||(a+=", ");return a+"}"}return t.constructor.name?t.constructor.name+" "+JSON.stringify(t):JSON.stringify(t)}},{}],1:[function(t,e,n){"use strict";!function(){t("/client-side/common.js");var e=t("/lib/assert.js");window.sb.upload=function(t,n){var r=t.type,i=t.value;if(e.instanceOf(r,window.sb.Type),e.instanceOf(n,Object),"POST"!==n.type&&"POST"!==n.method)throw Error("Must use POST when uploading");n.processData=!1,n.data=r.valueBuffer(i),$.ajax(n)}}()},{"/client-side/common.js":"/client-side/common.js","/lib/assert.js":"/lib/assert.js"}],2:[function(t,e,n){"use strict";function r(){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,n=t.length;e0)throw Error("Invalid string. Length must be a multiple of 4");a="="===t[u-2]?2:"="===t[u-1]?1:0,o=new c(3*u/4-a),r=a>0?u-4:u;var f=0;for(e=0,n=0;e>16&255,o[f++]=i>>8&255,o[f++]=255&i;return 2===a?(i=s[t.charCodeAt(e)]<<2|s[t.charCodeAt(e+1)]>>4,o[f++]=255&i):1===a&&(i=s[t.charCodeAt(e)]<<10|s[t.charCodeAt(e+1)]<<4|s[t.charCodeAt(e+2)]>>2,o[f++]=i>>8&255,o[f++]=255&i),o}function a(t){return f[t>>18&63]+f[t>>12&63]+f[t>>6&63]+f[63&t]}function o(t,e,n){for(var r,i=[],o=e;oc?c:s+u));return 1===r?(e=t[n-1],i+=f[e>>2],i+=f[e<<4&63],i+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],i+=f[e>>10],i+=f[e>>4&63],i+=f[e<<2&63],i+="="),a.push(i),a.join("")}n.toByteArray=i,n.fromByteArray=u;var f=[],s=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array;r()},{}],3:[function(t,e,n){!function(t){"use strict";function n(t){return t.map(function(t){return r(t.toString(16),2)}).join("")}function r(t,e){return t.length>e?t:Array(e-t.length+1).join("0")+t}var i={bytesToHex:function(t){return n(t)},hexToBytes:function(t){if(t.length%2===1)throw Error("hexToBytes can't have a string with an odd number of characters.");return 0===t.indexOf("0x")&&(t=t.slice(2)),t.match(/../g).map(function(t){return parseInt(t,16)})}};void 0!==e&&e.exports?e.exports=i:t.convertHex=i}(this)},{}],4:[function(t,e,n){!function(t){"use strict";var n={bytesToString:function(t){return t.map(function(t){return String.fromCharCode(t)}).join("")},stringToBytes:function(t){return t.split("").map(function(t){return t.charCodeAt(0)})}};n.UTF8={bytesToString:function(t){return decodeURIComponent(escape(n.bytesToString(t)))},stringToBytes:function(t){return n.stringToBytes(unescape(encodeURIComponent(t)))}},void 0!==e&&e.exports?e.exports=n:t.convertString=n}(this)},{}],5:[function(t,e,n){!function(n){"use strict";function r(t,e){t.constructor===String&&(t=i.convertString.UTF8.stringToBytes(t));var n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=o(t),a=8*t.length;r[a>>5]|=128<<24-a%32,r[(a+64>>9<<4)+15]=a;for(var f=0;f>>5]|=t[n]<<24-r%32;return e},u=function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},f=[],s=function(t,e,n){for(var r=t[0],i=t[1],o=t[2],u=t[3],s=t[4],c=t[5],l=t[6],y=t[7],h=0;h<64;h++){if(h<16)f[h]=0|e[n+h];else{var v=f[h-15],d=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,g=f[h-2],p=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;f[h]=d+f[h-7]+p+f[h-16]}var w=s&c^~s&l,b=r&i^r&o^i&o,O=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),A=(s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25),T=y+A+w+a[h]+f[h],B=O+b;y=l,l=c,c=s,s=u+T|0,u=o,o=i,i=r,r=T+B|0}t[0]=t[0]+r|0,t[1]=t[1]+i|0,t[2]=t[2]+o|0,t[3]=t[3]+u|0,t[4]=t[4]+s|0,t[5]=t[5]+c|0,t[6]=t[6]+l|0,t[7]=t[7]+y|0};r.x2=function(t,e){return r(r(t,{asBytes:!0}),e)}}(this)},{"convert-hex":3,"convert-string":4}],"/structure-types.js":[function(t,e,n){(function(n){"use strict";function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t){var e=new ArrayBuffer(4);return new DataView(e).setUint32(0,t),e}function u(t,e){if(e&&t.pointers){var n=!0,r=!1,i=void 0;try{for(var a,o=t.pointers[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=h(a.value,2),f=u[0],s=u[1],c=t.length;t.addAll(g.fromBinaryString(f));var l=new ArrayBuffer(4);new DataView(l).setUint32(0,c);var y=!0,v=!1,d=void 0;try{for(var p,w=s[Symbol.iterator]();!(y=(p=w.next()).done);y=!0){var b=p.value;t.setAll(b,l)}}catch(t){v=!0,d=t}finally{try{!y&&w.return&&w.return()}finally{if(v)throw d}}}}catch(t){r=!0,i=t}finally{try{!n&&o.return&&o.return()}finally{if(r)throw i}}}}function f(t){if(t&&t.constructor===String){var e=+t;if(!isNaN(e))return e}}function s(t,e){v.instanceOf(t,b),v.instanceOf(e,String),(O.gt(e,"18446744073709551615")||O.lt(e,"0"))&&v.fail("Value out of range");var n=O.div(e,O.LONG_UPPER_SHIFT),r=O.sub(e,O.mul(n,O.LONG_UPPER_SHIFT)),i=new ArrayBuffer(8),a=new DataView(i);a.setUint32(0,+n),a.setUint32(4,+r),t.addAll(i)}function c(t,e){v.instanceOf(e,Array);var n=j(e.length),r=B(e.length),i=void 0;i=n?r+1:r;for(var a=new ArrayBuffer(i),o=new Uint8Array(a),u=0;ue[$]?1:void 0}),n}return i(e,t),y(e,null,[{key:"_value",get:function(){return 81}}]),y(e,[{key:"addToBuffer",value:function(t){if(l(Object.getPrototypeOf(e.prototype),"addToBuffer",this).call(this,t)){t.add(this.fields.length);var n=!0,r=!1,i=void 0;try{for(var a,o=this.fields[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value,f=u[Y];t.add(f.byteLength),t.addAll(f),u[Q].addToBuffer(t)}}catch(t){r=!0,i=t}finally{try{!n&&o.return&&o.return()}finally{if(r)throw i}}}}},{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,b),v.instanceOf(e,Object);var r=!0,i=!1,a=void 0;try{for(var o,f=this.fields[Symbol.iterator]();!(r=(o=f.next()).done);r=!0){var s=o.value,c=e[s[$]];void 0===c&&v.fail("Value for field "+s[$]+" missing"),s[Q].writeValue(t,c,!1)}}catch(t){i=!0,a=t}finally{try{!r&&f.return&&f.return()}finally{if(i)throw a}}u(t,n)}}]),e}(k),Z=function(t){function e(t){a(this,e);var n=r(this,Object.getPrototypeOf(e).call(this));return v.instanceOf(t,S),n.type=t,n}return i(e,t),y(e,null,[{key:"_value",get:function(){return 82}}]),y(e,[{key:"addToBuffer",value:function(t){l(Object.getPrototypeOf(e.prototype),"addToBuffer",this).call(this,t)&&this.type.addToBuffer(t)}},{key:"_writeValue",value:function(t,e,n){v.instanceOf(t,b),v.fourByteUnsignedInteger(e.length),t.addAll(o(e.length));var r=!0,i=!1,a=void 0;try{for(var f,s=e[Symbol.iterator]();!(r=(f=s.next()).done);r=!0){var c=f.value;this.type.writeValue(t,c,!1)}}catch(t){i=!0,a=t}finally{try{!r&&s.return&&s.return()}finally{if(i)throw a}}u(t,n)}},{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,Array),this._writeValue(t,e,n)}}]),e}(k),tt=function(t){function e(t){return a(this,e),r(this,Object.getPrototypeOf(e).call(this,t))}return i(e,t),y(e,null,[{key:"_value",get:function(){return 83}}]),y(e,[{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,Set),e.length=e.size,this._writeValue(t,e,n)}}]),e}(Z),et=function(t){function e(t,n){a(this,e);var i=r(this,Object.getPrototypeOf(e).call(this)); -return v.instanceOf(t,S),v.instanceOf(n,S),i.keyType=t,i.valueType=n,i}return i(e,t),y(e,null,[{key:"_value",get:function(){return 84}}]),y(e,[{key:"addToBuffer",value:function(t){l(Object.getPrototypeOf(e.prototype),"addToBuffer",this).call(this,t)&&(this.keyType.addToBuffer(t),this.valueType.addToBuffer(t))}},{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,b),v.instanceOf(e,Map),v.fourByteUnsignedInteger(e.size),t.addAll(o(e.size));var r=!0,i=!1,a=void 0;try{for(var f,s=e[Symbol.iterator]();!(r=(f=s.next()).done);r=!0){var c=h(f.value,2),l=c[0],y=c[1];this.keyType.writeValue(t,l,!1),this.valueType.writeValue(t,y,!1)}}catch(t){i=!0,a=t}finally{try{!r&&s.return&&s.return()}finally{if(i)throw a}}u(t,n)}}]),e}(k),nt=function(t){function e(t){var n=t.type,i=t.values;a(this,e);var o=r(this,Object.getPrototypeOf(e).call(this));v.instanceOf(n,k),v.instanceOf(i,Array);try{v.byteUnsignedInteger(i.length)}catch(t){v.fail(i.length+" values is too many")}for(var u=new Map,f=0;f=200&&e.status<300||304===e.status;n?t[o]=e.response:t.text=e.statusText,r(e.status,e.statusText,t,e.getAllResponseHeaders())}),e.open(a,i,f),e.responseType=o;for(var s in n)n.hasOwnProperty(s)&&e.setRequestHeader(s,n[s]);e.send(u)},abort:function(){e&&e.abort()}}}})}(jQuery)},{}],"/client-side/common.js":[function(t,e,n){"use strict";var r=t("/lib/assert.js");if(r.instanceOf(window.Map,Function),r.instanceOf(window.Set,Function),r.instanceOf(window.ArrayBuffer,Function),r.instanceOf(window.Uint8Array,Function),r.instanceOf(window.Symbol,Function),t("/client-side/binary-ajax.js"),void 0===window.sb)window.sb=t("/structure-types.js");else if(!(window.sb instanceof Object))throw Error("window.sb is already defined")},{"/client-side/binary-ajax.js":"/client-side/binary-ajax.js","/lib/assert.js":"/lib/assert.js","/structure-types.js":"/structure-types.js"}],"/config.js":[function(t,e,n){(function(n){"use strict";"/"===n&&(n="");var r=t(n+"/lib/assert.js"),i=t("base64-js"),a=8;r.between(0,a,65536);var o=2,u=new ArrayBuffer(o);new DataView(u).setUint16(0,a);var f=i.fromByteArray(new Uint8Array(u));e.exports={VERSION_STRING:f}}).call(this,"/")},{"base64-js":2}],"/lib/assert.js":[function(t,e,n){"use strict";var r=t("/lib/util-inspect.js"),i={instanceOf:function(t,e){e instanceof Array||(e=[e]);var n=!1,i=!0,a=!1,o=void 0;try{for(var u,f=e[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var s=u.value;if(t instanceof s||void 0!==t&&null!==t&&t.constructor===s){n=!0;break}}}catch(t){a=!0,o=t}finally{try{!i&&f.return&&f.return()}finally{if(a)throw o}}if(!n)throw new TypeError(r.inspect(t)+" is not an instance of "+e.map(function(t){return t.name}).join(" or "))},integer:function(t){if(i.instanceOf(t,Number),!Number.isSafeInteger(t))throw new RangeError(r.inspect(t)+" is not an integer")},between:function(t,e,n,i){if(e=n){var a=r.inspect(e)+" is not in ["+r.inspect(t)+","+r.inspect(n)+")";throw void 0===i?new RangeError(a):new RangeError(i+" ("+a+")")}},byteUnsignedInteger:function(t){i.integer(t),i.between(0,t,256)},twoByteUnsignedInteger:function(t){i.integer(t),i.between(0,t,65536)},fourByteUnsignedInteger:function(t){i.integer(t),i.between(0,t,4294967296)},fail:function(t){throw Error(t)},assert:function(t,e){t||i.fail(e)},throws:function(t,e){var n=!0;try{t(),n=!1}catch(t){void 0!==e&&i.message(t,e)}i.assert(n,"Should throw an error")},equal:function(t,e){var n=new RangeError("Expected "+r.inspect(e)+" but got "+r.inspect(t));if(e&&e.constructor===Object){for(var a in e)if(e.hasOwnProperty(a))try{i.equal(t[a],e[a])}catch(t){throw n}}else if(e&&e.constructor===Array){if(!t||t.constructor!==Array)throw n;try{i.equal(t.length,e.length)}catch(t){throw n}for(var o=0;o>>3},modEight:function(t){return 7&t}}},{}],"/lib/buffer-string.js":[function(t,e,n){(function(n){"use strict";var r=t(n+"/assert.js"),i=t(n+"/growable-buffer.js"),a=4096;e.exports={toString:function(t){t&&t.constructor===ArrayBuffer&&(t=new Uint8Array(t)),r.instanceOf(t,Uint8Array);for(var e=[],n=0;n239?4:i>223?3:i>191?2:1;if(n+u<=t.length){var f=void 0,s=void 0,c=void 0,l=void 0;switch(u){case 1:i<128&&(o=i);break;case 2:f=t[n+1],128===(192&f)&&(l=(31&i)<<6|63&f,l>127&&(o=l));break;case 3:f=t[n+1],s=t[n+2],128===(192&f)&&128===(192&s)&&(l=(15&i)<<12|(63&f)<<6|63&s,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:f=t[n+1],s=t[n+2],c=t[n+3],128===(192&f)&&128===(192&s)&&128===(192&c)&&(l=(15&i)<<18|(63&f)<<12|(63&s)<<6|63&c,l>65535&&l<1114112&&(o=l))}}void 0===o?(o=65533,u=1):o>65535&&(o-=65536,e.push(o>>>10&1023|55296),o=56320|1023&o),e.push(o),n+=u}for(var y="",h=0;h>6),e.add(128|63&c)):c<55296||c>=57344?(e.add(224|c>>12),e.add(128|c>>6&63),e.add(128|63&c)):(c=65536+((1023&c)<<10|1023&c),e.add(240|c>>18),e.add(128|c>>12&63),e.add(128|c>>6&63),e.add(128|63&c))}}catch(t){a=!0,o=t}finally{try{!n&&f.return&&f.return()}finally{if(a)throw o}}return e.toBuffer()},toBinaryString:function(t){r.instanceOf(t,ArrayBuffer);var e="",n=new Uint8Array(t),i=!0,a=!1,o=void 0;try{for(var u,f=n[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var s=u.value;e+=String.fromCharCode(s)}}catch(t){a=!0,o=t}finally{try{!i&&f.return&&f.return()}finally{if(a)throw o}}return e},fromBinaryString:function(t){r.instanceOf(t,String);for(var e=new ArrayBuffer(t.length),n=new Uint8Array(e),i=0;ithis.buffer.byteLength){var e=new ArrayBuffer(t<<1);new Uint8Array(e).set(new Uint8Array(this.buffer).subarray(0,this.size)),this.buffer=e}return this}},{key:"set",value:function(t,e){a.integer(t),a.integer(e),a.between(0,t,this.size,"Index out of bounds: "+(t+"")),a.between(0,e,256,"Not a byte: "+(e+""));var n=new Uint8Array(this.buffer);return n[t]=e,this}},{key:"setAll",value:function(t,e){a.instanceOf(e,ArrayBuffer),a.integer(t),a.between(0,t,this.size-e.byteLength+1,"Index out of bounds: "+(t+"")),new Uint8Array(this.buffer).set(new Uint8Array(e),t)}},{key:"get",value:function(t){return a.integer(t),a.between(0,t,this.size,"Index out of bounds: "+(t+"")),new Uint8Array(this.buffer)[t]}},{key:"add",value:function(t){var e=this.size,n=e+1;this.grow(n),this.size=n;var r=new Uint8Array(this.buffer);return r[e]=t,this}},{key:"addAll",value:function(t){a.instanceOf(t,ArrayBuffer);var e=this.size,n=this.size+t.byteLength;return this.grow(n),this.size=n,new Uint8Array(this.buffer).set(new Uint8Array(t),e),this}},{key:"toBuffer",value:function(){return this.buffer.slice(0,this.size)}},{key:"length",get:function(){return this.size}},{key:"rawBuffer",get:function(){return this.buffer}}]),t}();e.exports=u}).call(this,"/lib")},{}],"/lib/strint.js":[function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},i={};!function(){function t(t,e){return m(t)===m(e)}function e(t,e){for(;e>0;)t+="0",e--;return t}function n(t){s(t,"string")}function a(t){n(t),f(t,m,"isPositive")}function o(t){s(t,"number")}function u(t){if(s(t,"number"),t<0)throw Error("Expected a positive number: "+t)}function f(t,e,n){if(!e.call(null,t))throw Error("Condition "+n+" failed for value "+t)}function s(t,e){if((void 0===t?"undefined":r(t))!==e)throw Error("Not a "+e+": "+t)}var c=i.subPositive=function(t,e){if(a(t),a(e),!T(t,e))throw Error("x must be greater or equal to y");for(var n=Math.max(t.length,e.length),r="",i=0,o=0,u=0;u=10;)c-=10,i++;0===c?o++:(r=c+""+U(r,o),o=0)}return i>0&&(r=i+""+U(r,o)),r},y=i.add=function(t,e){if(n(t),n(e),m(t)&&m(e))return l(t,e);if(A(t)&&A(e))return S(l(j(t),j(e)));if(O(j(t),j(e))){var r=t;t=e,e=r}var i=c(j(t),j(e));return m(t)?i:S(i)},h=i.sub=function(t,e){return n(t),n(e),y(t,S(e))},v=i.timesDigit=function(t,e){a(t),o(e);for(var n="",r=E(t),i=0,u=0,f=0;f=10;)s-=10,i++;0===s?u++:(n=s+""+U(n,u),u=0)}return i>0&&(n=i+""+U(n,u)),0===n.length?"0":n},d=i.mulPositive=function(t,n){a(t),a(n);for(var r="0",i=E(n),o=0;o=E(t)?"0":t.charAt(t.length-e-1)},E=function(t){return A(t)?t.length-1:t.length}}(),i.LONG_UPPER_SHIFT="4294967296",i.BYTE_SHIFT="256",e.exports=i},{}],"/lib/util-inspect.js":[function(t,e,n){"use strict";n.inspect=function(t){if(void 0===t)return"undefined";if(null===t||t.constructor===Object||t.constructor===Array||t.constructor===String||t.constructor===Number||t.constructor===Boolean||t.constructor===Date)return JSON.stringify(t);if(t.constructor===Set){for(var e="Set {",r=t.values(),i=r.next();!i.done;)e+=n.inspect(i.value),i=r.next(),i.done||(e+=", ");return e+"}"}if(t.constructor===Map){for(var a="Map {",o=t.entries(),u=o.next();!u.done;)a+=n.inspect(u.value[0]),a+=" => ",a+=n.inspect(u.value[1]),u=o.next(),u.done||(a+=", ");return a+"}"}return t.constructor.name?t.constructor.name+" "+JSON.stringify(t):JSON.stringify(t)}},{}],1:[function(t,e,n){"use strict";!function(){t("/client-side/common.js");var e=t("/lib/assert.js");window.sb.upload=function(t,n){var r=t.type,i=t.value;if(e.instanceOf(r,window.sb.Type),e.instanceOf(n,Object),"POST"!==n.type&&"POST"!==n.method)throw Error("Must use POST when uploading");n.processData=!1,n.data=r.valueBuffer(i),$.ajax(n)}}()},{"/client-side/common.js":"/client-side/common.js","/lib/assert.js":"/lib/assert.js"}],2:[function(t,e,n){"use strict";function r(){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,n=t.length;e0)throw Error("Invalid string. Length must be a multiple of 4");a="="===t[u-2]?2:"="===t[u-1]?1:0,o=new c(3*u/4-a),r=a>0?u-4:u;var f=0;for(e=0,n=0;e>16&255,o[f++]=i>>8&255,o[f++]=255&i;return 2===a?(i=s[t.charCodeAt(e)]<<2|s[t.charCodeAt(e+1)]>>4,o[f++]=255&i):1===a&&(i=s[t.charCodeAt(e)]<<10|s[t.charCodeAt(e+1)]<<4|s[t.charCodeAt(e+2)]>>2,o[f++]=i>>8&255,o[f++]=255&i),o}function a(t){return f[t>>18&63]+f[t>>12&63]+f[t>>6&63]+f[63&t]}function o(t,e,n){for(var r,i=[],o=e;oc?c:s+u));return 1===r?(e=t[n-1],i+=f[e>>2],i+=f[e<<4&63],i+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],i+=f[e>>10],i+=f[e>>4&63],i+=f[e<<2&63],i+="="),a.push(i),a.join("")}n.toByteArray=i,n.fromByteArray=u;var f=[],s=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array;r()},{}],3:[function(t,e,n){!function(t){"use strict";function n(t){return t.map(function(t){return r(t.toString(16),2)}).join("")}function r(t,e){return t.length>e?t:Array(e-t.length+1).join("0")+t}var i={bytesToHex:function(t){return n(t)},hexToBytes:function(t){if(t.length%2===1)throw Error("hexToBytes can't have a string with an odd number of characters.");return 0===t.indexOf("0x")&&(t=t.slice(2)),t.match(/../g).map(function(t){return parseInt(t,16)})}};void 0!==e&&e.exports?e.exports=i:t.convertHex=i}(this)},{}],4:[function(t,e,n){!function(t){"use strict";var n={bytesToString:function(t){return t.map(function(t){return String.fromCharCode(t)}).join("")},stringToBytes:function(t){return t.split("").map(function(t){return t.charCodeAt(0)})}};n.UTF8={bytesToString:function(t){return decodeURIComponent(escape(n.bytesToString(t)))},stringToBytes:function(t){return n.stringToBytes(unescape(encodeURIComponent(t)))}},void 0!==e&&e.exports?e.exports=n:t.convertString=n}(this)},{}],5:[function(t,e,n){!function(n){"use strict";function r(t,e){t.constructor===String&&(t=i.convertString.UTF8.stringToBytes(t));var n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=o(t),a=8*t.length;r[a>>5]|=128<<24-a%32,r[(a+64>>9<<4)+15]=a;for(var f=0;f>>5]|=t[n]<<24-r%32;return e},u=function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},f=[],s=function(t,e,n){for(var r=t[0],i=t[1],o=t[2],u=t[3],s=t[4],c=t[5],l=t[6],y=t[7],h=0;h<64;h++){if(h<16)f[h]=0|e[n+h];else{var v=f[h-15],d=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,g=f[h-2],p=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;f[h]=d+f[h-7]+p+f[h-16]}var w=s&c^~s&l,b=r&i^r&o^i&o,O=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),T=(s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25),B=y+T+w+a[h]+f[h],A=O+b;y=l,l=c,c=s,s=u+B|0,u=o,o=i,i=r,r=B+A|0}t[0]=t[0]+r|0,t[1]=t[1]+i|0,t[2]=t[2]+o|0,t[3]=t[3]+u|0,t[4]=t[4]+s|0,t[5]=t[5]+c|0,t[6]=t[6]+l|0,t[7]=t[7]+y|0};r.x2=function(t,e){return r(r(t,{asBytes:!0}),e)}}(this)},{"convert-hex":3,"convert-string":4}],"/structure-types.js":[function(t,e,n){(function(n){"use strict";function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t){var e=new ArrayBuffer(4);return new DataView(e).setUint32(0,t),e}function u(t,e){if(e&&t.pointers){var n=!0,r=!1,i=void 0;try{for(var a,o=t.pointers[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=h(a.value,2),f=u[0],s=u[1],c=t.length;t.addAll(g.fromBinaryString(f));var l=new ArrayBuffer(4);new DataView(l).setUint32(0,c);var y=!0,v=!1,d=void 0;try{for(var p,w=s[Symbol.iterator]();!(y=(p=w.next()).done);y=!0){var b=p.value;t.setAll(b,l)}}catch(t){v=!0,d=t}finally{try{!y&&w.return&&w.return()}finally{if(v)throw d}}}}catch(t){r=!0,i=t}finally{try{!n&&o.return&&o.return()}finally{if(r)throw i}}}}function f(t){if(t&&t.constructor===String){var e=+t;if(!isNaN(e))return e}}function s(t,e){v.instanceOf(t,b),v.instanceOf(e,String),(O.gt(e,L)||O.lt(e,"0"))&&v.fail("Value out of range");var n=O.div(e,O.LONG_UPPER_SHIFT),r=O.sub(e,O.mul(n,O.LONG_UPPER_SHIFT)),i=new ArrayBuffer(8),a=new DataView(i);a.setUint32(0,+n),a.setUint32(4,+r),t.addAll(i)}function c(t,e){v.instanceOf(e,Array);var n=m(e.length),r=A(e.length),i=void 0;i=n?r+1:r;for(var a=new ArrayBuffer(i),o=new Uint8Array(a),u=0;u-1;f--,u++)o.setUint8(u,n[f]);n.length&&o.setInt8(2,n[n.length-1]),t.addAll(a)}}],[{key:"_value",get:function(){return 6}}]),e}(P),C=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),e}(x),H=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b);var n=f(e);void 0!==n&&(e=n),v.integer(e),v.between(0,e,256,"Value out of range");var r=new ArrayBuffer(1);new Uint8Array(r)[0]=e,t.addAll(r)}}],[{key:"_value",get:function(){return 17}}]),e}(C),D=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b);var n=f(e);void 0!==n&&(e=n),v.integer(e),v.between(0,e,65536,"Value out of range");var r=new ArrayBuffer(2);new DataView(r).setUint16(0,e),t.addAll(r)}}],[{key:"_value",get:function(){return 18}}]),e}(C),F=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b);var n=f(e);void 0!==n&&(e=n),v.integer(e),v.between(0,e,4294967296,"Value out of range");var r=new ArrayBuffer(4);new DataView(r).setUint32(0,e),t.addAll(r)}}],[{key:"_value",get:function(){return 19}}]),e}(C),L="18446744073709551615",R=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){s(t,e)}}],[{key:"_value",get:function(){return 20}}]),e}(C),z=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(e,Date),s(t,e.getTime()+"")}}],[{key:"_value",get:function(){return 21}}]),e}(x),M=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b),v.instanceOf(e,String),O.isNegative(e)&&v.fail("Value out of range");var n=[];if(!O.eq(e,"0")){for(;O.ge(e,O.BYTE_SHIFT);){var r=O.quotientRemainderPositive(e,O.BYTE_SHIFT),i=h(r,2),a=i[0],o=i[1];n.push(+o),e=a}n.push(+e),v.twoByteUnsignedInteger(n.length)}var u=new ArrayBuffer(2+n.length),f=new DataView(u);f.setUint16(0,n.length);for(var s=2,c=n.length-1;c>-1;c--,s++)f.setUint8(s,n[c]);t.addAll(u)}}],[{key:"_value",get:function(){return 22}}]),e}(C),G=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),e}(x),Y=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b);var n=f(e);void 0!==n&&(e=n),v.instanceOf(e,Number);var r=new ArrayBuffer(4);new DataView(r).setFloat32(0,e),t.addAll(r)}}],[{key:"_value",get:function(){return 32}}]),e}(G),J=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b);var n=f(e);void 0!==n&&(e=n),v.instanceOf(e,Number);var r=new ArrayBuffer(8);new DataView(r).setFloat64(0,e),t.addAll(r)}}],[{key:"_value",get:function(){return 33}}]),e}(G),W=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b),v.instanceOf(e,Boolean),e?t.add(255):t.add(0)}}],[{key:"_value",get:function(){return 48}}]),e}(x),X=function(t){function e(t){a(this,e);var n=r(this,Object.getPrototypeOf(e).call(this));return v.fourByteUnsignedInteger(t),n.length=t,n}return i(e,t),y(e,null,[{key:"_value",get:function(){return 49}}]),y(e,[{key:"addToBuffer",value:function(t){l(Object.getPrototypeOf(e.prototype),"addToBuffer",this).call(this,t)&&t.addAll(o(this.length))}},{key:"writeValue",value:function(t,e){v.instanceOf(t,b),v.instanceOf(e,Array),e.length!==this.length&&v.fail("Length does not match"),c(t,e)}}]),e}(x),$=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(e,Array),v.fourByteUnsignedInteger(e.length),t.addAll(o(e.length)),c(t,e)}}],[{key:"_value",get:function(){return 50}}]),e}(x),Q=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b),v.instanceOf(e,String),v.assert(1===e.length,"String must contain only 1 character"),t.addAll(g.fromString(e))}}],[{key:"_value",get:function(){return 64}}]),e}(x),K=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b),v.instanceOf(e,String);var n=g.fromString(e);t.addAll(n),t.add(0)}}],[{key:"_value",get:function(){return 65}}]),e}(x),Z=function(t){function e(){return a(this,e),r(this,Object.getPrototypeOf(e).apply(this,arguments))}return i(e,t),y(e,[{key:"writeValue",value:function(t,e){v.instanceOf(t,b),v.instanceOf(e,ArrayBuffer),v.fourByteUnsignedInteger(e.byteLength),t.addAll(o(e.byteLength)),t.addAll(e)}}],[{key:"_value",get:function(){return 66}}]),e}(x),tt=function(t){function e(t){var n=t.type,i=t.length;a(this,e);var o=r(this,Object.getPrototypeOf(e).call(this));return v.instanceOf(n,k),v.fourByteUnsignedInteger(i),o.type=n,o.length=i,o}return i(e,t),y(e,null,[{key:"_value",get:function(){return 80}}]),y(e,[{key:"addToBuffer",value:function(t){l(Object.getPrototypeOf(e.prototype),"addToBuffer",this).call(this,t)&&(this.type.addToBuffer(t),t.addAll(o(this.length)))}},{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,b),v.instanceOf(e,Array),e.length!==this.length&&v.fail("Length does not match: expected "+(this.length+"")+" but got "+e.length);var r=!0,i=!1,a=void 0;try{for(var o,f=e[Symbol.iterator]();!(r=(o=f.next()).done);r=!0){var s=o.value;this.type.writeValue(t,s,!1)}}catch(t){i=!0,a=t}finally{try{!r&&f.return&&f.return()}finally{if(i)throw a}}u(t,n)}}]),e}(x),et="name",nt="type",rt="buffer",it=function(t){function e(t){a(this,e);var n=r(this,Object.getPrototypeOf(e).call(this));v.instanceOf(t,Object);var i=0;for(var o in t)i++;try{v.byteUnsignedInteger(i)}catch(t){v.fail(i+" fields is too many")}n.fields=Array(i);var u=0;for(var f in t){var s=g.fromString(f);try{v.byteUnsignedInteger(s.byteLength)}catch(t){v.fail("Field name "+f+" is too long")}var c=t[f];try{v.instanceOf(c,k)}catch(t){v.fail(c+" is not a valid field type")}var l={};l[et]=f,l[nt]=c,l[rt]=s,n.fields[u]=l,u++}return n.fields.sort(function(t,e){return t[et]e[et]?1:void 0}),n}return i(e,t),y(e,null,[{key:"_value",get:function(){return 81}}]),y(e,[{key:"addToBuffer",value:function(t){if(l(Object.getPrototypeOf(e.prototype),"addToBuffer",this).call(this,t)){t.add(this.fields.length);var n=!0,r=!1,i=void 0;try{for(var a,o=this.fields[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value,f=u[rt];t.add(f.byteLength),t.addAll(f),u[nt].addToBuffer(t)}}catch(t){r=!0,i=t}finally{try{!n&&o.return&&o.return()}finally{if(r)throw i}}}}},{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,b),v.instanceOf(e,Object);var r=!0,i=!1,a=void 0;try{for(var o,f=this.fields[Symbol.iterator]();!(r=(o=f.next()).done);r=!0){var s=o.value,c=e[s[et]];void 0===c&&v.fail("Value for field "+s[et]+" missing"), +s[nt].writeValue(t,c,!1)}}catch(t){i=!0,a=t}finally{try{!r&&f.return&&f.return()}finally{if(i)throw a}}u(t,n)}}]),e}(x),at=function(t){function e(t){a(this,e);var n=r(this,Object.getPrototypeOf(e).call(this));return v.instanceOf(t,k),n.type=t,n}return i(e,t),y(e,null,[{key:"_value",get:function(){return 82}}]),y(e,[{key:"addToBuffer",value:function(t){l(Object.getPrototypeOf(e.prototype),"addToBuffer",this).call(this,t)&&this.type.addToBuffer(t)}},{key:"_writeValue",value:function(t,e,n){v.instanceOf(t,b),v.fourByteUnsignedInteger(e.length),t.addAll(o(e.length));var r=!0,i=!1,a=void 0;try{for(var f,s=e[Symbol.iterator]();!(r=(f=s.next()).done);r=!0){var c=f.value;this.type.writeValue(t,c,!1)}}catch(t){i=!0,a=t}finally{try{!r&&s.return&&s.return()}finally{if(i)throw a}}u(t,n)}},{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,Array),this._writeValue(t,e,n)}}]),e}(x),ot=function(t){function e(t){return a(this,e),r(this,Object.getPrototypeOf(e).call(this,t))}return i(e,t),y(e,null,[{key:"_value",get:function(){return 83}}]),y(e,[{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(e,Set),e.length=e.size,this._writeValue(t,e,n)}}]),e}(at),ut=function(t){function e(t,n){a(this,e);var i=r(this,Object.getPrototypeOf(e).call(this));return v.instanceOf(t,k),v.instanceOf(n,k),i.keyType=t,i.valueType=n,i}return i(e,t),y(e,null,[{key:"_value",get:function(){return 84}}]),y(e,[{key:"addToBuffer",value:function(t){l(Object.getPrototypeOf(e.prototype),"addToBuffer",this).call(this,t)&&(this.keyType.addToBuffer(t),this.valueType.addToBuffer(t))}},{key:"writeValue",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]||arguments[2];v.instanceOf(t,b),v.instanceOf(e,Map),v.fourByteUnsignedInteger(e.size),t.addAll(o(e.size));var r=!0,i=!1,a=void 0;try{for(var f,s=e[Symbol.iterator]();!(r=(f=s.next()).done);r=!0){var c=h(f.value,2),l=c[0],y=c[1];this.keyType.writeValue(t,l,!1),this.valueType.writeValue(t,y,!1)}}catch(t){i=!0,a=t}finally{try{!r&&s.return&&s.return()}finally{if(i)throw a}}u(t,n)}}]),e}(x),ft=function(t){function e(t){var n=t.type,i=t.values;a(this,e);var o=r(this,Object.getPrototypeOf(e).call(this));v.instanceOf(n,x),v.instanceOf(i,Array);try{v.byteUnsignedInteger(i.length)}catch(t){v.fail(i.length+" values is too many")}for(var u=new Map,f=0;fParameters:
Source:
@@ -317,7 +317,7 @@
Parameters:
Source:
@@ -475,7 +475,7 @@
Parameters:
Source:
@@ -502,7 +502,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -584,7 +584,7 @@

getHashSource:
@@ -694,7 +694,7 @@

getSignat
Source:
@@ -804,7 +804,7 @@

toBufferSource:
@@ -959,7 +959,7 @@
Parameters:
Source:
@@ -1147,7 +1147,7 @@
Parameters:
Source:
@@ -1223,7 +1223,7 @@
Example

diff --git a/doc/BigIntType.html b/doc/BigIntType.html new file mode 100644 index 0000000..77e2581 --- /dev/null +++ b/doc/BigIntType.html @@ -0,0 +1,1178 @@ + + + + + JSDoc: Class: BigIntType + + + + + + + + + + +
+ +

Class: BigIntType

+ + + + + + +
+ +
+ +

BigIntType

+ +
A type storing an arbitrary precision signed integer +(up to 65535 bytes of precision). +Each written value has its own number of bytes of precision.
+ + +
+ +
+
+ + + + +

Constructor

+ + +

new BigIntType()

+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

addToBuffer(buffer) → {boolean}

+ + + + + +
+ Appends the type information to a GrowableBuffer. +All types start with the byte specified by Type._value. +For the most primitive types, this implementation is sufficient. +Recursive types should override this method, +invoking super.addToBuffer() and then adding their own data if it returns true. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
buffer + + +GrowableBuffer + + + + The buffer to append to
+ + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ false if it wrote a pointer to a previous instance, true if it wrote the type byte. Intended to only be used internally. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + + + +

equals(otherType) → {boolean}

+ + + + + +
+ Returns whether this type object represents the same type as another object +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
otherType + + +Type + + + + Another object to compare with
+ + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ true iff the types have the same constructor and the same field values for fields that don't store cached results +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + + + +

getHash() → {string}

+ + + + + +
+ Gets an SHA256 hash of the type, using a cached value if present +
+ + + + + + + + + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ a hash of the buffer given by toBuffer() +
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + + + + + + + +

getSignature() → {string}

+ + + + + +
+ Gets a signature string for the type, using a cached value if present. +This string encodes the specification version and the type hash. +
+ + + + + + + + + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ a signature for the type +
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + + + + + + + +

toBuffer() → {external:ArrayBuffer}

+ + + + + +
+ Gets the type in buffer form, using a cached value if present. +Since types are immutable, the result should never change from the cached value. +
+ + + + + + + + + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ A Buffer containing the type bytes +
+ + + +
+
+ Type +
+
+ +external:ArrayBuffer + + +
+
+ + + + + + + + + + +

valueBuffer(value) → {external:ArrayBuffer}

+ + + + + +
+ Gets a Buffer containing the value in binary format. +See this type's writeValue() documentation +for acceptable values. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + The value to write
+ + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ a Buffer storing the value (assuming the type is known) +
+ + + +
+
+ Type +
+
+ +external:ArrayBuffer + + +
+
+ + + + + + + + + + +

writeValue(buffer, value)

+ + + + + +
+ Appends value bytes to a GrowableBuffer according to the type +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
buffer + + +GrowableBuffer + + + + The buffer to which to append
value + + +string + + + + The value to write (a base-10 string representation of an integer)
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+ + + +
+
+
+ If the value doesn't match the type, e.g. sb.StringType().writeValue(buffer, 23) +
+
+
+
+
+
+ Type +
+
+ +Error + + +
+
+
+
+
+ + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/BigUnsignedIntType.html b/doc/BigUnsignedIntType.html new file mode 100644 index 0000000..2f32e1e --- /dev/null +++ b/doc/BigUnsignedIntType.html @@ -0,0 +1,1178 @@ + + + + + JSDoc: Class: BigUnsignedIntType + + + + + + + + + + +
+ +

Class: BigUnsignedIntType

+ + + + + + +
+ +
+ +

BigUnsignedIntType

+ +
A type storing an arbitrary precision unsigned integer +(up to 65535 bytes of precision). +Each written value has its own number of bytes of precision.
+ + +
+ +
+
+ + + + +

Constructor

+ + +

new BigUnsignedIntType()

+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

addToBuffer(buffer) → {boolean}

+ + + + + +
+ Appends the type information to a GrowableBuffer. +All types start with the byte specified by Type._value. +For the most primitive types, this implementation is sufficient. +Recursive types should override this method, +invoking super.addToBuffer() and then adding their own data if it returns true. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
buffer + + +GrowableBuffer + + + + The buffer to append to
+ + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ false if it wrote a pointer to a previous instance, true if it wrote the type byte. Intended to only be used internally. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + + + +

equals(otherType) → {boolean}

+ + + + + +
+ Returns whether this type object represents the same type as another object +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
otherType + + +Type + + + + Another object to compare with
+ + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ true iff the types have the same constructor and the same field values for fields that don't store cached results +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + + + +

getHash() → {string}

+ + + + + +
+ Gets an SHA256 hash of the type, using a cached value if present +
+ + + + + + + + + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ a hash of the buffer given by toBuffer() +
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + + + + + + + +

getSignature() → {string}

+ + + + + +
+ Gets a signature string for the type, using a cached value if present. +This string encodes the specification version and the type hash. +
+ + + + + + + + + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ a signature for the type +
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + + + + + + + +

toBuffer() → {external:ArrayBuffer}

+ + + + + +
+ Gets the type in buffer form, using a cached value if present. +Since types are immutable, the result should never change from the cached value. +
+ + + + + + + + + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ A Buffer containing the type bytes +
+ + + +
+
+ Type +
+
+ +external:ArrayBuffer + + +
+
+ + + + + + + + + + +

valueBuffer(value) → {external:ArrayBuffer}

+ + + + + +
+ Gets a Buffer containing the value in binary format. +See this type's writeValue() documentation +for acceptable values. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + The value to write
+ + + + + + +
+ + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ a Buffer storing the value (assuming the type is known) +
+ + + +
+
+ Type +
+
+ +external:ArrayBuffer + + +
+
+ + + + + + + + + + +

writeValue(buffer, value)

+ + + + + +
+ Appends value bytes to a GrowableBuffer according to the type +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
buffer + + +GrowableBuffer + + + + The buffer to which to append
value + + +string + + + + The value to write (a base-10 string representation of an integer)
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+ + + +
+
+
+ If the value doesn't match the type, e.g. sb.StringType().writeValue(buffer, 23) +
+
+
+
+
+
+ Type +
+
+ +Error + + +
+
+
+
+
+ + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/BooleanArrayType.html b/doc/BooleanArrayType.html index 87ffe69..6c4e386 100644 --- a/doc/BooleanArrayType.html +++ b/doc/BooleanArrayType.html @@ -91,7 +91,7 @@

new B
Source:
@@ -267,7 +267,7 @@

Parameters:
Source:
@@ -425,7 +425,7 @@
Parameters:
Source:
@@ -452,7 +452,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -534,7 +534,7 @@

getHashSource:
@@ -644,7 +644,7 @@

getSignat
Source:
@@ -754,7 +754,7 @@

toBufferSource:
@@ -909,7 +909,7 @@
Parameters:
Source:
@@ -1097,7 +1097,7 @@
Parameters:
Source:
@@ -1168,7 +1168,7 @@
Throws:

diff --git a/doc/BooleanTupleType.html b/doc/BooleanTupleType.html index 50e023a..21496fb 100644 --- a/doc/BooleanTupleType.html +++ b/doc/BooleanTupleType.html @@ -140,7 +140,7 @@
Parameters:
Source:
@@ -318,7 +318,7 @@
Parameters:
Source:
@@ -476,7 +476,7 @@
Parameters:
Source:
@@ -503,7 +503,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -585,7 +585,7 @@

getHashSource:
@@ -695,7 +695,7 @@

getSignat
Source:
@@ -805,7 +805,7 @@

toBufferSource:
@@ -960,7 +960,7 @@
Parameters:
Source:
@@ -1148,7 +1148,7 @@
Parameters:
Source:
@@ -1219,7 +1219,7 @@
Throws:

diff --git a/doc/BooleanType.html b/doc/BooleanType.html index a3caf61..a56c763 100644 --- a/doc/BooleanType.html +++ b/doc/BooleanType.html @@ -91,7 +91,7 @@

new Boolea
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1090,7 +1090,7 @@
Parameters:
Source:
@@ -1161,7 +1161,7 @@
Throws:

diff --git a/doc/BufferStream.html b/doc/BufferStream.html index c1123c4..e06f1aa 100644 --- a/doc/BufferStream.html +++ b/doc/BufferStream.html @@ -212,7 +212,7 @@
Parameters:

diff --git a/doc/ByteType.html b/doc/ByteType.html index 810eadf..b3b5961 100644 --- a/doc/ByteType.html +++ b/doc/ByteType.html @@ -91,7 +91,7 @@

new ByteType<
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1093,7 +1093,7 @@
Parameters:
Source:
@@ -1164,7 +1164,7 @@
Throws:

diff --git a/doc/CharType.html b/doc/CharType.html index 3cc5095..295e14c 100644 --- a/doc/CharType.html +++ b/doc/CharType.html @@ -91,7 +91,7 @@

new CharType<
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1090,7 +1090,7 @@
Parameters:
Source:
@@ -1161,7 +1161,7 @@
Throws:

diff --git a/doc/ChoiceType.html b/doc/ChoiceType.html index 48e4d85..80827c9 100644 --- a/doc/ChoiceType.html +++ b/doc/ChoiceType.html @@ -145,7 +145,7 @@
Parameters:
Source:
@@ -324,7 +324,7 @@
Parameters:
Source:
@@ -482,7 +482,7 @@
Parameters:
Source:
@@ -509,7 +509,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -591,7 +591,7 @@

getHashSource:
@@ -701,7 +701,7 @@

getSignat
Source:
@@ -811,7 +811,7 @@

toBufferSource:
@@ -966,7 +966,7 @@
Parameters:
Source:
@@ -1149,7 +1149,7 @@
Parameters:
Source:
@@ -1226,7 +1226,7 @@
Example

diff --git a/doc/DateType.html b/doc/DateType.html index 364a8bc..4f70ebe 100644 --- a/doc/DateType.html +++ b/doc/DateType.html @@ -92,7 +92,7 @@

new DateType<
Source:
@@ -261,7 +261,7 @@

Parameters:
Source:
@@ -419,7 +419,7 @@
Parameters:
Source:
@@ -446,7 +446,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -528,7 +528,7 @@

getHashSource:
@@ -638,7 +638,7 @@

getSignat
Source:
@@ -748,7 +748,7 @@

toBufferSource:
@@ -903,7 +903,7 @@
Parameters:
Source:
@@ -1091,7 +1091,7 @@
Parameters:
Source:
@@ -1162,7 +1162,7 @@
Throws:

diff --git a/doc/DoubleType.html b/doc/DoubleType.html index a273f50..02a9baa 100644 --- a/doc/DoubleType.html +++ b/doc/DoubleType.html @@ -91,7 +91,7 @@

new DoubleT
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1093,7 +1093,7 @@
Parameters:
Source:
@@ -1164,7 +1164,7 @@
Throws:

diff --git a/doc/EnumType.html b/doc/EnumType.html index 2ee9ca6..0bdb249 100644 --- a/doc/EnumType.html +++ b/doc/EnumType.html @@ -214,7 +214,7 @@
Properties
Source:
@@ -397,7 +397,7 @@
Parameters:
Source:
@@ -555,7 +555,7 @@
Parameters:
Source:
@@ -582,7 +582,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -664,7 +664,7 @@

getHashSource:
@@ -774,7 +774,7 @@

getSignat
Source:
@@ -884,7 +884,7 @@

toBufferSource:
@@ -1039,7 +1039,7 @@
Parameters:
Source:
@@ -1227,7 +1227,7 @@
Parameters:
Source:
@@ -1303,7 +1303,7 @@
Example

diff --git a/doc/FloatType.html b/doc/FloatType.html index c6e57e4..d377d3f 100644 --- a/doc/FloatType.html +++ b/doc/FloatType.html @@ -91,7 +91,7 @@

new FloatTyp
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1093,7 +1093,7 @@
Parameters:
Source:
@@ -1164,7 +1164,7 @@
Throws:

diff --git a/doc/GrowableBuffer.html b/doc/GrowableBuffer.html index a306c27..3cadd7c 100644 --- a/doc/GrowableBuffer.html +++ b/doc/GrowableBuffer.html @@ -1403,7 +1403,7 @@
Returns:

diff --git a/doc/IntType.html b/doc/IntType.html index 2e1117b..51d81b6 100644 --- a/doc/IntType.html +++ b/doc/IntType.html @@ -91,7 +91,7 @@

new IntTypeSource:
@@ -260,7 +260,7 @@
Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1093,7 +1093,7 @@
Parameters:
Source:
@@ -1164,7 +1164,7 @@
Throws:

diff --git a/doc/LongType.html b/doc/LongType.html index a567253..f971aea 100644 --- a/doc/LongType.html +++ b/doc/LongType.html @@ -91,7 +91,7 @@

new LongType<
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1044,7 +1044,7 @@
Parameters:
- The value to write + The value to write (a base-10 string representation of an integer) @@ -1090,7 +1090,7 @@
Parameters:
Source:
@@ -1161,7 +1161,7 @@
Throws:

diff --git a/doc/MapType.html b/doc/MapType.html index a610e67..59810ad 100644 --- a/doc/MapType.html +++ b/doc/MapType.html @@ -164,7 +164,7 @@
Parameters:
Source:
@@ -343,7 +343,7 @@
Parameters:
Source:
@@ -501,7 +501,7 @@
Parameters:
Source:
@@ -528,7 +528,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -610,7 +610,7 @@

getHashSource:
@@ -720,7 +720,7 @@

getSignat
Source:
@@ -830,7 +830,7 @@

toBufferSource:
@@ -985,7 +985,7 @@
Parameters:
Source:
@@ -1173,7 +1173,7 @@
Parameters:
Source:
@@ -1253,7 +1253,7 @@
Example

diff --git a/doc/OctetsType.html b/doc/OctetsType.html index bb0d8ba..0cc6501 100644 --- a/doc/OctetsType.html +++ b/doc/OctetsType.html @@ -93,7 +93,7 @@

new OctetsT
Source:
@@ -262,7 +262,7 @@

Parameters:
Source:
@@ -420,7 +420,7 @@
Parameters:
Source:
@@ -447,7 +447,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -529,7 +529,7 @@

getHashSource:
@@ -639,7 +639,7 @@

getSignat
Source:
@@ -749,7 +749,7 @@

toBufferSource:
@@ -904,7 +904,7 @@
Parameters:
Source:
@@ -1092,7 +1092,7 @@
Parameters:
Source:
@@ -1163,7 +1163,7 @@
Throws:

diff --git a/doc/OptionalType.html b/doc/OptionalType.html index 7151af4..a899a5d 100644 --- a/doc/OptionalType.html +++ b/doc/OptionalType.html @@ -140,7 +140,7 @@
Parameters:
Source:
@@ -319,7 +319,7 @@
Parameters:
Source:
@@ -477,7 +477,7 @@
Parameters:
Source:
@@ -504,7 +504,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -586,7 +586,7 @@

getHashSource:
@@ -696,7 +696,7 @@

getSignat
Source:
@@ -806,7 +806,7 @@

toBufferSource:
@@ -961,7 +961,7 @@
Parameters:
Source:
@@ -1152,7 +1152,7 @@
Parameters:
Source:
@@ -1235,7 +1235,7 @@
Example

diff --git a/doc/PointerType.html b/doc/PointerType.html index e153873..aa06a47 100644 --- a/doc/PointerType.html +++ b/doc/PointerType.html @@ -142,7 +142,7 @@
Parameters:
Source:
@@ -328,7 +328,7 @@
Parameters:
Source:
@@ -486,7 +486,7 @@
Parameters:
Source:
@@ -513,7 +513,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -595,7 +595,7 @@

getHashSource:
@@ -705,7 +705,7 @@

getSignat
Source:
@@ -815,7 +815,7 @@

toBufferSource:
@@ -970,7 +970,7 @@
Parameters:
Source:
@@ -1158,7 +1158,7 @@
Parameters:
Source:
@@ -1253,7 +1253,7 @@
Example

diff --git a/doc/SetType.html b/doc/SetType.html index a5fb095..480515f 100644 --- a/doc/SetType.html +++ b/doc/SetType.html @@ -142,7 +142,7 @@
Parameters:
Source:
@@ -318,7 +318,7 @@
Parameters:
Source:
@@ -476,7 +476,7 @@
Parameters:
Source:
@@ -503,7 +503,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -585,7 +585,7 @@

getHashSource:
@@ -695,7 +695,7 @@

getSignat
Source:
@@ -805,7 +805,7 @@

toBufferSource:
@@ -960,7 +960,7 @@
Parameters:
Source:
@@ -1148,7 +1148,7 @@
Parameters:
Source:
@@ -1224,7 +1224,7 @@
Example

diff --git a/doc/ShortType.html b/doc/ShortType.html index 8533744..d9f676d 100644 --- a/doc/ShortType.html +++ b/doc/ShortType.html @@ -91,7 +91,7 @@

new ShortTyp
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1093,7 +1093,7 @@
Parameters:
Source:
@@ -1164,7 +1164,7 @@
Throws:

diff --git a/doc/StringType.html b/doc/StringType.html index 96f43d2..b60b931 100644 --- a/doc/StringType.html +++ b/doc/StringType.html @@ -91,7 +91,7 @@

new StringT
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1090,7 +1090,7 @@
Parameters:
Source:
@@ -1161,7 +1161,7 @@
Throws:

diff --git a/doc/StructType.html b/doc/StructType.html index 80651c6..df1c828 100644 --- a/doc/StructType.html +++ b/doc/StructType.html @@ -142,7 +142,7 @@
Parameters:
Source:
@@ -321,7 +321,7 @@
Parameters:
Source:
@@ -479,7 +479,7 @@
Parameters:
Source:
@@ -506,7 +506,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -588,7 +588,7 @@

getHashSource:
@@ -698,7 +698,7 @@

getSignat
Source:
@@ -808,7 +808,7 @@

toBufferSource:
@@ -963,7 +963,7 @@
Parameters:
Source:
@@ -1151,7 +1151,7 @@
Parameters:
Source:
@@ -1231,7 +1231,7 @@
Example

diff --git a/doc/TupleType.html b/doc/TupleType.html index 89c8ca5..6ce0820 100644 --- a/doc/TupleType.html +++ b/doc/TupleType.html @@ -214,7 +214,7 @@
Properties
Source:
@@ -389,7 +389,7 @@
Parameters:
Source:
@@ -547,7 +547,7 @@
Parameters:
Source:
@@ -574,7 +574,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -656,7 +656,7 @@

getHashSource:
@@ -766,7 +766,7 @@

getSignat
Source:
@@ -876,7 +876,7 @@

toBufferSource:
@@ -1031,7 +1031,7 @@
Parameters:
Source:
@@ -1219,7 +1219,7 @@
Parameters:
Source:
@@ -1295,7 +1295,7 @@
Example

diff --git a/doc/Type.html b/doc/Type.html index a33530d..85dccb7 100644 --- a/doc/Type.html +++ b/doc/Type.html @@ -92,7 +92,7 @@

new TypeSource:
@@ -191,7 +191,7 @@
Type:
Source:
@@ -322,7 +322,7 @@
Parameters:
Source:
@@ -475,7 +475,7 @@
Parameters:
Source:
@@ -502,7 +502,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -579,7 +579,7 @@

getHashSource:
@@ -684,7 +684,7 @@

getSignat
Source:
@@ -789,7 +789,7 @@

toBufferSource:
@@ -939,7 +939,7 @@
Parameters:
Source:
@@ -1117,7 +1117,7 @@
Parameters:
Source:
@@ -1215,7 +1215,7 @@
Throws:

diff --git a/doc/UnsignedByteType.html b/doc/UnsignedByteType.html index 50cdb24..d640b50 100644 --- a/doc/UnsignedByteType.html +++ b/doc/UnsignedByteType.html @@ -91,7 +91,7 @@

new U
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1093,7 +1093,7 @@
Parameters:
Source:
@@ -1164,7 +1164,7 @@
Throws:

diff --git a/doc/UnsignedIntType.html b/doc/UnsignedIntType.html index 4726c0a..c825dc6 100644 --- a/doc/UnsignedIntType.html +++ b/doc/UnsignedIntType.html @@ -91,7 +91,7 @@

new Un
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1093,7 +1093,7 @@
Parameters:
Source:
@@ -1164,7 +1164,7 @@
Throws:

diff --git a/doc/UnsignedLongType.html b/doc/UnsignedLongType.html index 61ab8a3..f6105b9 100644 --- a/doc/UnsignedLongType.html +++ b/doc/UnsignedLongType.html @@ -91,7 +91,7 @@

new U
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1044,7 +1044,7 @@
Parameters:
- The value to write + The value to write (a base-10 string representation of an integer) @@ -1090,7 +1090,7 @@
Parameters:
Source:
@@ -1161,7 +1161,7 @@
Throws:

diff --git a/doc/UnsignedShortType.html b/doc/UnsignedShortType.html index 1bdea38..255b128 100644 --- a/doc/UnsignedShortType.html +++ b/doc/UnsignedShortType.html @@ -91,7 +91,7 @@

new
Source:
@@ -260,7 +260,7 @@

Parameters:
Source:
@@ -418,7 +418,7 @@
Parameters:
Source:
@@ -445,7 +445,7 @@
Returns:
- true iff the types have the same constructor and the same field values for fields not starting with 'cached' + true iff the types have the same constructor and the same field values for fields that don't store cached results
@@ -527,7 +527,7 @@

getHashSource:
@@ -637,7 +637,7 @@

getSignat
Source:
@@ -747,7 +747,7 @@

toBufferSource:
@@ -902,7 +902,7 @@
Parameters:
Source:
@@ -1093,7 +1093,7 @@
Parameters:
Source:
@@ -1164,7 +1164,7 @@
Throws:

diff --git a/doc/external-ArrayBuffer.html b/doc/external-ArrayBuffer.html index 05c5ccc..fbe73d1 100644 --- a/doc/external-ArrayBuffer.html +++ b/doc/external-ArrayBuffer.html @@ -122,7 +122,7 @@

ArrayBuffer


diff --git a/doc/external-http.IncomingMessage.html b/doc/external-http.IncomingMessage.html index d78db8f..1bfd0ce 100644 --- a/doc/external-http.IncomingMessage.html +++ b/doc/external-http.IncomingMessage.html @@ -151,7 +151,7 @@

new In
diff --git a/doc/external-http.ServerResponse.html b/doc/external-http.ServerResponse.html index 0d5ce4f..268e741 100644 --- a/doc/external-http.ServerResponse.html +++ b/doc/external-http.ServerResponse.html @@ -151,7 +151,7 @@

new Ser
diff --git a/doc/external-http.html b/doc/external-http.html index 4ec0af3..a7b62d5 100644 --- a/doc/external-http.html +++ b/doc/external-http.html @@ -132,7 +132,7 @@

Classes


diff --git a/doc/global.html b/doc/global.html index a872f82..623a6ec 100644 --- a/doc/global.html +++ b/doc/global.html @@ -347,7 +347,7 @@
Properties
Source:
@@ -504,7 +504,7 @@
Parameters:
Source:
@@ -661,7 +661,7 @@
Parameters:
Source:
@@ -891,7 +891,7 @@
Properties
Source:
@@ -1140,7 +1140,7 @@
Properties
Source:
@@ -1414,7 +1414,7 @@
Properties
Source:
@@ -1686,7 +1686,7 @@
Properties
Source:
@@ -1826,7 +1826,7 @@
Parameters:
Source:
@@ -2013,7 +2013,7 @@
Parameters:
Source:
@@ -2174,7 +2174,7 @@
Parameters:
Source:
@@ -2335,7 +2335,7 @@
Parameters:
Source:
@@ -2375,7 +2375,7 @@
Parameters:

diff --git a/doc/index.html b/doc/index.html index b35a0df..c79621b 100644 --- a/doc/index.html +++ b/doc/index.html @@ -47,7 +47,7 @@

npm Build Status Coverage Status

-

Concept

Most data nowadays is stored in files or transfered over HTTP as either text files which can represent a wide variety of data structures (e.g. JSON or YAML) or in a format created to represent only one specific sort of data (e.g. MP3). The idea with this project is to get the advantages of both sorts of formats. To accomplish this, the project was designed with several principles in mind:

+

Concept

A lot of data, especially data designed to be used in many different languages, is stored in files or transfered over HTTP as either text files which can represent a wide variety of data structures (e.g. JSON) or in a format created to represent only one specific sort of data (e.g. MP3). The idea with this project is to get the advantages of both sorts of formats. This project is somewhat similar to Google's Protocol Buffers, but was not designed to match its functionality. To accomplish this, the project was designed with several principles in mind:

  • Types (user-created formats of data) are created by combining a wide variety of datatypes, both primitive and recursive. This allows for representations which accurately describe types (e.g. distinguishing between structs and mappings of strings to values, and numeric types, unlike JSON). Types are very customizable, so you can build any desired type formats.
  • Types are kept separate from values (instances of a type) because types are designed to be created once and used to store many different values. This allows for communications to cache the type format after the first use and only have to send the values in subsequent requests.
  • @@ -58,18 +58,22 @@

    Use cases

    • Use when you plan to have many different values for the type (either many different files storing the same sort of information, or many communications of the same sort of information). This will give you the benefit of being able to keep only a single copy of the type spec.
    • Use when there is a lot of repetition in the data. If you don't have any arrays, sets, or maps, you can't really benefit from the cutdown on redundancy.
    +

    Differences from Protocol Buffers

      +
    • Types are generated programmatically rather than by reading .proto files. This allows for functionality like a function which turns a type into another type that either contains an error message or an instance of the original type.
    • +
    • This project is designed with downloading data of known types from servers over HTTP in mind. If the client has already received data of the same type, the server only sends the value and the client reads it using its cached type. If the client doesn't know what the type looks like, the server sends it in byte form along with the value and the client caches the type. This way, the type does not need to be specified in the client-side JavaScript and repeated requests are very efficient.
    • +

    Data types

    • Primitive types
      • Byte (1-byte signed integer)
      • Short (2-byte signed integer)
      • Int (4-byte signed integer)
      • Long (8-byte signed integer)
      • -
      • (planned) BigInt (a signed integer with up to 256 bytes of precision)
      • +
      • BigInt (a signed integer with up to 65535 bytes of precision)
      • UnsignedByte (1-byte unsigned integer)
      • UnsignedShort (2-byte unsigned integer)
      • UnsignedInt (4-byte unsigned integer)
      • UnsignedLong (8-byte unsigned integer)
      • -
      • (planned) BigUnsignedInt (an unsigned integer with up to 256 bytes of precision)
      • +
      • BigUnsignedInt (an unsigned integer with up to 65535 bytes of precision)
      • Date (8-byte unsigned integer representing number of milliseconds since Jan 1, 1970)
      • Float (IEEE 32-bit floating-point number)
      • Double (IEEE 64-bit floating-point number)
      • @@ -277,7 +281,7 @@

        Testing

        To test the NodeJS code, run npm test.


        diff --git a/doc/index.js.html b/doc/index.js.html index 6a21de0..d7cb1fb 100644 --- a/doc/index.js.html +++ b/doc/index.js.html @@ -48,11 +48,12 @@

        Source: index.js

        */ module.exports = {}; +//Copy version string, io functions, and types into package exports for (let sbModule of ['config', 'io', 'structure-types']) { sbModule = require(__dirname + '/' + sbModule + '.js'); for (let attribute in sbModule) module.exports[attribute] = sbModule[attribute]; } -module.exports.r = require(__dirname + '/read.js'); +module.exports.r = require(__dirname + '/read.js'); //add .r to read functions because type() and value() would be confusing @@ -62,7 +63,7 @@

        Source: index.js


        diff --git a/doc/io.js.html b/doc/io.js.html index 00e30cd..4d4f0bc 100644 --- a/doc/io.js.html +++ b/doc/io.js.html @@ -29,6 +29,9 @@

        Source: io.js

        //For use with browserify
         if (__dirname === '/') __dirname = '';
         
        +//This file contains functions for performing I/O;
        +//specifically, reads and writes of types and values and HTTP responses
        +
         const assert = require(__dirname + '/lib/assert.js');
         const BufferStream = require(__dirname + '/lib/buffer-stream.js');
         const GrowableBuffer = require(__dirname + '/lib/growable-buffer.js');
        @@ -151,7 +154,7 @@ 

        Source: io.js

        let type; try { type = r.type(toArrayBuffer(buffer), false) } //eslint-disable-line semi catch (e) { callback(e, null) } //eslint-disable-line semi - if (type) callback(null, type); + if (type) callback(null, type); //if error occurred, don't callback with a null type }); }, /** @@ -187,7 +190,7 @@

        Source: io.js

        let value; try { value = r.value({buffer: toArrayBuffer(buffer), type}) } //eslint-disable-line semi catch (e) { callback(e, null) } //eslint-disable-line semi - if (value) callback(null, value); + if (value) callback(null, value); //if error occurred, don't callback with a null value }); }, /** @@ -219,13 +222,14 @@

        Source: io.js

        inStream.on('end', () => { const buffer = Buffer.concat(segments); let type; + //Using consumeType() in order to get the length of the type (the start of the value) try { type = r._consumeType(toArrayBuffer(buffer), 0) } //eslint-disable-line semi catch (e) { callback(e, null, null) } //eslint-disable-line semi if (type) { let value; try { value = r.value({buffer: toArrayBuffer(buffer), offset: type.length, type: type.value}) } //eslint-disable-line semi catch (e) { callback(e, null, null) } //eslint-disable-line semi - if (value) callback(null, type.value, value); + if (value) callback(null, type.value, value); //if error occurred, don't callback with null value or type } }); }, @@ -252,13 +256,17 @@

        Source: io.js

        res.setHeader('Content-Type', 'application/octet-stream'); res.setHeader('Content-Encoding', 'gzip'); res.setHeader('sig', type.getSignature()); - const outStream = zlib.createGzip(); //eslint-disable-line no-undef - if (req.headers.sig && req.headers.sig === type.getSignature()) io.writeValue({type, value, outStream}, err => { - if (err) callback(err); - }); - else io.writeTypeAndValue({type, value, outStream}, err => { - if (err) callback(err); - }); + const outStream = zlib.createGzip(); //pipe into a zip stream to decrease size of response + if (req.headers.sig && req.headers.sig === type.getSignature()) { //if client already has type, only value needs to be sent + io.writeValue({type, value, outStream}, err => { + if (err) callback(err); + }); + } + else { //otherwise, type and value need to be sent + io.writeTypeAndValue({type, value, outStream}, err => { + if (err) callback(err); + }); + } outStream.pipe(res).on('finish', () => callback(null)); } catch (err) { callback(err) } @@ -273,7 +281,7 @@

        Source: io.js


        diff --git a/doc/lib_buffer-stream.js.html b/doc/lib_buffer-stream.js.html index 7bc6ebb..737dc36 100644 --- a/doc/lib_buffer-stream.js.html +++ b/doc/lib_buffer-stream.js.html @@ -59,14 +59,14 @@

        Source: lib/buffer-stream.js

        } else if (buffer && buffer.constructor === GrowableBuffer) { this.buffer = buffer.rawBuffer; - this.end = buffer.length; + this.end = buffer.length; //end earlier than the end of the raw buffer } else assert.fail('Expected ArrayBuffer or GrowableBuffer, got ' + (buffer ? buffer.constructor.name : String(buffer))); //buffer should always have a constructor if it is neither undefined nor null this.offset = 0; } _read(size) { if (this.offset < this.end) { - this.push(Buffer.from(this.buffer.slice(this.offset, Math.min(this.offset + size, this.end)))); + this.push(Buffer.from(this.buffer.slice(this.offset, Math.min(this.offset + size, this.end)))); //slice behaves nicely when going past the end of the buffer this.offset += size; } else { @@ -86,7 +86,7 @@

        Source: lib/buffer-stream.js


        diff --git a/doc/lib_growable-buffer.js.html b/doc/lib_growable-buffer.js.html index d911f6f..9c9aeed 100644 --- a/doc/lib_growable-buffer.js.html +++ b/doc/lib_growable-buffer.js.html @@ -80,7 +80,7 @@

        Source: lib/growable-buffer.js

        */ grow(size) { assert.integer(size); - if (size > this.buffer.byteLength) { + if (size > this.buffer.byteLength) { //if resizing is necessary const newBuffer = new ArrayBuffer(size << 1); new Uint8Array(newBuffer).set(new Uint8Array(this.buffer).subarray(0, this.size)); this.buffer = newBuffer; @@ -195,7 +195,7 @@

        Source: lib/growable-buffer.js


        diff --git a/doc/r.html b/doc/r.html index 4711a01..3cfbc23 100644 --- a/doc/r.html +++ b/doc/r.html @@ -70,7 +70,7 @@

        r

        Source:
        @@ -262,7 +262,7 @@
        Parameters:
        Source:
        @@ -555,7 +555,7 @@
        Properties
        Source:
        @@ -607,7 +607,7 @@
        Returns:

        diff --git a/doc/read.js.html b/doc/read.js.html index 65c0238..fcaff82 100644 --- a/doc/read.js.html +++ b/doc/read.js.html @@ -29,6 +29,8 @@

        Source: read.js

        //For use with browserify
         if (__dirname === '/') __dirname = '';
         
        +//This file contains functions for reading types and values from bytes
        +
         const assert = require(__dirname + '/lib/assert.js');
         const bitMath = require(__dirname + '/lib/bit-math.js');
         const bufferString = require(__dirname + '/lib/buffer-string.js');
        @@ -37,6 +39,7 @@ 

        Source: read.js

        const util = require('util'); const NOT_LONG_ENOUGH = 'Buffer is not long enough'; +//Reads a 4-byte length buffer function readLengthBuffer(buffer, offset) { try { return { @@ -46,68 +49,47 @@

        Source: read.js

        } catch (e) { assert.fail(NOT_LONG_ENOUGH) } //eslint-disable-line semi } +const SINGLE_BYTE_TYPES = [ //types whose type bytes are only 1 byte long (the type byte) + t.ByteType, + t.ShortType, + t.IntType, + t.LongType, + t.BigIntType, + t.UnsignedByteType, + t.UnsignedShortType, + t.UnsignedIntType, + t.UnsignedLongType, + t.DateType, + t.BigUnsignedIntType, + t.FloatType, + t.DoubleType, + t.BooleanType, + t.BooleanArrayType, + t.CharType, + t.StringType, + t.OctetsType +]; +//Pads a string with preceding 0s so that it has the desired length (for error messages) function pad(str, digits) { if (str.length < digits) return '0'.repeat(digits - str.length) + str; else return str; } +//Reads a type from the specified bytes at the specified offset +//Returns the type that was read and the number of bytes consumed function consumeType(typeBuffer, offset) { assert.assert(offset >= 0, 'Offset is negative: ' + String(offset)); - assert.assert(typeBuffer.byteLength > offset, NOT_LONG_ENOUGH); + assert.assert(typeBuffer.byteLength > offset, NOT_LONG_ENOUGH); //make sure there is a type byte let value, length = 1; - switch (new Uint8Array(typeBuffer)[offset]) { - case t.ByteType._value: - value = new t.ByteType; - break; - case t.ShortType._value: - value = new t.ShortType; - break; - case t.IntType._value: - value = new t.IntType; - break; - case t.LongType._value: - value = new t.LongType; - break; - case t.UnsignedByteType._value: - value = new t.UnsignedByteType; - break; - case t.UnsignedShortType._value: - value = new t.UnsignedShortType; - break; - case t.UnsignedIntType._value: - value = new t.UnsignedIntType; - break; - case t.UnsignedLongType._value: - value = new t.UnsignedLongType; - break; - case t.DateType._value: - value = new t.DateType; - break; - case t.FloatType._value: - value = new t.FloatType; - break; - case t.DoubleType._value: - value = new t.DoubleType; - break; - case t.BooleanType._value: - value = new t.BooleanType; - break; + const typeByte = new Uint8Array(typeBuffer)[offset]; + for (let testType of SINGLE_BYTE_TYPES) { + if (typeByte === testType._value) return {value: new testType, length}; //eslint-disable-line new-cap + } + switch (typeByte) { case t.BooleanTupleType._value: const booleanTupleLength = readLengthBuffer(typeBuffer, offset + length); value = new t.BooleanTupleType(booleanTupleLength.value); length += booleanTupleLength.length; break; - case t.BooleanArrayType._value: - value = new t.BooleanArrayType; - break; - case t.CharType._value: - value = new t.CharType; - break; - case t.StringType._value: - value = new t.StringType; - break; - case t.OctetsType._value: - value = new t.OctetsType; - break; case t.TupleType._value: const tupleType = consumeType(typeBuffer, offset + length); length += tupleType.length; @@ -124,7 +106,7 @@

        Source: read.js

        const fieldCount = castBuffer[offset + length]; length++; const fields = {}; - for (let i = 0; i < fieldCount; i++) { + for (let i = 0; i < fieldCount; i++) { //read field information for each field assert.assert(typeBuffer.byteLength > offset + length, NOT_LONG_ENOUGH); const nameLength = castBuffer[offset + length]; length++; @@ -162,7 +144,7 @@

        Source: read.js

        length++; const values = []; for (let i = 0; i < valueCount; i++) { - const value = consumeValue({buffer: typeBuffer, offset: offset + length, type: enumType.value}); + const value = consumeValue({buffer: typeBuffer, offset: offset + length, type: enumType.value}); //reading values rather than types length += value.length; values[i] = value.value; } @@ -211,7 +193,7 @@

        Source: read.js

        if (fullBuffer) assert.assert(length === typeBuffer.byteLength, 'Did not consume all of the buffer'); return value; } -function readBooleans({buffer, offset, count}) { +function readBooleans({buffer, offset, count}) { //complement to writeBooleans() in structure-types.js const value = new Array(count); const incompleteBytes = bitMath.modEight(value.length); const bytes = bitMath.dividedByEight(value.length); @@ -230,13 +212,15 @@

        Source: read.js

        } return {value, length: byteLength}; } +//Reads a value from the specified bytes at the specified offset, given a type +//Returns the value that was read and the number of bytes consumed (excepting any values being pointed to) function consumeValue({buffer, offset, type}) { let value, length; switch (type.constructor) { case t.ByteType: length = 1; assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); - value = new Int8Array(buffer)[offset]; + value = new Int8Array(buffer)[offset]; //endianness doesn't matter because there is only 1 byte break; case t.ShortType: length = 2; @@ -257,10 +241,24 @@

        Source: read.js

        const lower = longView.getUint32(offset + 4); value = strint.add(strint.mul(String(upper), strint.LONG_UPPER_SHIFT), String(lower)); break; + case t.BigIntType: + length = 2; + assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); + const bigIntView = new DataView(buffer); + const bigIntBytes = bigIntView.getUint16(offset); + assert.assert(buffer.byteLength >= offset + length + bigIntBytes, NOT_LONG_ENOUGH); + if (bigIntBytes) value = String(bigIntView.getInt8(offset + length)); + else value = '0'; + for (let byte = 1; byte < bigIntBytes; byte++) { + if (byte) value = strint.mul(value, strint.BYTE_SHIFT); //after the first byte, shift everything left one byte before adding + value = strint.add(value, String(bigIntView.getUint8(offset + length + byte))); + } + length += bigIntBytes; + break; case t.UnsignedByteType: length = 1; assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); - value = new Uint8Array(buffer)[offset]; + value = new Uint8Array(buffer)[offset]; //endianness doesn't matter because there is only 1 byte break; case t.UnsignedShortType: length = 2; @@ -282,6 +280,19 @@

        Source: read.js

        value = strint.add(strint.mul(String(unsignedUpper), strint.LONG_UPPER_SHIFT), String(unsignedLower)); if (type.constructor === t.DateType) value = new Date(Number(value)); break; + case t.BigUnsignedIntType: + length = 2; + assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); + const bigUnsignedView = new DataView(buffer); + const bigUnsignedBytes = bigUnsignedView.getUint16(offset); + assert.assert(buffer.byteLength >= offset + length + bigUnsignedBytes, NOT_LONG_ENOUGH); + value = '0'; + for (let byte = 0; byte < bigUnsignedBytes; byte++) { + if (byte) value = strint.mul(value, strint.BYTE_SHIFT); //after the first byte, shift everything left one byte before adding + value = strint.add(value, String(bigUnsignedView.getUint8(offset + length + byte))); + } + length += bigUnsignedBytes; + break; case t.FloatType: length = 4; assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); @@ -297,7 +308,7 @@

        Source: read.js

        assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); const readByte = new Uint8Array(buffer)[offset]; assert.assert((readByte === 0x00 || readByte === 0xFF), '0x' + readByte.toString(16) + ' is an invalid Boolean value'); - value = !!readByte; + value = !!readByte; //convert integer to boolean break; case t.BooleanArrayType: const booleanArrayLength = readLengthBuffer(buffer, offset); @@ -426,6 +437,7 @@

        Source: read.js

        if (offset === undefined) offset = 0; //for some reason, isparta doesn't like default parameters inside destructuring assert.instanceOf(offset, Number); const {value} = consumeValue({buffer, offset, type}); + //no length validation because bytes being pointed to don't get counted in the length return value; } @@ -469,7 +481,7 @@

        Source: read.js


        diff --git a/doc/structure-types.js.html b/doc/structure-types.js.html index 4a2e508..1ca4b21 100644 --- a/doc/structure-types.js.html +++ b/doc/structure-types.js.html @@ -29,6 +29,9 @@

        Source: structure-types.js

        //For use with browserify
         if (__dirname === '/') __dirname = '';
         
        +//This file contains definitions for all the types
        +//and their writing to bytes methods
        +
         const assert = require(__dirname + '/lib/assert.js');
         const base64 = require('base64-js');
         const bufferString = require(__dirname + '/lib/buffer-string.js');
        @@ -47,21 +50,27 @@ 

        Source: structure-types.js

        return buffer; } //After writing all the values, it is necessary to insert all the values of pointer types +//This function should be called in writeValue() for every type that could have a subtype that is a pointer type function setPointers(buffer, root) { if (root) { //ensure this only happens once if (buffer.pointers) { - for (let [binaryString, insertionIndices] of buffer.pointers) { - const index = buffer.length; - buffer.addAll(bufferString.fromBinaryString(binaryString)); + for (let [binaryString, insertionIndices] of buffer.pointers) { //find all the locations where pointers must be inserted + const index = buffer.length; //value is going to be appended to buffer, so it will start at buffer.length + buffer.addAll(bufferString.fromBinaryString(binaryString)); //add raw data const indexBuffer = new ArrayBuffer(4); new DataView(indexBuffer).setUint32(0, index); + //In each pointer location, set the bytes to be a pointer to the correct location for (let insertionIndex of insertionIndices) buffer.setAll(insertionIndex, indexBuffer); } } } } -const REPEATED_TYPE = 0xFF; //type byte indicating next 2 bytes are an unsigned short containing the location of the type +//Type byte indicating next 2 bytes are an unsigned short containing the location of the type +//The unsigned short is a negative offset from this type byte to the true location +const REPEATED_TYPE = 0xFF; +//Stored to avoid constructing the string multiple times +const CACHED = 'cached'; /** * The superclass of each class representing a possible type. @@ -88,7 +97,7 @@

        Source: structure-types.js

        */ addToBuffer(buffer) { assert.instanceOf(buffer, GrowableBuffer); - if (this.cachedTypeLocations) { + if (this.cachedTypeLocations) { //only bother checking if type has already been written if there are cached locations const location = this.cachedTypeLocations.get(buffer); if (location !== undefined) { //if type has already been written to this buffer, can create a pointer to it buffer.add(REPEATED_TYPE); @@ -102,7 +111,7 @@

        Source: structure-types.js

        } } else this.cachedTypeLocations = new Map; - this.cachedTypeLocations.set(buffer, buffer.length); + this.cachedTypeLocations.set(buffer, buffer.length); //future uses of this type will be able to point to this position in the buffer buffer.add(this.constructor._value); return true; } @@ -188,15 +197,18 @@

        Source: structure-types.js

        /** * Returns whether this type object represents the same type as another object * @param {Type} otherType Another object to compare with - * @return {boolean} {@link true} iff the types have the same constructor and the same field values for fields not starting with {@link 'cached'} + * @return {boolean} {@link true} iff the types have the same constructor and the same field values for fields that don't store cached results */ equals(otherType) { + //Other type must be descended from the same class (this check will ensure that otherType is not null or undefined) try { assert.instanceOf(otherType, this.constructor) } //eslint-disable-line semi catch (e) { return false } //eslint-disable-line semi + //Other type must have the same constructor try { assert.equal(otherType.constructor, this.constructor) } //eslint-disable-line semi catch (e) { return false } //eslint-disable-line semi + //Each non-cached property should match for (let param in this) { - if (this.hasOwnProperty(param) && !param.startsWith('cached')) { + if (this.hasOwnProperty(param) && !param.startsWith(CACHED)) { try { assert.equal(otherType[param], this[param]) } //eslint-disable-line semi catch (e) { return false } //eslint-disable-line semi } @@ -219,7 +231,7 @@

        Source: structure-types.js

        if (!isNaN(converted)) return converted; } } - return undefined; + return undefined; //returned if conversion failed } /** @@ -305,6 +317,7 @@

        Source: structure-types.js

        buffer.addAll(byteBuffer); } } +const LONG_MAX = '9223372036854775807', LONG_MIN = '-9223372036854775808'; /** * A type storing an 8-byte signed integer * @extends Type @@ -317,13 +330,13 @@

        Source: structure-types.js

        /** * Appends value bytes to a {@link GrowableBuffer} according to the type * @param {GrowableBuffer} buffer The buffer to which to append - * @param {string} value The value to write + * @param {string} value The value to write (a base-10 string representation of an integer) * @throws {Error} If the value doesn't match the type, e.g. {@link new sb.StringType().writeValue(buffer, 23)} */ writeValue(buffer, value) { assert.instanceOf(buffer, GrowableBuffer); assert.instanceOf(value, String); - if (strint.gt(value, '9223372036854775807') || strint.lt(value, '-9223372036854775808')) assert.fail('Value out of range'); + if (strint.gt(value, LONG_MAX) || strint.lt(value, LONG_MIN)) assert.fail('Value out of range'); const upper = strint.div(value, strint.LONG_UPPER_SHIFT, true); //get upper signed int const lower = strint.sub(value, strint.mul(upper, strint.LONG_UPPER_SHIFT)); //get lower unsigned int const byteBuffer = new ArrayBuffer(8); @@ -333,6 +346,47 @@

        Source: structure-types.js

        buffer.addAll(byteBuffer); } } +/** + * A type storing an arbitrary precision signed integer + * (up to 65535 bytes of precision). + * Each written value has its own number of bytes of precision. + * @extends Type + * @inheritdoc + */ +class BigIntType extends IntegerType { + static get _value() { + return 0x06; + } + /** + * Appends value bytes to a {@link GrowableBuffer} according to the type + * @param {GrowableBuffer} buffer The buffer to which to append + * @param {string} value The value to write (a base-10 string representation of an integer) + * @throws {Error} If the value doesn't match the type, e.g. {@link new sb.StringType().writeValue(buffer, 23)} + */ + writeValue(buffer, value) { + assert.instanceOf(buffer, GrowableBuffer); + assert.instanceOf(value, String); + value = strint.normalize(value); //throws if value is invalid + const bytes = []; + if (!strint.eq(value, '0')) { + while (strint.gt(value, '127') || strint.lt(value, '-128')) { //builds bytes in LE order + const quotient = strint.div(value, strint.BYTE_SHIFT, true); + const remainder = strint.sub(value, strint.mul(quotient, strint.BYTE_SHIFT)); + bytes.push(Number(remainder)); + value = quotient; + } + bytes.push(Number(value)); + assert.twoByteUnsignedInteger(bytes.length); + } + const byteBuffer = new ArrayBuffer(2 + bytes.length); + const dataView = new DataView(byteBuffer); + dataView.setUint16(0, bytes.length); //use 2 bytes to store the number of bytes in the value + let offset = 3; + for (let i = bytes.length - 2; i > -1; i--, offset++) dataView.setUint8(offset, bytes[i]); //write in reverse order to get BE + if (bytes.length) dataView.setInt8(2, bytes[bytes.length - 1]); //highest byte is signed so it must be treated separately + buffer.addAll(byteBuffer); + } +} /** * A type storing an unsigned integer @@ -417,12 +471,13 @@

        Source: structure-types.js

        buffer.addAll(byteBuffer); } } -function writeUnsignedLong(buffer, value) { +const UNSIGNED_LONG_MAX = '18446744073709551615'; +function writeUnsignedLong(buffer, value) { //used for both UnsignedLongType and DateType assert.instanceOf(buffer, GrowableBuffer); assert.instanceOf(value, String); - if (strint.gt(value, '18446744073709551615') || strint.lt(value, '0')) assert.fail('Value out of range'); - const upper = strint.div(value, strint.LONG_UPPER_SHIFT); - const lower = strint.sub(value, strint.mul(upper, strint.LONG_UPPER_SHIFT)); + if (strint.gt(value, UNSIGNED_LONG_MAX) || strint.lt(value, '0')) assert.fail('Value out of range'); + const upper = strint.div(value, strint.LONG_UPPER_SHIFT); //get upper unsigned int + const lower = strint.sub(value, strint.mul(upper, strint.LONG_UPPER_SHIFT)); //get lower unsigned int const byteBuffer = new ArrayBuffer(8); const dataView = new DataView(byteBuffer); dataView.setUint32(0, Number(upper)); @@ -441,7 +496,7 @@

        Source: structure-types.js

        /** * Appends value bytes to a {@link GrowableBuffer} according to the type * @param {GrowableBuffer} buffer The buffer to which to append - * @param {string} value The value to write + * @param {string} value The value to write (a base-10 string representation of an integer) * @throws {Error} If the value doesn't match the type, e.g. {@link new sb.StringType().writeValue(buffer, 23)} */ writeValue(buffer, value) { @@ -469,6 +524,45 @@

        Source: structure-types.js

        writeUnsignedLong(buffer, String(value.getTime())); } } +/** + * A type storing an arbitrary precision unsigned integer + * (up to 65535 bytes of precision). + * Each written value has its own number of bytes of precision. + * @extends Type + * @inheritdoc + */ +class BigUnsignedIntType extends UnsignedType { + static get _value() { + return 0x16; + } + /** + * Appends value bytes to a {@link GrowableBuffer} according to the type + * @param {GrowableBuffer} buffer The buffer to which to append + * @param {string} value The value to write (a base-10 string representation of an integer) + * @throws {Error} If the value doesn't match the type, e.g. {@link new sb.StringType().writeValue(buffer, 23)} + */ + writeValue(buffer, value) { + assert.instanceOf(buffer, GrowableBuffer); + assert.instanceOf(value, String); + if (strint.isNegative(value)) assert.fail('Value out of range'); + const bytes = []; + if (!strint.eq(value, '0')) { //if value is 0, avoid adding a 0 byte + while (strint.ge(value, strint.BYTE_SHIFT)) { //builds bytes in LE order + const [quotient, remainder] = strint.quotientRemainderPositive(value, strint.BYTE_SHIFT); + bytes.push(Number(remainder)); + value = quotient; + } + bytes.push(Number(value)); + assert.twoByteUnsignedInteger(bytes.length); + } + const byteBuffer = new ArrayBuffer(2 + bytes.length); + const dataView = new DataView(byteBuffer); + dataView.setUint16(0, bytes.length); //use 2 bytes to store the number of bytes in the value + let offset = 2; + for (let i = bytes.length - 1; i > -1; i--, offset++) dataView.setUint8(offset, bytes[i]); //write in reverse order to get BE + buffer.addAll(byteBuffer); + } +} /** * A type storing a [floating-point number]{@linkplain https://en.wikipedia.org/wiki/Floating_point} @@ -544,14 +638,16 @@

        Source: structure-types.js

        writeValue(buffer, value) { assert.instanceOf(buffer, GrowableBuffer); assert.instanceOf(value, Boolean); - if (value) buffer.add(0xFF); + if (value) buffer.add(0xFF); //all bits are set for good measure else buffer.add(0x00); } } +//Writes an array of booleans for BooleanTupleType or BooleanArrayType +//The boolean at index 8a + b is in the bth MSB (0-indexed) of the ath byte function writeBooleans(buffer, booleans) { assert.instanceOf(booleans, Array); - const incompleteBytes = modEight(booleans.length); - const bytes = dividedByEight(booleans.length); + const incompleteBytes = modEight(booleans.length); //whether the booleans take up a partial byte + const bytes = dividedByEight(booleans.length); //floored, so need to add one if incompleteBytes let length; if (incompleteBytes) length = bytes + 1; else length = bytes; @@ -561,6 +657,7 @@

        Source: structure-types.js

        const boolean = booleans[i]; assert.instanceOf(boolean, Boolean); const bit = modEight(~modEight(i)); //7 - (i % 8) + //Set desired bit, leaving the others unchanges if (boolean) castBuffer[dividedByEight(i)] |= 1 << bit; else castBuffer[dividedByEight(i)] &= ~(1 << bit); } @@ -667,7 +764,7 @@

        Source: structure-types.js

        assert.instanceOf(value, String); const valueBuffer = bufferString.fromString(value); buffer.addAll(valueBuffer); - buffer.add(0); + buffer.add(0); //add a null byte to make clear where the end is } } /** @@ -774,27 +871,31 @@

        Source: structure-types.js

        constructor(fields) { super(); assert.instanceOf(fields, Object); + //Allow only 255 fields let fieldCount = 0; for (let _ in fields) fieldCount++; //eslint-disable-line no-unused-vars try { assert.byteUnsignedInteger(fieldCount); } catch (e) { assert.fail(String(fieldCount) + ' fields is too many'); } + this.fields = new Array(fieldCount); //really a set, but we want ordering to be fixed so that type bytes are consistent let i = 0; for (let fieldName in fields) { + //Name must fit in 255 UTF-8 bytes const fieldNameBuffer = bufferString.fromString(fieldName); try { assert.byteUnsignedInteger(fieldNameBuffer.byteLength); } catch (e) { assert.fail('Field name ' + fieldName + ' is too long'); } + //Type must be a Type const fieldType = fields[fieldName]; try { assert.instanceOf(fieldType, Type); } catch (e) { assert.fail(String(fieldType) + ' is not a valid field type'); } const resultField = {}; resultField[NAME] = fieldName; resultField[TYPE] = fieldType; - resultField[NAME_BUFFER] = fieldNameBuffer; + resultField[NAME_BUFFER] = fieldNameBuffer; //cache the written name for use in addToBuffer() this.fields[i] = resultField; i++; } - this.fields.sort((a, b) => { //so field order is predictable + this.fields.sort((a, b) => { //sort by field name so field order is predictable if (a[NAME] < b[NAME]) return -1; else if (a[NAME] > b[NAME]) return 1; }); @@ -804,7 +905,7 @@

        Source: structure-types.js

        buffer.add(this.fields.length); for (let field of this.fields) { const nameBuffer = field[NAME_BUFFER]; - buffer.add(nameBuffer.byteLength); + buffer.add(nameBuffer.byteLength); //not using null-terminated string because length is only 1 byte buffer.addAll(nameBuffer); field[TYPE].addToBuffer(buffer); } @@ -969,7 +1070,7 @@

        Source: structure-types.js

        assert.instanceOf(value, Map); assert.fourByteUnsignedInteger(value.size); buffer.addAll(lengthBuffer(value.size)); - for (let [mapKey, mapValue] of value) { + for (let [mapKey, mapValue] of value) { //for each key-value pairing, write key and value this.keyType.writeValue(buffer, mapKey, false); this.valueType.writeValue(buffer, mapValue, false); } @@ -1008,19 +1109,21 @@

        Source: structure-types.js

        super(); assert.instanceOf(type, AbsoluteType); //pointer types don't make sense because each value should be distinct assert.instanceOf(values, Array); + //At most 255 values allowed try { assert.byteUnsignedInteger(values.length); } catch (e) { assert.fail(String(values.length) + ' values is too many'); } + const valueIndices = new Map; for (let i = 0; i < values.length; i++) { const value = values[i]; const valueBuffer = new GrowableBuffer; type.writeValue(valueBuffer, value, false); - const valueString = bufferString.toBinaryString(valueBuffer.toBuffer()); + const valueString = bufferString.toBinaryString(valueBuffer.toBuffer()); //convert value to bytes and then string for use as a map key assert.assert(!valueIndices.has(valueString), 'Value is repeated: ' + util.inspect(value)); - valueIndices.set(valueString, i); + valueIndices.set(valueString, i); //so writing a value has constant-time lookup into the values array } this.type = type; - this.values = values; + this.values = values; //used when reading to get constant-time lookup of value index into value this.valueIndices = valueIndices; } addToBuffer(buffer) { @@ -1044,7 +1147,7 @@

        Source: structure-types.js

        this.type.writeValue(valueBuffer, value, false); const index = this.valueIndices.get(bufferString.toBinaryString(valueBuffer.toBuffer())); assert.assert(index !== undefined, 'Not a valid enum value: ' + util.inspect(value)); - buffer.add(index); + buffer.add(index); //write the index to the requested value in the values array setPointers(buffer, root); } } @@ -1098,6 +1201,7 @@

        Source: structure-types.js

        writeValue(buffer, value, root = true) { assert.instanceOf(buffer, GrowableBuffer); let success = false; + //Try to write value using each type in order until no error is thrown for (let i = 0; i < this.types.length; i++) { const type = this.types[i]; const valueBuffer = new GrowableBuffer; @@ -1228,14 +1332,14 @@

        Source: structure-types.js

        * tribeType.writeValue(buffer, value); */ writeValue(buffer, value, root = true) { - if (buffer.pointers === undefined) buffer.pointers = new Map; + if (!buffer.pointers) buffer.pointers = new Map; //initialize pointers map if it doesn't exist const valueBuffer = new GrowableBuffer; this.type.writeValue(valueBuffer, value, false); const valueString = bufferString.toBinaryString(valueBuffer.toBuffer()); //have to convert the buffer to a string because equivalent buffers are not === const currentIndex = buffer.length; - const previousSet = buffer.pointers.get(valueString); - if (previousSet) previousSet.add(currentIndex); - else buffer.pointers.set(valueString, new Set([currentIndex])); + const pointerLocations = buffer.pointers.get(valueString); + if (pointerLocations) pointerLocations.add(currentIndex); + else buffer.pointers.set(valueString, new Set([currentIndex])); //buffer.pointers maps values to the set of indices that need to point to the value buffer.addAll(new ArrayBuffer(4)); //placeholder for pointer setPointers(buffer, root); } @@ -1247,11 +1351,13 @@

        Source: structure-types.js

        ShortType, IntType, LongType, + BigIntType, UnsignedByteType, UnsignedShortType, UnsignedIntType, UnsignedLongType, DateType, + BigUnsignedIntType, FloatType, DoubleType, BooleanType, @@ -1280,7 +1386,7 @@

        Source: structure-types.js


        diff --git a/lib/assert.js b/lib/assert.js index 6ff7313..a10fe47 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -36,6 +36,11 @@ const assert = { assert.integer(value); assert.between(0, value, 256); }, + //Assert that a number fits in an unsigned short + twoByteUnsignedInteger(value) { + assert.integer(value); + assert.between(0, value, 65536); + }, //Assert that a number fits in an unsigned integer fourByteUnsignedInteger(value) { assert.integer(value); diff --git a/lib/strint.js b/lib/strint.js index 240745e..511bd2f 100644 --- a/lib/strint.js +++ b/lib/strint.js @@ -227,7 +227,7 @@ var e = {}; var absResult = quotientRemainderPositive(abs(dividend), abs(divisor))[0]; if (!sameSign(dividend, divisor)) absResult = negate(absResult); - if (floorNeg && !eq(mul(absResult, divisor), dividend) && isNegative(absResult)) absResult = sub(absResult, '1'); //if floorNeg is omitted, it will evaluate to false + if (floorNeg && !eq(mul(absResult, divisor), dividend) && isNegative(absResult)) absResult = sub(absResult, '1'); return absResult; }; @@ -402,4 +402,5 @@ var e = {}; })(); e.LONG_UPPER_SHIFT = '4294967296'; //stores the value needed to multiply an integer to shift it left 32 bits - for long math +e.BYTE_SHIFT = '256'; //stores the value needed to multiply an integer to shift it left 8 bits - for big int math module.exports = e; \ No newline at end of file diff --git a/package.json b/package.json index b5726e5..f6b5fa9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "structure-bytes", - "version": "2.8.7", + "version": "2.9.8", "description": "Efficiently stores data of any shape by separating it into structure and value", "main": "index.js", "dependencies": { diff --git a/read.js b/read.js index 5e0ac32..e0ac713 100644 --- a/read.js +++ b/read.js @@ -21,6 +21,26 @@ function readLengthBuffer(buffer, offset) { } catch (e) { assert.fail(NOT_LONG_ENOUGH) } //eslint-disable-line semi } +const SINGLE_BYTE_TYPES = [ //types whose type bytes are only 1 byte long (the type byte) + t.ByteType, + t.ShortType, + t.IntType, + t.LongType, + t.BigIntType, + t.UnsignedByteType, + t.UnsignedShortType, + t.UnsignedIntType, + t.UnsignedLongType, + t.DateType, + t.BigUnsignedIntType, + t.FloatType, + t.DoubleType, + t.BooleanType, + t.BooleanArrayType, + t.CharType, + t.StringType, + t.OctetsType +]; //Pads a string with preceding 0s so that it has the desired length (for error messages) function pad(str, digits) { if (str.length < digits) return '0'.repeat(digits - str.length) + str; @@ -32,60 +52,16 @@ function consumeType(typeBuffer, offset) { assert.assert(offset >= 0, 'Offset is negative: ' + String(offset)); assert.assert(typeBuffer.byteLength > offset, NOT_LONG_ENOUGH); //make sure there is a type byte let value, length = 1; - switch (new Uint8Array(typeBuffer)[offset]) { - case t.ByteType._value: - value = new t.ByteType; - break; - case t.ShortType._value: - value = new t.ShortType; - break; - case t.IntType._value: - value = new t.IntType; - break; - case t.LongType._value: - value = new t.LongType; - break; - case t.UnsignedByteType._value: - value = new t.UnsignedByteType; - break; - case t.UnsignedShortType._value: - value = new t.UnsignedShortType; - break; - case t.UnsignedIntType._value: - value = new t.UnsignedIntType; - break; - case t.UnsignedLongType._value: - value = new t.UnsignedLongType; - break; - case t.DateType._value: - value = new t.DateType; - break; - case t.FloatType._value: - value = new t.FloatType; - break; - case t.DoubleType._value: - value = new t.DoubleType; - break; - case t.BooleanType._value: - value = new t.BooleanType; - break; + const typeByte = new Uint8Array(typeBuffer)[offset]; + for (let testType of SINGLE_BYTE_TYPES) { + if (typeByte === testType._value) return {value: new testType, length}; //eslint-disable-line new-cap + } + switch (typeByte) { case t.BooleanTupleType._value: const booleanTupleLength = readLengthBuffer(typeBuffer, offset + length); value = new t.BooleanTupleType(booleanTupleLength.value); length += booleanTupleLength.length; break; - case t.BooleanArrayType._value: - value = new t.BooleanArrayType; - break; - case t.CharType._value: - value = new t.CharType; - break; - case t.StringType._value: - value = new t.StringType; - break; - case t.OctetsType._value: - value = new t.OctetsType; - break; case t.TupleType._value: const tupleType = consumeType(typeBuffer, offset + length); length += tupleType.length; @@ -237,6 +213,20 @@ function consumeValue({buffer, offset, type}) { const lower = longView.getUint32(offset + 4); value = strint.add(strint.mul(String(upper), strint.LONG_UPPER_SHIFT), String(lower)); break; + case t.BigIntType: + length = 2; + assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); + const bigIntView = new DataView(buffer); + const bigIntBytes = bigIntView.getUint16(offset); + assert.assert(buffer.byteLength >= offset + length + bigIntBytes, NOT_LONG_ENOUGH); + if (bigIntBytes) value = String(bigIntView.getInt8(offset + length)); + else value = '0'; + for (let byte = 1; byte < bigIntBytes; byte++) { + if (byte) value = strint.mul(value, strint.BYTE_SHIFT); //after the first byte, shift everything left one byte before adding + value = strint.add(value, String(bigIntView.getUint8(offset + length + byte))); + } + length += bigIntBytes; + break; case t.UnsignedByteType: length = 1; assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); @@ -262,6 +252,19 @@ function consumeValue({buffer, offset, type}) { value = strint.add(strint.mul(String(unsignedUpper), strint.LONG_UPPER_SHIFT), String(unsignedLower)); if (type.constructor === t.DateType) value = new Date(Number(value)); break; + case t.BigUnsignedIntType: + length = 2; + assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); + const bigUnsignedView = new DataView(buffer); + const bigUnsignedBytes = bigUnsignedView.getUint16(offset); + assert.assert(buffer.byteLength >= offset + length + bigUnsignedBytes, NOT_LONG_ENOUGH); + value = '0'; + for (let byte = 0; byte < bigUnsignedBytes; byte++) { + if (byte) value = strint.mul(value, strint.BYTE_SHIFT); //after the first byte, shift everything left one byte before adding + value = strint.add(value, String(bigUnsignedView.getUint8(offset + length + byte))); + } + length += bigUnsignedBytes; + break; case t.FloatType: length = 4; assert.assert(buffer.byteLength >= offset + length, NOT_LONG_ENOUGH); diff --git a/structure-types.js b/structure-types.js index 87e7767..3e4ee79 100644 --- a/structure-types.js +++ b/structure-types.js @@ -169,7 +169,7 @@ class Type { /** * Returns whether this type object represents the same type as another object * @param {Type} otherType Another object to compare with - * @return {boolean} {@link true} iff the types have the same constructor and the same field values for fields not starting with {@link 'cached'} + * @return {boolean} {@link true} iff the types have the same constructor and the same field values for fields that don't store cached results */ equals(otherType) { //Other type must be descended from the same class (this check will ensure that otherType is not null or undefined) @@ -302,7 +302,7 @@ class LongType extends IntegerType { /** * Appends value bytes to a {@link GrowableBuffer} according to the type * @param {GrowableBuffer} buffer The buffer to which to append - * @param {string} value The value to write + * @param {string} value The value to write (a base-10 string representation of an integer) * @throws {Error} If the value doesn't match the type, e.g. {@link new sb.StringType().writeValue(buffer, 23)} */ writeValue(buffer, value) { @@ -318,6 +318,47 @@ class LongType extends IntegerType { buffer.addAll(byteBuffer); } } +/** + * A type storing an arbitrary precision signed integer + * (up to 65535 bytes of precision). + * Each written value has its own number of bytes of precision. + * @extends Type + * @inheritdoc + */ +class BigIntType extends IntegerType { + static get _value() { + return 0x06; + } + /** + * Appends value bytes to a {@link GrowableBuffer} according to the type + * @param {GrowableBuffer} buffer The buffer to which to append + * @param {string} value The value to write (a base-10 string representation of an integer) + * @throws {Error} If the value doesn't match the type, e.g. {@link new sb.StringType().writeValue(buffer, 23)} + */ + writeValue(buffer, value) { + assert.instanceOf(buffer, GrowableBuffer); + assert.instanceOf(value, String); + value = strint.normalize(value); //throws if value is invalid + const bytes = []; + if (!strint.eq(value, '0')) { + while (strint.gt(value, '127') || strint.lt(value, '-128')) { //builds bytes in LE order + const quotient = strint.div(value, strint.BYTE_SHIFT, true); + const remainder = strint.sub(value, strint.mul(quotient, strint.BYTE_SHIFT)); + bytes.push(Number(remainder)); + value = quotient; + } + bytes.push(Number(value)); + assert.twoByteUnsignedInteger(bytes.length); + } + const byteBuffer = new ArrayBuffer(2 + bytes.length); + const dataView = new DataView(byteBuffer); + dataView.setUint16(0, bytes.length); //use 2 bytes to store the number of bytes in the value + let offset = 3; + for (let i = bytes.length - 2; i > -1; i--, offset++) dataView.setUint8(offset, bytes[i]); //write in reverse order to get BE + if (bytes.length) dataView.setInt8(2, bytes[bytes.length - 1]); //highest byte is signed so it must be treated separately + buffer.addAll(byteBuffer); + } +} /** * A type storing an unsigned integer @@ -427,7 +468,7 @@ class UnsignedLongType extends UnsignedType { /** * Appends value bytes to a {@link GrowableBuffer} according to the type * @param {GrowableBuffer} buffer The buffer to which to append - * @param {string} value The value to write + * @param {string} value The value to write (a base-10 string representation of an integer) * @throws {Error} If the value doesn't match the type, e.g. {@link new sb.StringType().writeValue(buffer, 23)} */ writeValue(buffer, value) { @@ -455,6 +496,45 @@ class DateType extends AbsoluteType { writeUnsignedLong(buffer, String(value.getTime())); } } +/** + * A type storing an arbitrary precision unsigned integer + * (up to 65535 bytes of precision). + * Each written value has its own number of bytes of precision. + * @extends Type + * @inheritdoc + */ +class BigUnsignedIntType extends UnsignedType { + static get _value() { + return 0x16; + } + /** + * Appends value bytes to a {@link GrowableBuffer} according to the type + * @param {GrowableBuffer} buffer The buffer to which to append + * @param {string} value The value to write (a base-10 string representation of an integer) + * @throws {Error} If the value doesn't match the type, e.g. {@link new sb.StringType().writeValue(buffer, 23)} + */ + writeValue(buffer, value) { + assert.instanceOf(buffer, GrowableBuffer); + assert.instanceOf(value, String); + if (strint.isNegative(value)) assert.fail('Value out of range'); + const bytes = []; + if (!strint.eq(value, '0')) { //if value is 0, avoid adding a 0 byte + while (strint.ge(value, strint.BYTE_SHIFT)) { //builds bytes in LE order + const [quotient, remainder] = strint.quotientRemainderPositive(value, strint.BYTE_SHIFT); + bytes.push(Number(remainder)); + value = quotient; + } + bytes.push(Number(value)); + assert.twoByteUnsignedInteger(bytes.length); + } + const byteBuffer = new ArrayBuffer(2 + bytes.length); + const dataView = new DataView(byteBuffer); + dataView.setUint16(0, bytes.length); //use 2 bytes to store the number of bytes in the value + let offset = 2; + for (let i = bytes.length - 1; i > -1; i--, offset++) dataView.setUint8(offset, bytes[i]); //write in reverse order to get BE + buffer.addAll(byteBuffer); + } +} /** * A type storing a [floating-point number]{@linkplain https://en.wikipedia.org/wiki/Floating_point} @@ -1243,11 +1323,13 @@ module.exports = { ShortType, IntType, LongType, + BigIntType, UnsignedByteType, UnsignedShortType, UnsignedIntType, UnsignedLongType, DateType, + BigUnsignedIntType, FloatType, DoubleType, BooleanType, diff --git a/test/type-bytes/big-int.js b/test/type-bytes/big-int.js new file mode 100644 index 0000000..37dd8eb --- /dev/null +++ b/test/type-bytes/big-int.js @@ -0,0 +1,5 @@ +/*eslint-disable no-undef*/ +let type = new t.BigIntType; +let buffer = type.toBuffer(); +assert.equal(buffer, bufferFrom([0x06])); +assert.equal(r.type(buffer), new t.BigIntType); \ No newline at end of file diff --git a/test/type-bytes/big-unsigned-int.js b/test/type-bytes/big-unsigned-int.js new file mode 100644 index 0000000..5d34527 --- /dev/null +++ b/test/type-bytes/big-unsigned-int.js @@ -0,0 +1,5 @@ +/*eslint-disable no-undef*/ +let type = new t.BigUnsignedIntType; +let buffer = type.toBuffer(); +assert.equal(buffer, bufferFrom([0x16])); +assert.equal(r.type(buffer), new t.BigUnsignedIntType); \ No newline at end of file diff --git a/test/type-bytes/signature.js b/test/type-bytes/signature.js index 97d7eb6..2c4961a 100644 --- a/test/type-bytes/signature.js +++ b/test/type-bytes/signature.js @@ -1,5 +1,5 @@ /*eslint-disable no-undef*/ -assert.equal(new t.ByteType().getSignature(), 'AAc=S/USLzRFVMU73i67jNK349FgCtYxw4Wl18ziPHeFRZo='); +assert.equal(new t.ByteType().getSignature(), 'AAg=S/USLzRFVMU73i67jNK349FgCtYxw4Wl18ziPHeFRZo='); let type = new t.StructType({ bcd: new t.PointerType( new t.OptionalType( @@ -17,4 +17,4 @@ let type = new t.StructType({ ) ) }); -assert.equal(type.getSignature(), 'AAc=URZ81sn26XuBj9ckIE65/aNkAylI8xHXWB+8V34RJBs='); \ No newline at end of file +assert.equal(type.getSignature(), 'AAg=URZ81sn26XuBj9ckIE65/aNkAylI8xHXWB+8V34RJBs='); \ No newline at end of file diff --git a/test/value-bytes/big-int.js b/test/value-bytes/big-int.js new file mode 100644 index 0000000..d40dbed --- /dev/null +++ b/test/value-bytes/big-int.js @@ -0,0 +1,20 @@ +/*eslint-disable no-undef*/ +let type = new t.BigIntType; +const VALUE = '-1234567890'; +let buffer = type.valueBuffer(VALUE); +const bytes = [0xb6, 0x69, 0xfd, 0x2e]; +assert.equal(buffer, concat([bufferFrom([0, bytes.length]), bufferFrom(bytes)])); +assert.equal(r.value({buffer, type}), VALUE); +buffer = type.valueBuffer('0'); +assert.equal(buffer, bufferFill(2, 0)); +assert.equal(r.value({buffer, type}), '0'); +buffer = type.valueBuffer('-128'); +assert.equal(buffer, bufferFrom([0, 1, -128 + 256])); +assert.equal(r.value({buffer, type}), '-128'); +buffer = type.valueBuffer('127'); +assert.equal(buffer, bufferFrom([0, 1, 127])); +assert.equal(r.value({buffer, type}), '127'); +assert.throws( + () => type.valueBuffer('120971.00'), + 'Illegal strint format: 120971.00' +); \ No newline at end of file diff --git a/test/value-bytes/big-unsigned-int.js b/test/value-bytes/big-unsigned-int.js new file mode 100644 index 0000000..37f0af2 --- /dev/null +++ b/test/value-bytes/big-unsigned-int.js @@ -0,0 +1,18 @@ +/*eslint-disable no-undef*/ +let type = new t.BigUnsignedIntType; +const VALUE = '81129638414606663681390495662081'; +let buffer = type.valueBuffer(VALUE); +const bytes = [0x3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; +assert.equal(buffer, concat([bufferFrom([0, bytes.length]), bufferFrom(bytes)])); +assert.equal(r.value({buffer, type}), VALUE); +buffer = type.valueBuffer('0'); +assert.equal(buffer, bufferFill(2, 0)); +assert.equal(r.value({buffer, type}), '0'); +assert.throws( + () => type.valueBuffer('120971.00'), + 'Illegal strint format: 120971.00' +); +assert.throws( + () => type.valueBuffer('-1'), + 'Value out of range' +); \ No newline at end of file