Socket
Socket
Sign inDemoInstall

@geckos.io/typed-array-buffer-schema

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@geckos.io/typed-array-buffer-schema - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

bundle/typed-array-buffer-schema.tmp.js

2

bundle/typed-array-buffer-schema.js

@@ -1,1 +0,1 @@

var Schema=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=12)}([function(t,r,e){var n=e(3)(Object,"create");t.exports=n},function(t,r,e){var n=e(11);t.exports=function(t,r){for(var e=t.length;e--;)if(n(t[e][0],r))return e;return-1}},function(t,r,e){var n=e(53);t.exports=function(t,r){var e=t.__data__;return n(r)?e["string"==typeof r?"string":"hash"]:e.map}},function(t,r,e){var n=e(21),i=e(30);t.exports=function(t,r){var e=i(t,r);return n(e)?e:void 0}},function(t,r,e){var n=e(5).Symbol;t.exports=n},function(t,r,e){var n=e(23),i="object"==typeof self&&self&&self.Object===Object&&self,o=n||i||Function("return this")();t.exports=o},function(t,r){t.exports=function(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)}},function(t,r){var e=Array.isArray;t.exports=e},function(t,r,e){var n=e(10),i=e(33);t.exports=function(t){return"symbol"==typeof t||i(t)&&"[object Symbol]"==n(t)}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.Lib=void 0;var n=e(13),i=function(){function t(){}return t.newHash=function(t,r){var e=function(t){for(var r=0,e=0;e<t.length;e++){r=(r<<5)-r+t.charCodeAt(e),r|=0}return r*=254785,Math.abs(r).toString(32).slice(2,6)}(JSON.stringify(r)+t);if(4!==e.length)throw new Error("Hash has not length of 4");return"#"+e},t.schema=function(r,e){var i=t.newHash(r,e),o=new n.Schema(i,r,e);return this._schemas.set(i,o),o},t._schemas=new Map,t}();r.Lib=i},function(t,r,e){var n=e(4),i=e(25),o=e(26),a=n?n.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":a&&a in Object(t)?i(t):o(t)}},function(t,r){t.exports=function(t,r){return t===r||t!=t&&r!=r}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e(9),i=e(14),o=e(62);r.default={BufferSchema:n.Lib,Model:i.Model,int8:o.int8,uint8:o.uint8,int16:o.int16,uint16:o.uint16,int32:o.int32,uint32:o.uint32,int64:o.int64,uint64:o.uint64,float32:o.float32,float64:o.float64,string8:o.string8,string16:o.string16}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.Schema=void 0;var n=function(){function t(r,e,n){this._id=r,this._name=e,this._struct=n,this._bytes=0,t.Validation(n),this.calcBytes()}return t.Validation=function(t){},Object.defineProperty(t.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"name",{get:function(){return this._name},enumerable:!1,configurable:!0}),t.prototype.calcBytes=function(){var t=this,r=function(e){var n,i;for(var o in e){var a=(null==e?void 0:e._type)||(null===(n=null==e?void 0:e.type)||void 0===n?void 0:n._type),u=e._bytes||(null===(i=e.type)||void 0===i?void 0:i._bytes);if(!a&&e.hasOwnProperty(o))"object"==typeof e[o]&&r(e[o]);else{if("_type"!==o&&"type"!==o)return;if(!u)return;if("String8"===a||"String16"===a){var s=e.length||12;t._bytes+=u*s}else t._bytes+=u}}};r(this._struct)},Object.defineProperty(t.prototype,"struct",{get:function(){return this._struct},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bytes",{get:function(){return this._bytes},enumerable:!1,configurable:!0}),t}();r.Schema=n},function(t,r,e){"use strict";var n,i=this&&this.__extends||(n=function(t,r){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(t,r)},function(t,r){function e(){this.constructor=t}n(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)});Object.defineProperty(r,"__esModule",{value:!0}),r.Model=void 0;var o=function(t){function r(r){var e=t.call(this,r)||this;return e.schema=r,e}return i(r,t),r}(e(15).Serialize);r.Model=o},function(t,r,e){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var i in r=arguments[e])Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i]);return t}).apply(this,arguments)},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(r,"__esModule",{value:!0}),r.Serialize=void 0;var o=e(9),a=i(e(16)),u=function(){function t(t){this.schema=t,this._buffer=new ArrayBuffer(0),this._dataView=new DataView(this._buffer),this._bytes=0}return t.prototype.refresh=function(){this._buffer=new ArrayBuffer(8192),this._dataView=new DataView(this._buffer),this._bytes=0},t.prototype.cropString=function(t,r){return t.padEnd(r," ").slice(0,r)},t.prototype.flatten=function(t,r){var e=this,n=[],i=function(t,r){var o,a,u,s,c,f,p;for(var l in(null==t?void 0:t._id)?n.push({d:t._id,t:"String8"}):(null===(o=null==t?void 0:t[0])||void 0===o?void 0:o._id)&&n.push({d:t[0]._id,t:"String8"}),(null==t?void 0:t._struct)?t=t._struct:(null===(a=null==t?void 0:t[0])||void 0===a?void 0:a._struct)&&(t=t[0]._struct),r)if(r.hasOwnProperty(l))if("object"==typeof r[l])Array.isArray(r)?i(t,r[parseInt(l)]):i(t[l],r[l]);else if(null===(s=null===(u=t[l])||void 0===u?void 0:u.type)||void 0===s?void 0:s._type){if((null===(c=t[l])||void 0===c?void 0:c.digits)&&(r[l]*=Math.pow(10,t[l].digits),r[l]=parseInt(r[l].toFixed(0))),null===(f=t[l])||void 0===f?void 0:f.length){var y=null===(p=t[l])||void 0===p?void 0:p.length;r[l]=e.cropString(r[l],y)}n.push({d:r[l],t:t[l].type._type})}else"String8"!==t[l]._type&&"String16"!==t[l]._type||(r[l]=e.cropString(r[l],12)),n.push({d:r[l],t:t[l]._type})};return i(t,r),n},t.prototype.toBuffer=function(t){var r=this,e=JSON.parse(JSON.stringify(t));this.refresh(),this.flatten(this.schema,e).forEach((function(t,e){if("String8"===t.t)for(var n=0;n<t.d.length;n++)r._dataView.setUint8(r._bytes,t.d[n].charCodeAt(0)),r._bytes++;if("String16"===t.t)for(n=0;n<t.d.length;n++)r._dataView.setUint16(r._bytes,t.d[n].charCodeAt(0)),r._bytes+=2;"Int8Array"===t.t&&(r._dataView.setInt8(r._bytes,t.d),r._bytes++),"Uint8Array"===t.t&&(r._dataView.setUint8(r._bytes,t.d),r._bytes++),"Int16Array"===t.t&&(r._dataView.setInt16(r._bytes,t.d),r._bytes+=2),"Uint16Array"===t.t&&(r._dataView.setUint16(r._bytes,t.d),r._bytes+=2),"Int32Array"===t.t&&(r._dataView.setInt32(r._bytes,t.d),r._bytes+=4),"Uint32Array"===t.t&&(r._dataView.setUint32(r._bytes,t.d),r._bytes+=4),"BigInt64Array"===t.t&&(r._dataView.setBigInt64(r._bytes,BigInt(t.d)),r._bytes+=8),"BigUint64Array"===t.t&&(r._dataView.setBigUint64(r._bytes,BigInt(t.d)),r._bytes+=8),"Float32Array"===t.t&&(r._dataView.setFloat32(r._bytes,t.d),r._bytes+=4),"Float64Array"===t.t&&(r._dataView.setFloat64(r._bytes,t.d),r._bytes+=8)}));for(var n=new ArrayBuffer(this._bytes),i=new DataView(n),o=0;o<this._bytes;o++)i.setUint8(o,this._dataView.getUint8(o));return n},t.prototype.fromBuffer=function(t){for(var r=0,e=[],i=new DataView(t),u=Array.from(new Int8Array(t));r>-1;)-1!==(r=u.indexOf(35,r))&&(e.push(r),r++);var s=[];e.forEach((function(t){for(var r="",e=0;e<5;e++){r+=String.fromCharCode(u[t+e])}s.push(r)}));var c=[];s.forEach((function(t,r){o.Lib._schemas.get(t)&&c.push({id:t,schema:o.Lib._schemas.get(t),startsAt:e[r]+5})}));var f={},p=0,l={},y=function(t){var r,e,o,a={};if("object"==typeof t)for(var u in t)if(t.hasOwnProperty(u)){var s=t[u],c=void 0;if((null===(e=null==s?void 0:s.type)||void 0===e?void 0:e._type)&&(null===(o=null==s?void 0:s.type)||void 0===o?void 0:o._bytes)&&(c=s,s._type=s.type._type,s._bytes=s.type._bytes),s&&s._type&&s._bytes){var f=s._type,l=s._bytes,y=void 0;if("String8"===f){y="";for(var _=s.length||12,v=0;v<_;v++){y+=String.fromCharCode(i.getUint8(p)),p++}}if("String16"===f){y="";var d=s.length||12;for(v=0;v<d;v++){y+=String.fromCharCode(i.getUint16(p)),p+=2}}"Int8Array"===f&&(y=i.getInt8(p),p+=l),"Uint8Array"===f&&(y=i.getUint8(p),p+=l),"Int16Array"===f&&(y=i.getInt16(p),p+=l),"Uint16Array"===f&&(y=i.getUint16(p),p+=l),"Int32Array"===f&&(y=i.getInt32(p),p+=l),"Uint32Array"===f&&(y=i.getUint32(p),p+=l),"BigInt64Array"===f&&(y=parseInt(i.getBigInt64(p).toString()),p+=l),"BigUint64Array"===f&&(y=parseInt(i.getBigUint64(p).toString()),p+=l),"Float32Array"===f&&(y=i.getFloat32(p),p+=l),"Float64Array"===f&&(y=i.getFloat64(p),p+=l),"number"==typeof y&&(null==c?void 0:c.digits)&&(y*=Math.pow(10,-c.digits),y=parseFloat(y.toFixed(c.digits))),a=n(n({},a),((r={})[u]=y,r))}}return a};c.forEach((function(r,e){var i,o,a,u=null===(i=r.schema)||void 0===i?void 0:i.struct,s=r.startsAt,f=t.byteLength,_=(null===(o=r.schema)||void 0===o?void 0:o.id)||"XX";"XX"===_&&console.error("ERROR: Something went horribly wrong!");try{f=c[e+1].startsAt-5}catch(t){}for(var v=(null===(a=r.schema)||void 0===a?void 0:a.bytes)||1,d=(f-s)/v,h=0;h<d;h++){p=s+h*v;var b=y(u);d<=1?l[_]=n({},b):(void 0===l[_]&&(l[_]=[]),l[_].push(b))}})),f={};for(var _=function(t,r,e,i,o){if(void 0===i&&(i=""),void 0===o&&(o=!1),t&&t._id&&t._id===r){var u=i.replace(/_struct\./,"").replace(/\.$/,"");o&&!Array.isArray(e)&&(e=[e]),""===u?f=n(n({},f),e):a.default(f,u,e)}else for(var s in t)if(t.hasOwnProperty(s)&&"object"==typeof t[s]){u=Array.isArray(t)?"":s+".";_(t[s],r,e,i+u,Array.isArray(t))}},v=0;v<Object.keys(l).length;v++){var d=Object.keys(l)[v],h=l[d];_(this.schema,d,h,"")}return f},t}();r.Serialize=u},function(t,r,e){var n=e(17);t.exports=function(t,r,e){return null==t?t:n(t,r,e)}},function(t,r,e){var n=e(18),i=e(31),o=e(60),a=e(6),u=e(61);t.exports=function(t,r,e,s){if(!a(t))return t;for(var c=-1,f=(r=i(r,t)).length,p=f-1,l=t;null!=l&&++c<f;){var y=u(r[c]),_=e;if(c!=p){var v=l[y];void 0===(_=s?s(v,y,l):void 0)&&(_=a(v)?v:o(r[c+1])?[]:{})}n(l,y,_),l=l[y]}return t}},function(t,r,e){var n=e(19),i=e(11),o=Object.prototype.hasOwnProperty;t.exports=function(t,r,e){var a=t[r];o.call(t,r)&&i(a,e)&&(void 0!==e||r in t)||n(t,r,e)}},function(t,r,e){var n=e(20);t.exports=function(t,r,e){"__proto__"==r&&n?n(t,r,{configurable:!0,enumerable:!0,value:e,writable:!0}):t[r]=e}},function(t,r,e){var n=e(3),i=function(){try{var t=n(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=i},function(t,r,e){var n=e(22),i=e(27),o=e(6),a=e(29),u=/^\[object .+?Constructor\]$/,s=Function.prototype,c=Object.prototype,f=s.toString,p=c.hasOwnProperty,l=RegExp("^"+f.call(p).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=function(t){return!(!o(t)||i(t))&&(n(t)?l:u).test(a(t))}},function(t,r,e){var n=e(10),i=e(6);t.exports=function(t){if(!i(t))return!1;var r=n(t);return"[object Function]"==r||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r}},function(t,r,e){(function(r){var e="object"==typeof r&&r&&r.Object===Object&&r;t.exports=e}).call(this,e(24))},function(t,r){var e;e=function(){return this}();try{e=e||new Function("return this")()}catch(t){"object"==typeof window&&(e=window)}t.exports=e},function(t,r,e){var n=e(4),i=Object.prototype,o=i.hasOwnProperty,a=i.toString,u=n?n.toStringTag:void 0;t.exports=function(t){var r=o.call(t,u),e=t[u];try{t[u]=void 0;var n=!0}catch(t){}var i=a.call(t);return n&&(r?t[u]=e:delete t[u]),i}},function(t,r){var e=Object.prototype.toString;t.exports=function(t){return e.call(t)}},function(t,r,e){var n,i=e(28),o=(n=/[^.]+$/.exec(i&&i.keys&&i.keys.IE_PROTO||""))?"Symbol(src)_1."+n:"";t.exports=function(t){return!!o&&o in t}},function(t,r,e){var n=e(5)["__core-js_shared__"];t.exports=n},function(t,r){var e=Function.prototype.toString;t.exports=function(t){if(null!=t){try{return e.call(t)}catch(t){}try{return t+""}catch(t){}}return""}},function(t,r){t.exports=function(t,r){return null==t?void 0:t[r]}},function(t,r,e){var n=e(7),i=e(32),o=e(34),a=e(57);t.exports=function(t,r){return n(t)?t:i(t,r)?[t]:o(a(t))}},function(t,r,e){var n=e(7),i=e(8),o=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,a=/^\w*$/;t.exports=function(t,r){if(n(t))return!1;var e=typeof t;return!("number"!=e&&"symbol"!=e&&"boolean"!=e&&null!=t&&!i(t))||(a.test(t)||!o.test(t)||null!=r&&t in Object(r))}},function(t,r){t.exports=function(t){return null!=t&&"object"==typeof t}},function(t,r,e){var n=e(35),i=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,o=/\\(\\)?/g,a=n((function(t){var r=[];return 46===t.charCodeAt(0)&&r.push(""),t.replace(i,(function(t,e,n,i){r.push(n?i.replace(o,"$1"):e||t)})),r}));t.exports=a},function(t,r,e){var n=e(36);t.exports=function(t){var r=n(t,(function(t){return 500===e.size&&e.clear(),t})),e=r.cache;return r}},function(t,r,e){var n=e(37);function i(t,r){if("function"!=typeof t||null!=r&&"function"!=typeof r)throw new TypeError("Expected a function");var e=function(){var n=arguments,i=r?r.apply(this,n):n[0],o=e.cache;if(o.has(i))return o.get(i);var a=t.apply(this,n);return e.cache=o.set(i,a)||o,a};return e.cache=new(i.Cache||n),e}i.Cache=n,t.exports=i},function(t,r,e){var n=e(38),i=e(52),o=e(54),a=e(55),u=e(56);function s(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}s.prototype.clear=n,s.prototype.delete=i,s.prototype.get=o,s.prototype.has=a,s.prototype.set=u,t.exports=s},function(t,r,e){var n=e(39),i=e(45),o=e(51);t.exports=function(){this.size=0,this.__data__={hash:new n,map:new(o||i),string:new n}}},function(t,r,e){var n=e(40),i=e(41),o=e(42),a=e(43),u=e(44);function s(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}s.prototype.clear=n,s.prototype.delete=i,s.prototype.get=o,s.prototype.has=a,s.prototype.set=u,t.exports=s},function(t,r,e){var n=e(0);t.exports=function(){this.__data__=n?n(null):{},this.size=0}},function(t,r){t.exports=function(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}},function(t,r,e){var n=e(0),i=Object.prototype.hasOwnProperty;t.exports=function(t){var r=this.__data__;if(n){var e=r[t];return"__lodash_hash_undefined__"===e?void 0:e}return i.call(r,t)?r[t]:void 0}},function(t,r,e){var n=e(0),i=Object.prototype.hasOwnProperty;t.exports=function(t){var r=this.__data__;return n?void 0!==r[t]:i.call(r,t)}},function(t,r,e){var n=e(0);t.exports=function(t,r){var e=this.__data__;return this.size+=this.has(t)?0:1,e[t]=n&&void 0===r?"__lodash_hash_undefined__":r,this}},function(t,r,e){var n=e(46),i=e(47),o=e(48),a=e(49),u=e(50);function s(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}s.prototype.clear=n,s.prototype.delete=i,s.prototype.get=o,s.prototype.has=a,s.prototype.set=u,t.exports=s},function(t,r){t.exports=function(){this.__data__=[],this.size=0}},function(t,r,e){var n=e(1),i=Array.prototype.splice;t.exports=function(t){var r=this.__data__,e=n(r,t);return!(e<0)&&(e==r.length-1?r.pop():i.call(r,e,1),--this.size,!0)}},function(t,r,e){var n=e(1);t.exports=function(t){var r=this.__data__,e=n(r,t);return e<0?void 0:r[e][1]}},function(t,r,e){var n=e(1);t.exports=function(t){return n(this.__data__,t)>-1}},function(t,r,e){var n=e(1);t.exports=function(t,r){var e=this.__data__,i=n(e,t);return i<0?(++this.size,e.push([t,r])):e[i][1]=r,this}},function(t,r,e){var n=e(3)(e(5),"Map");t.exports=n},function(t,r,e){var n=e(2);t.exports=function(t){var r=n(this,t).delete(t);return this.size-=r?1:0,r}},function(t,r){t.exports=function(t){var r=typeof t;return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t}},function(t,r,e){var n=e(2);t.exports=function(t){return n(this,t).get(t)}},function(t,r,e){var n=e(2);t.exports=function(t){return n(this,t).has(t)}},function(t,r,e){var n=e(2);t.exports=function(t,r){var e=n(this,t),i=e.size;return e.set(t,r),this.size+=e.size==i?0:1,this}},function(t,r,e){var n=e(58);t.exports=function(t){return null==t?"":n(t)}},function(t,r,e){var n=e(4),i=e(59),o=e(7),a=e(8),u=n?n.prototype:void 0,s=u?u.toString:void 0;t.exports=function t(r){if("string"==typeof r)return r;if(o(r))return i(r,t)+"";if(a(r))return s?s.call(r):"";var e=r+"";return"0"==e&&1/r==-1/0?"-0":e}},function(t,r){t.exports=function(t,r){for(var e=-1,n=null==t?0:t.length,i=Array(n);++e<n;)i[e]=r(t[e],e,t);return i}},function(t,r){var e=/^(?:0|[1-9]\d*)$/;t.exports=function(t,r){var n=typeof t;return!!(r=null==r?9007199254740991:r)&&("number"==n||"symbol"!=n&&e.test(t))&&t>-1&&t%1==0&&t<r}},function(t,r,e){var n=e(8);t.exports=function(t){if("string"==typeof t||n(t))return t;var r=t+"";return"0"==r&&1/t==-1/0?"-0":r}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.string16=r.string8=r.float64=r.float32=r.uint64=r.int64=r.uint32=r.int32=r.uint16=r.int16=r.uint8=r.int8=void 0,r.int8={_type:"Int8Array",_bytes:1},r.uint8={_type:"Uint8Array",_bytes:1},r.int16={_type:"Int16Array",_bytes:2},r.uint16={_type:"Uint16Array",_bytes:2},r.int32={_type:"Int32Array",_bytes:4},r.uint32={_type:"Uint32Array",_bytes:4},r.int64={_type:"BigInt64Array",_bytes:8},r.uint64={_type:"BigUint64Array",_bytes:8},r.float32={_type:"Float32Array",_bytes:4},r.float64={_type:"Float64Array",_bytes:8},r.string8={_type:"String8",_bytes:1},r.string16={_type:"String16",_bytes:2}}]).default;
var Schema;(()=>{var t={1989:(t,e,r)=>{var n=r(1789),i=r(401),o=r(7667),s=r(1327),a=r(1866);function u(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}u.prototype.clear=n,u.prototype.delete=i,u.prototype.get=o,u.prototype.has=s,u.prototype.set=a,t.exports=u},8407:(t,e,r)=>{var n=r(7040),i=r(4125),o=r(2117),s=r(7518),a=r(4705);function u(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}u.prototype.clear=n,u.prototype.delete=i,u.prototype.get=o,u.prototype.has=s,u.prototype.set=a,t.exports=u},7071:(t,e,r)=>{var n=r(852)(r(5639),"Map");t.exports=n},3369:(t,e,r)=>{var n=r(4785),i=r(1285),o=r(6e3),s=r(9916),a=r(5265);function u(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}u.prototype.clear=n,u.prototype.delete=i,u.prototype.get=o,u.prototype.has=s,u.prototype.set=a,t.exports=u},2705:(t,e,r)=>{var n=r(5639).Symbol;t.exports=n},9932:t=>{t.exports=function(t,e){for(var r=-1,n=null==t?0:t.length,i=Array(n);++r<n;)i[r]=e(t[r],r,t);return i}},4865:(t,e,r)=>{var n=r(9465),i=r(7813),o=Object.prototype.hasOwnProperty;t.exports=function(t,e,r){var s=t[e];o.call(t,e)&&i(s,r)&&(void 0!==r||e in t)||n(t,e,r)}},8470:(t,e,r)=>{var n=r(7813);t.exports=function(t,e){for(var r=t.length;r--;)if(n(t[r][0],e))return r;return-1}},9465:(t,e,r)=>{var n=r(8777);t.exports=function(t,e,r){"__proto__"==e&&n?n(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}},4239:(t,e,r)=>{var n=r(2705),i=r(9607),o=r(2333),s=n?n.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":s&&s in Object(t)?i(t):o(t)}},8458:(t,e,r)=>{var n=r(3560),i=r(5346),o=r(3218),s=r(346),a=/^\[object .+?Constructor\]$/,u=Function.prototype,l=Object.prototype,c=u.toString,p=l.hasOwnProperty,h=RegExp("^"+c.call(p).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=function(t){return!(!o(t)||i(t))&&(n(t)?h:a).test(s(t))}},611:(t,e,r)=>{var n=r(4865),i=r(1811),o=r(5776),s=r(3218),a=r(327);t.exports=function(t,e,r,u){if(!s(t))return t;for(var l=-1,c=(e=i(e,t)).length,p=c-1,h=t;null!=h&&++l<c;){var y=a(e[l]),_=r;if("__proto__"===y||"constructor"===y||"prototype"===y)return t;if(l!=p){var f=h[y];void 0===(_=u?u(f,y,h):void 0)&&(_=s(f)?f:o(e[l+1])?[]:{})}n(h,y,_),h=h[y]}return t}},531:(t,e,r)=>{var n=r(2705),i=r(9932),o=r(1469),s=r(3448),a=n?n.prototype:void 0,u=a?a.toString:void 0;t.exports=function t(e){if("string"==typeof e)return e;if(o(e))return i(e,t)+"";if(s(e))return u?u.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r}},1811:(t,e,r)=>{var n=r(1469),i=r(5403),o=r(5514),s=r(9833);t.exports=function(t,e){return n(t)?t:i(t,e)?[t]:o(s(t))}},4429:(t,e,r)=>{var n=r(5639)["__core-js_shared__"];t.exports=n},8777:(t,e,r)=>{var n=r(852),i=function(){try{var t=n(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=i},1957:(t,e,r)=>{var n="object"==typeof r.g&&r.g&&r.g.Object===Object&&r.g;t.exports=n},5050:(t,e,r)=>{var n=r(7019);t.exports=function(t,e){var r=t.__data__;return n(e)?r["string"==typeof e?"string":"hash"]:r.map}},852:(t,e,r)=>{var n=r(8458),i=r(7801);t.exports=function(t,e){var r=i(t,e);return n(r)?r:void 0}},9607:(t,e,r)=>{var n=r(2705),i=Object.prototype,o=i.hasOwnProperty,s=i.toString,a=n?n.toStringTag:void 0;t.exports=function(t){var e=o.call(t,a),r=t[a];try{t[a]=void 0;var n=!0}catch(t){}var i=s.call(t);return n&&(e?t[a]=r:delete t[a]),i}},7801:t=>{t.exports=function(t,e){return null==t?void 0:t[e]}},1789:(t,e,r)=>{var n=r(4536);t.exports=function(){this.__data__=n?n(null):{},this.size=0}},401:t=>{t.exports=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}},7667:(t,e,r)=>{var n=r(4536),i=Object.prototype.hasOwnProperty;t.exports=function(t){var e=this.__data__;if(n){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return i.call(e,t)?e[t]:void 0}},1327:(t,e,r)=>{var n=r(4536),i=Object.prototype.hasOwnProperty;t.exports=function(t){var e=this.__data__;return n?void 0!==e[t]:i.call(e,t)}},1866:(t,e,r)=>{var n=r(4536);t.exports=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=n&&void 0===e?"__lodash_hash_undefined__":e,this}},5776:t=>{var e=/^(?:0|[1-9]\d*)$/;t.exports=function(t,r){var n=typeof t;return!!(r=null==r?9007199254740991:r)&&("number"==n||"symbol"!=n&&e.test(t))&&t>-1&&t%1==0&&t<r}},5403:(t,e,r)=>{var n=r(1469),i=r(3448),o=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,s=/^\w*$/;t.exports=function(t,e){if(n(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!i(t))||s.test(t)||!o.test(t)||null!=e&&t in Object(e)}},7019:t=>{t.exports=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}},5346:(t,e,r)=>{var n,i=r(4429),o=(n=/[^.]+$/.exec(i&&i.keys&&i.keys.IE_PROTO||""))?"Symbol(src)_1."+n:"";t.exports=function(t){return!!o&&o in t}},7040:t=>{t.exports=function(){this.__data__=[],this.size=0}},4125:(t,e,r)=>{var n=r(8470),i=Array.prototype.splice;t.exports=function(t){var e=this.__data__,r=n(e,t);return!(r<0||(r==e.length-1?e.pop():i.call(e,r,1),--this.size,0))}},2117:(t,e,r)=>{var n=r(8470);t.exports=function(t){var e=this.__data__,r=n(e,t);return r<0?void 0:e[r][1]}},7518:(t,e,r)=>{var n=r(8470);t.exports=function(t){return n(this.__data__,t)>-1}},4705:(t,e,r)=>{var n=r(8470);t.exports=function(t,e){var r=this.__data__,i=n(r,t);return i<0?(++this.size,r.push([t,e])):r[i][1]=e,this}},4785:(t,e,r)=>{var n=r(1989),i=r(8407),o=r(7071);t.exports=function(){this.size=0,this.__data__={hash:new n,map:new(o||i),string:new n}}},1285:(t,e,r)=>{var n=r(5050);t.exports=function(t){var e=n(this,t).delete(t);return this.size-=e?1:0,e}},6e3:(t,e,r)=>{var n=r(5050);t.exports=function(t){return n(this,t).get(t)}},9916:(t,e,r)=>{var n=r(5050);t.exports=function(t){return n(this,t).has(t)}},5265:(t,e,r)=>{var n=r(5050);t.exports=function(t,e){var r=n(this,t),i=r.size;return r.set(t,e),this.size+=r.size==i?0:1,this}},4523:(t,e,r)=>{var n=r(8306);t.exports=function(t){var e=n(t,(function(t){return 500===r.size&&r.clear(),t})),r=e.cache;return e}},4536:(t,e,r)=>{var n=r(852)(Object,"create");t.exports=n},2333:t=>{var e=Object.prototype.toString;t.exports=function(t){return e.call(t)}},5639:(t,e,r)=>{var n=r(1957),i="object"==typeof self&&self&&self.Object===Object&&self,o=n||i||Function("return this")();t.exports=o},5514:(t,e,r)=>{var n=r(4523),i=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,o=/\\(\\)?/g,s=n((function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(i,(function(t,r,n,i){e.push(n?i.replace(o,"$1"):r||t)})),e}));t.exports=s},327:(t,e,r)=>{var n=r(3448);t.exports=function(t){if("string"==typeof t||n(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}},346:t=>{var e=Function.prototype.toString;t.exports=function(t){if(null!=t){try{return e.call(t)}catch(t){}try{return t+""}catch(t){}}return""}},7813:t=>{t.exports=function(t,e){return t===e||t!=t&&e!=e}},1469:t=>{var e=Array.isArray;t.exports=e},3560:(t,e,r)=>{var n=r(4239),i=r(3218);t.exports=function(t){if(!i(t))return!1;var e=n(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}},3218:t=>{t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},7005:t=>{t.exports=function(t){return null!=t&&"object"==typeof t}},3448:(t,e,r)=>{var n=r(4239),i=r(7005);t.exports=function(t){return"symbol"==typeof t||i(t)&&"[object Symbol]"==n(t)}},8306:(t,e,r)=>{var n=r(3369);function i(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],o=r.cache;if(o.has(i))return o.get(i);var s=t.apply(this,n);return r.cache=o.set(i,s)||o,s};return r.cache=new(i.Cache||n),r}i.Cache=n,t.exports=i},6968:(t,e,r)=>{var n=r(611);t.exports=function(t,e,r){return null==t?t:n(t,e,r)}},9833:(t,e,r)=>{var n=r(531);t.exports=function(t){return null==t?"":n(t)}},5563:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Lib=void 0;const n=r(1734);class i{static newHash(t,e){let r=(t=>{let e=0;for(let r=0;r<t.length;r++)e=(e<<5)-e+t.charCodeAt(r),e|=0;return e*=254785,Math.abs(e).toString(32).slice(2,6)})(JSON.stringify(e)+t);if(4!==r.length)throw new Error("Hash has not length of 4");return`#${r}`}static schema(t,e){const r=i.newHash(t,e),o=new n.Schema(r,t,e);return this._schemas.set(r,o),o}}e.Lib=i,i._schemas=new Map,i.getIdFromBuffer=t=>{const e=new DataView(t);let r="";for(let t=0;t<5;t++){const n=e.getUint8(t);r+=String.fromCharCode(n)}return r},i.getIdFromSchema=t=>t.id,i.getIdFromModel=t=>t.schema.id},3134:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Model=void 0;const n=r(488);class i extends n.Serialize{constructor(t){super(t),this.schema=t}}e.Model=i},1734:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Schema=void 0;class r{constructor(t,e,n){this._id=t,this._name=e,this._struct=n,this._bytes=0,r.Validation(n),this.calcBytes()}static Validation(t){}get id(){return this._id}get name(){return this._name}calcBytes(){const t=e=>{var r,n;for(var i in e){const o=(null==e?void 0:e._type)||(null===(r=null==e?void 0:e.type)||void 0===r?void 0:r._type),s=e._bytes||(null===(n=e.type)||void 0===n?void 0:n._bytes);if(!o&&e.hasOwnProperty(i))"object"==typeof e[i]&&t(e[i]);else{if("_type"!==i&&"type"!==i)return;if(!s)return;if("String8"===o||"String16"===o){const t=e.length||12;this._bytes+=s*t}else this._bytes+=s}}};t(this._struct)}get struct(){return this._struct}get bytes(){return this._bytes}}e.Schema=r},488:function(t,e,r){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Serialize=void 0;const i=r(5563),o=n(r(6968));e.Serialize=class{constructor(t){this.schema=t,this._buffer=new ArrayBuffer(0),this._dataView=new DataView(this._buffer),this._bytes=0}refresh(){this._buffer=new ArrayBuffer(8192),this._dataView=new DataView(this._buffer),this._bytes=0}cropString(t,e){return t.padEnd(e," ").slice(0,e)}flatten(t,e){let r=[];const n=(t,e)=>{var i,o,s,a,u,l,c;for(var p in(null==t?void 0:t._id)?r.push({d:t._id,t:"String8"}):(null===(i=null==t?void 0:t[0])||void 0===i?void 0:i._id)&&r.push({d:t[0]._id,t:"String8"}),(null==t?void 0:t._struct)?t=t._struct:(null===(o=null==t?void 0:t[0])||void 0===o?void 0:o._struct)&&(t=t[0]._struct),e)if(e.hasOwnProperty(p))if("object"==typeof e[p])Array.isArray(e)?n(t,e[parseInt(p)]):n(t[p],e[p]);else if(null===(a=null===(s=t[p])||void 0===s?void 0:s.type)||void 0===a?void 0:a._type){if((null===(u=t[p])||void 0===u?void 0:u.digits)&&(e[p]*=Math.pow(10,t[p].digits),e[p]=parseInt(e[p].toFixed(0))),null===(l=t[p])||void 0===l?void 0:l.length){const r=null===(c=t[p])||void 0===c?void 0:c.length;e[p]=this.cropString(e[p],r)}r.push({d:e[p],t:t[p].type._type})}else"String8"!==t[p]._type&&"String16"!==t[p]._type||(e[p]=this.cropString(e[p],12)),r.push({d:e[p],t:t[p]._type})};return n(t,e),r}toBuffer(t){const e=JSON.parse(JSON.stringify(t));this.refresh(),this.flatten(this.schema,e).forEach(((t,e)=>{if("String8"===t.t)for(let e=0;e<t.d.length;e++)this._dataView.setUint8(this._bytes,t.d[e].charCodeAt(0)),this._bytes++;if("String16"===t.t)for(let e=0;e<t.d.length;e++)this._dataView.setUint16(this._bytes,t.d[e].charCodeAt(0)),this._bytes+=2;"Int8Array"===t.t&&(this._dataView.setInt8(this._bytes,t.d),this._bytes++),"Uint8Array"===t.t&&(this._dataView.setUint8(this._bytes,t.d),this._bytes++),"Int16Array"===t.t&&(this._dataView.setInt16(this._bytes,t.d),this._bytes+=2),"Uint16Array"===t.t&&(this._dataView.setUint16(this._bytes,t.d),this._bytes+=2),"Int32Array"===t.t&&(this._dataView.setInt32(this._bytes,t.d),this._bytes+=4),"Uint32Array"===t.t&&(this._dataView.setUint32(this._bytes,t.d),this._bytes+=4),"BigInt64Array"===t.t&&(this._dataView.setBigInt64(this._bytes,BigInt(t.d)),this._bytes+=8),"BigUint64Array"===t.t&&(this._dataView.setBigUint64(this._bytes,BigInt(t.d)),this._bytes+=8),"Float32Array"===t.t&&(this._dataView.setFloat32(this._bytes,t.d),this._bytes+=4),"Float64Array"===t.t&&(this._dataView.setFloat64(this._bytes,t.d),this._bytes+=8)}));const r=new ArrayBuffer(this._bytes),n=new DataView(r);for(let t=0;t<this._bytes;t++)n.setUint8(t,this._dataView.getUint8(t));return r}fromBuffer(t){let e=0,r=[];const n=new DataView(t),s=Array.from(new Int8Array(t));for(;e>-1;)e=s.indexOf(35,e),-1!==e&&(r.push(e),e++);let a=[];r.forEach((t=>{let e="";for(let r=0;r<5;r++)e+=String.fromCharCode(s[t+r]);a.push(e)}));let u=[];a.forEach(((t,e)=>{i.Lib._schemas.get(t)&&u.push({id:t,schema:i.Lib._schemas.get(t),startsAt:r[e]+5})}));let l={},c=0,p={};const h=t=>{var e,r;let i={};if("object"==typeof t)for(var o in t)if(t.hasOwnProperty(o)){const s=t[o];let a;if((null===(e=null==s?void 0:s.type)||void 0===e?void 0:e._type)&&(null===(r=null==s?void 0:s.type)||void 0===r?void 0:r._bytes)&&(a=s,s._type=s.type._type,s._bytes=s.type._bytes),s&&s._type&&s._bytes){const t=s._type,e=s._bytes;let r;if("String8"===t){r="";const t=s.length||12;for(let e=0;e<t;e++)r+=String.fromCharCode(n.getUint8(c)),c++}if("String16"===t){r="";const t=s.length||12;for(let e=0;e<t;e++)r+=String.fromCharCode(n.getUint16(c)),c+=2}"Int8Array"===t&&(r=n.getInt8(c),c+=e),"Uint8Array"===t&&(r=n.getUint8(c),c+=e),"Int16Array"===t&&(r=n.getInt16(c),c+=e),"Uint16Array"===t&&(r=n.getUint16(c),c+=e),"Int32Array"===t&&(r=n.getInt32(c),c+=e),"Uint32Array"===t&&(r=n.getUint32(c),c+=e),"BigInt64Array"===t&&(r=parseInt(n.getBigInt64(c).toString()),c+=e),"BigUint64Array"===t&&(r=parseInt(n.getBigUint64(c).toString()),c+=e),"Float32Array"===t&&(r=n.getFloat32(c),c+=e),"Float64Array"===t&&(r=n.getFloat64(c),c+=e),"number"==typeof r&&(null==a?void 0:a.digits)&&(r*=Math.pow(10,-a.digits),r=parseFloat(r.toFixed(a.digits))),i={...i,[o]:r}}}return i};u.forEach(((e,r)=>{var n,i,o;let s=null===(n=e.schema)||void 0===n?void 0:n.struct,a=e.startsAt,l=t.byteLength,y=(null===(i=e.schema)||void 0===i?void 0:i.id)||"XX";"XX"===y&&console.error("ERROR: Something went horribly wrong!");try{l=u[r+1].startsAt-5}catch{}const _=(null===(o=e.schema)||void 0===o?void 0:o.bytes)||1,f=(l-a)/_;for(let t=0;t<f;t++){c=a+t*_;let e=h(s);f<=1?p[y]={...e}:(void 0===p[y]&&(p[y]=[]),p[y].push(e))}})),l={};const y=(t,e,r,n="",i=!1)=>{if(t&&t._id&&t._id===e){let t=n.replace(/_struct\./,"").replace(/\.$/,"");i&&!Array.isArray(r)&&(r=[r]),""===t?l={...l,...r}:(0,o.default)(l,t,r)}else for(const i in t)if(t.hasOwnProperty(i)&&"object"==typeof t[i]){let o=Array.isArray(t)?"":`${i}.`;y(t[i],e,r,n+o,Array.isArray(t))}};for(let t=0;t<Object.keys(p).length;t++){const e=Object.keys(p)[t],r=p[e];y(this.schema,e,r,"")}return l}}},7826:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.string16=e.string8=e.float64=e.float32=e.uint64=e.int64=e.uint32=e.int32=e.uint16=e.int16=e.uint8=e.int8=void 0,e.int8={_type:"Int8Array",_bytes:1},e.uint8={_type:"Uint8Array",_bytes:1},e.int16={_type:"Int16Array",_bytes:2},e.uint16={_type:"Uint16Array",_bytes:2},e.int32={_type:"Int32Array",_bytes:4},e.uint32={_type:"Uint32Array",_bytes:4},e.int64={_type:"BigInt64Array",_bytes:8},e.uint64={_type:"BigUint64Array",_bytes:8},e.float32={_type:"Float32Array",_bytes:4},e.float64={_type:"Float64Array",_bytes:8},e.string8={_type:"String8",_bytes:1},e.string16={_type:"String16",_bytes:2}}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}();var n={};(()=>{"use strict";var t=n;const e=r(5563),i=r(3134),o=r(7826);t.default={BufferSchema:e.Lib,Model:i.Model,int8:o.int8,uint8:o.uint8,int16:o.int16,uint16:o.uint16,int32:o.int32,uint32:o.uint32,int64:o.int64,uint64:o.uint64,float32:o.float32,float64:o.float64,string8:o.string8,string16:o.string16}})(),Schema=n.default})();

@@ -56,1 +56,2 @@ import { Lib as BufferSchema } from './lib';

export default _default;
//# sourceMappingURL=bundle.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var lib_1 = require("./lib");
var model_1 = require("./model");
var views_1 = require("./views");
const lib_1 = require("./lib");
const model_1 = require("./model");
const views_1 = require("./views");
exports.default = {

@@ -7,0 +7,0 @@ BufferSchema: lib_1.Lib,

export {};
//# sourceMappingURL=dev.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("./index");
var views_1 = require("./views");
var playerSchema = index_1.BufferSchema.schema('player', {
const index_1 = require("./index");
const views_1 = require("./views");
const playerSchema = index_1.BufferSchema.schema('player', {
id: index_1.uint8,

@@ -11,3 +11,3 @@ name: { type: views_1.string8, length: 6 },

});
var towerSchema = index_1.BufferSchema.schema('tower', {
const towerSchema = index_1.BufferSchema.schema('tower', {
id: index_1.uint8,

@@ -17,3 +17,3 @@ health: index_1.uint8,

});
var mainSchema = index_1.BufferSchema.schema('snapshot', {
const mainSchema = index_1.BufferSchema.schema('snapshot', {
time: views_1.int64,

@@ -24,3 +24,3 @@ tick: index_1.uint16,

});
var gameState = {
const gameState = {
time: new Date().getTime(),

@@ -38,5 +38,5 @@ tick: 32580,

};
var mainModel = new index_1.Model(mainSchema);
var buffer = mainModel.toBuffer(gameState);
var data = mainModel.fromBuffer(buffer);
const mainModel = new index_1.Model(mainSchema);
const buffer = mainModel.toBuffer(gameState);
const data = mainModel.fromBuffer(buffer);
// toBuffer() shrunk the byte size from 241 to only 56

@@ -47,2 +47,13 @@ // that is -77% compression!

console.log(JSON.stringify(data).length); // 241
//------------------------------------------------------------------
// Get the Schema IDs
//------------------------------------------------------------------
const bufferId = index_1.BufferSchema.getIdFromBuffer(buffer);
const schemaId = index_1.BufferSchema.getIdFromSchema(mainSchema);
const modelId = index_1.BufferSchema.getIdFromModel(mainModel);
console.log(`bufferId: ${bufferId}`);
console.log(`schemaId: ${schemaId}`);
console.log(`modelId: ${modelId}`);
if (bufferId === schemaId && schemaId === modelId)
console.log(`Schema name is "${mainSchema.name}"`);
//# sourceMappingURL=dev.js.map
export { Lib as BufferSchema } from './lib';
export { Model } from './model';
export { int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64, string8, string16 } from './views';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.string16 = exports.string8 = exports.float64 = exports.float32 = exports.uint64 = exports.int64 = exports.uint32 = exports.int32 = exports.uint16 = exports.int16 = exports.uint8 = exports.int8 = exports.Model = exports.BufferSchema = void 0;
var lib_1 = require("./lib");

@@ -4,0 +5,0 @@ Object.defineProperty(exports, "BufferSchema", { enumerable: true, get: function () { return lib_1.Lib; } });

@@ -0,1 +1,2 @@

import { Model } from './model';
import { Schema } from './schema';

@@ -6,2 +7,6 @@ export declare class Lib {

static schema(name: string, _struct: Object): Schema;
static getIdFromBuffer: (buffer: ArrayBuffer) => string;
static getIdFromSchema: (schema: Schema) => string;
static getIdFromModel: (model: Model) => string;
}
//# sourceMappingURL=lib.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Lib = void 0;
var schema_1 = require("./schema");
var Lib = /** @class */ (function () {
function Lib() {
}
Lib.newHash = function (name, _struct) {
const schema_1 = require("./schema");
class Lib {
static newHash(name, _struct) {
// https://stackoverflow.com/a/7616484/12656855
var strToHash = function (s) {
var hash = 0;
for (var i = 0; i < s.length; i++) {
var chr = s.charCodeAt(i);
const strToHash = (s) => {
let hash = 0;
for (let i = 0; i < s.length; i++) {
const chr = s.charCodeAt(i);
hash = (hash << 5) - hash + chr;

@@ -20,17 +18,27 @@ hash |= 0; // Convert to 32bit integer

};
var hash = strToHash(JSON.stringify(_struct) + name);
let hash = strToHash(JSON.stringify(_struct) + name);
if (hash.length !== 4)
throw new Error('Hash has not length of 4');
return "#" + hash;
};
Lib.schema = function (name, _struct) {
var id = Lib.newHash(name, _struct);
var s = new schema_1.Schema(id, name, _struct);
return `#${hash}`;
}
static schema(name, _struct) {
const id = Lib.newHash(name, _struct);
const s = new schema_1.Schema(id, name, _struct);
this._schemas.set(id, s);
return s;
};
Lib._schemas = new Map();
return Lib;
}());
}
}
exports.Lib = Lib;
Lib._schemas = new Map();
Lib.getIdFromBuffer = (buffer) => {
const dataView = new DataView(buffer);
let id = '';
for (let i = 0; i < 5; i++) {
const uInt8 = dataView.getUint8(i);
id += String.fromCharCode(uInt8);
}
return id;
};
Lib.getIdFromSchema = (schema) => schema.id;
Lib.getIdFromModel = (model) => model.schema.id;
//# sourceMappingURL=lib.js.map
import { Schema } from './schema';
import { Serialize } from './serialize';
export declare class Model extends Serialize {
protected schema: Schema;
schema: Schema;
constructor(schema: Schema);
}
//# sourceMappingURL=model.d.ts.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Model = void 0;
var serialize_1 = require("./serialize");
var Model = /** @class */ (function (_super) {
__extends(Model, _super);
function Model(schema) {
var _this = _super.call(this, schema) || this;
_this.schema = schema;
return _this;
const serialize_1 = require("./serialize");
class Model extends serialize_1.Serialize {
constructor(schema) {
super(schema);
this.schema = schema;
}
return Model;
}(serialize_1.Serialize));
}
exports.Model = Model;
//# sourceMappingURL=model.js.map

@@ -14,1 +14,2 @@ export declare class Schema {

}
//# sourceMappingURL=schema.d.ts.map

@@ -5,4 +5,4 @@ "use strict";

exports.Schema = void 0;
var Schema = /** @class */ (function () {
function Schema(_id, _name, _struct) {
class Schema {
constructor(_id, _name, _struct) {
this._id = _id;

@@ -15,26 +15,17 @@ this._name = _name;

}
Schema.Validation = function (struct) {
static Validation(struct) {
// do all the validation here (as static me)
};
Object.defineProperty(Schema.prototype, "id", {
get: function () {
return this._id;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Schema.prototype, "name", {
get: function () {
return this._name;
},
enumerable: false,
configurable: true
});
Schema.prototype.calcBytes = function () {
var _this = this;
var iterate = function (obj) {
}
get id() {
return this._id;
}
get name() {
return this._name;
}
calcBytes() {
const iterate = (obj) => {
var _a, _b;
for (var property in obj) {
var type = (obj === null || obj === void 0 ? void 0 : obj._type) || ((_a = obj === null || obj === void 0 ? void 0 : obj.type) === null || _a === void 0 ? void 0 : _a._type);
var bytes = obj._bytes || ((_b = obj.type) === null || _b === void 0 ? void 0 : _b._bytes);
const type = (obj === null || obj === void 0 ? void 0 : obj._type) || ((_a = obj === null || obj === void 0 ? void 0 : obj.type) === null || _a === void 0 ? void 0 : _a._type);
const bytes = obj._bytes || ((_b = obj.type) === null || _b === void 0 ? void 0 : _b._bytes);
if (!type && obj.hasOwnProperty(property)) {

@@ -52,7 +43,7 @@ if (typeof obj[property] === 'object') {

if (type === 'String8' || type === 'String16') {
var length_1 = obj.length || 12;
_this._bytes += bytes * length_1;
const length = obj.length || 12;
this._bytes += bytes * length;
}
else {
_this._bytes += bytes;
this._bytes += bytes;
}

@@ -63,20 +54,11 @@ }

iterate(this._struct);
};
Object.defineProperty(Schema.prototype, "struct", {
get: function () {
return this._struct;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Schema.prototype, "bytes", {
get: function () {
return this._bytes;
},
enumerable: false,
configurable: true
});
return Schema;
}());
}
get struct() {
return this._struct;
}
get bytes() {
return this._bytes;
}
}
exports.Schema = Schema;
//# sourceMappingURL=schema.js.map

@@ -14,1 +14,2 @@ import { Schema } from './schema';

}
//# sourceMappingURL=serialize.d.ts.map
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -18,6 +7,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.Serialize = void 0;
var lib_1 = require("./lib");
var set_1 = __importDefault(require("lodash/set"));
var Serialize = /** @class */ (function () {
function Serialize(schema) {
const lib_1 = require("./lib");
const set_1 = __importDefault(require("lodash/set"));
class Serialize {
constructor(schema) {
this.schema = schema;

@@ -28,15 +17,14 @@ this._buffer = new ArrayBuffer(0);

}
Serialize.prototype.refresh = function () {
refresh() {
this._buffer = new ArrayBuffer(8 * 1024);
this._dataView = new DataView(this._buffer);
this._bytes = 0;
};
Serialize.prototype.cropString = function (str, length) {
}
cropString(str, length) {
return str.padEnd(length, ' ').slice(0, length);
};
Serialize.prototype.flatten = function (schema, data) {
var _this = this;
var flat = [];
}
flatten(schema, data) {
let flat = [];
// https://stackoverflow.com/a/15589677/12656855
var flatten = function (schema, data) {
const flatten = (schema, data) => {
var _a, _b, _c, _d, _e, _f, _g;

@@ -74,4 +62,4 @@ // add the schema id to flat[] (its a String8 with 5 characters, the first char is #)

if ((_f = schema[property]) === null || _f === void 0 ? void 0 : _f.length) {
var length_1 = (_g = schema[property]) === null || _g === void 0 ? void 0 : _g.length;
data[property] = _this.cropString(data[property], length_1);
const length = (_g = schema[property]) === null || _g === void 0 ? void 0 : _g.length;
data[property] = this.cropString(data[property], length);
}

@@ -83,3 +71,3 @@ flat.push({ d: data[property], t: schema[property].type._type });

if (schema[property]._type === 'String8' || schema[property]._type === 'String16') {
data[property] = _this.cropString(data[property], 12);
data[property] = this.cropString(data[property], 12);
}

@@ -96,79 +84,78 @@ flat.push({ d: data[property], t: schema[property]._type });

return flat;
};
Serialize.prototype.toBuffer = function (worldState) {
var _this = this;
}
toBuffer(worldState) {
// deep clone the worldState
var data = JSON.parse(JSON.stringify(worldState));
const data = JSON.parse(JSON.stringify(worldState));
this.refresh();
var flat = this.flatten(this.schema, data);
const flat = this.flatten(this.schema, data);
// to buffer
flat.forEach(function (f, i) {
flat.forEach((f, i) => {
if (f.t === 'String8') {
for (var j = 0; j < f.d.length; j++) {
_this._dataView.setUint8(_this._bytes, f.d[j].charCodeAt(0));
_this._bytes++;
for (let j = 0; j < f.d.length; j++) {
this._dataView.setUint8(this._bytes, f.d[j].charCodeAt(0));
this._bytes++;
}
}
if (f.t === 'String16') {
for (var j = 0; j < f.d.length; j++) {
_this._dataView.setUint16(_this._bytes, f.d[j].charCodeAt(0));
_this._bytes += 2;
for (let j = 0; j < f.d.length; j++) {
this._dataView.setUint16(this._bytes, f.d[j].charCodeAt(0));
this._bytes += 2;
}
}
if (f.t === 'Int8Array') {
_this._dataView.setInt8(_this._bytes, f.d);
_this._bytes++;
this._dataView.setInt8(this._bytes, f.d);
this._bytes++;
}
if (f.t === 'Uint8Array') {
_this._dataView.setUint8(_this._bytes, f.d);
_this._bytes++;
this._dataView.setUint8(this._bytes, f.d);
this._bytes++;
}
if (f.t === 'Int16Array') {
_this._dataView.setInt16(_this._bytes, f.d);
_this._bytes += 2;
this._dataView.setInt16(this._bytes, f.d);
this._bytes += 2;
}
if (f.t === 'Uint16Array') {
_this._dataView.setUint16(_this._bytes, f.d);
_this._bytes += 2;
this._dataView.setUint16(this._bytes, f.d);
this._bytes += 2;
}
if (f.t === 'Int32Array') {
_this._dataView.setInt32(_this._bytes, f.d);
_this._bytes += 4;
this._dataView.setInt32(this._bytes, f.d);
this._bytes += 4;
}
if (f.t === 'Uint32Array') {
_this._dataView.setUint32(_this._bytes, f.d);
_this._bytes += 4;
this._dataView.setUint32(this._bytes, f.d);
this._bytes += 4;
}
if (f.t === 'BigInt64Array') {
_this._dataView.setBigInt64(_this._bytes, BigInt(f.d));
_this._bytes += 8;
this._dataView.setBigInt64(this._bytes, BigInt(f.d));
this._bytes += 8;
}
if (f.t === 'BigUint64Array') {
_this._dataView.setBigUint64(_this._bytes, BigInt(f.d));
_this._bytes += 8;
this._dataView.setBigUint64(this._bytes, BigInt(f.d));
this._bytes += 8;
}
if (f.t === 'Float32Array') {
_this._dataView.setFloat32(_this._bytes, f.d);
_this._bytes += 4;
this._dataView.setFloat32(this._bytes, f.d);
this._bytes += 4;
}
if (f.t === 'Float64Array') {
_this._dataView.setFloat64(_this._bytes, f.d);
_this._bytes += 8;
this._dataView.setFloat64(this._bytes, f.d);
this._bytes += 8;
}
});
var newBuffer = new ArrayBuffer(this._bytes);
var view = new DataView(newBuffer);
const newBuffer = new ArrayBuffer(this._bytes);
const view = new DataView(newBuffer);
// copy all data to a new (resized) ArrayBuffer
for (var i = 0; i < this._bytes; i++) {
for (let i = 0; i < this._bytes; i++) {
view.setUint8(i, this._dataView.getUint8(i));
}
return newBuffer;
};
Serialize.prototype.fromBuffer = function (buffer) {
}
fromBuffer(buffer) {
// 35 is #
// check where, in the buffer, the schemas are
var index = 0;
var indexes = [];
var view = new DataView(buffer);
var int8 = Array.from(new Int8Array(buffer));
let index = 0;
let indexes = [];
const view = new DataView(buffer);
const int8 = Array.from(new Int8Array(buffer));
while (index > -1) {

@@ -182,7 +169,7 @@ index = int8.indexOf(35, index);

// get the schema ids
var schemaIds = [];
indexes.forEach(function (index) {
var id = '';
for (var i = 0; i < 5; i++) {
var char = String.fromCharCode(int8[index + i]);
let schemaIds = [];
indexes.forEach(index => {
let id = '';
for (let i = 0; i < 5; i++) {
let char = String.fromCharCode(int8[index + i]);
id += char;

@@ -193,26 +180,25 @@ }

// assemble all info about the schemas we need
var schemas = [];
schemaIds.forEach(function (id, i) {
let schemas = [];
schemaIds.forEach((id, i) => {
// check if the schemaId exists
// (this can be, for example, if charCode 35 is not really a #)
var schemaId = lib_1.Lib._schemas.get(id);
const schemaId = lib_1.Lib._schemas.get(id);
if (schemaId)
schemas.push({ id: id, schema: lib_1.Lib._schemas.get(id), startsAt: indexes[i] + 5 });
schemas.push({ id, schema: lib_1.Lib._schemas.get(id), startsAt: indexes[i] + 5 });
});
// schemas[] contains now all the schemas we need to fromBuffer the bufferArray
// lets begin the serialization
var data = {}; // holds all the data we want to give back
var bytes = 0; // the current bytes of arrayBuffer iteration
var dataPerSchema = {};
var deserializeSchema = function (struct) {
var _a;
var _b, _c;
var data = {};
let data = {}; // holds all the data we want to give back
let bytes = 0; // the current bytes of arrayBuffer iteration
let dataPerSchema = {};
const deserializeSchema = (struct) => {
var _a, _b;
let data = {};
if (typeof struct === 'object') {
for (var property in struct) {
if (struct.hasOwnProperty(property)) {
var prop = struct[property];
const prop = struct[property];
// handle specialTypes e.g.: "x: { type: int16, digits: 2 }"
var specialTypes = void 0;
if (((_b = prop === null || prop === void 0 ? void 0 : prop.type) === null || _b === void 0 ? void 0 : _b._type) && ((_c = prop === null || prop === void 0 ? void 0 : prop.type) === null || _c === void 0 ? void 0 : _c._bytes)) {
let specialTypes;
if (((_a = prop === null || prop === void 0 ? void 0 : prop.type) === null || _a === void 0 ? void 0 : _a._type) && ((_b = prop === null || prop === void 0 ? void 0 : prop.type) === null || _b === void 0 ? void 0 : _b._bytes)) {
specialTypes = prop;

@@ -223,10 +209,10 @@ prop._type = prop.type._type;

if (prop && prop['_type'] && prop['_bytes']) {
var _type = prop['_type'];
var _bytes = prop['_bytes'];
var value = void 0;
const _type = prop['_type'];
const _bytes = prop['_bytes'];
let value;
if (_type === 'String8') {
value = '';
var length_2 = prop.length || 12;
for (var i = 0; i < length_2; i++) {
var char = String.fromCharCode(view.getUint8(bytes));
const length = prop.length || 12;
for (let i = 0; i < length; i++) {
const char = String.fromCharCode(view.getUint8(bytes));
value += char;

@@ -238,5 +224,5 @@ bytes++;

value = '';
var length_3 = prop.length || 12;
for (var i = 0; i < length_3; i++) {
var char = String.fromCharCode(view.getUint16(bytes));
const length = prop.length || 12;
for (let i = 0; i < length; i++) {
const char = String.fromCharCode(view.getUint16(bytes));
value += char;

@@ -291,3 +277,3 @@ bytes += 2;

}
data = __assign(__assign({}, data), (_a = {}, _a[property] = value, _a));
data = { ...data, [property]: value };
}

@@ -299,8 +285,8 @@ }

};
schemas.forEach(function (s, i) {
schemas.forEach((s, i) => {
var _a, _b, _c;
var struct = (_a = s.schema) === null || _a === void 0 ? void 0 : _a.struct;
var start = s.startsAt;
var end = buffer.byteLength;
var id = ((_b = s.schema) === null || _b === void 0 ? void 0 : _b.id) || 'XX';
let struct = (_a = s.schema) === null || _a === void 0 ? void 0 : _a.struct;
let start = s.startsAt;
let end = buffer.byteLength;
let id = ((_b = s.schema) === null || _b === void 0 ? void 0 : _b.id) || 'XX';
if (id === 'XX')

@@ -311,14 +297,14 @@ console.error('ERROR: Something went horribly wrong!');

}
catch (_d) { }
catch { }
// TOOD(yandeu) bytes is not accurate since it includes child schemas
var length = ((_c = s.schema) === null || _c === void 0 ? void 0 : _c.bytes) || 1;
const length = ((_c = s.schema) === null || _c === void 0 ? void 0 : _c.bytes) || 1;
// determine how many iteration we have to make in this schema
// the players array maybe contains 5 player, so we have to make 5 iterations
var iterations = (end - start) / length;
for (var i_1 = 0; i_1 < iterations; i_1++) {
bytes = start + i_1 * length;
const iterations = (end - start) / length;
for (let i = 0; i < iterations; i++) {
bytes = start + i * length;
// gets the data from this schema
var schemaData = deserializeSchema(struct);
let schemaData = deserializeSchema(struct);
if (iterations <= 1)
dataPerSchema[id] = __assign({}, schemaData);
dataPerSchema[id] = { ...schemaData };
else {

@@ -333,7 +319,5 @@ if (typeof dataPerSchema[id] === 'undefined')

data = {};
var populateData = function (obj, key, value, path, isArray) {
if (path === void 0) { path = ''; }
if (isArray === void 0) { isArray = false; }
const populateData = (obj, key, value, path = '', isArray = false) => {
if (obj && obj._id && obj._id === key) {
var p = path.replace(/_struct\./, '').replace(/\.$/, '');
let p = path.replace(/_struct\./, '').replace(/\.$/, '');
// if it is a schema[], but only has one set, we manually have to make sure it transforms to an array

@@ -344,11 +328,11 @@ if (isArray && !Array.isArray(value))

if (p === '')
data = __assign(__assign({}, data), value);
data = { ...data, ...value };
else
set_1.default(data, p, value);
(0, set_1.default)(data, p, value);
}
else {
for (var props in obj) {
for (const props in obj) {
if (obj.hasOwnProperty(props)) {
if (typeof obj[props] === 'object') {
var p = Array.isArray(obj) ? '' : props + ".";
let p = Array.isArray(obj) ? '' : `${props}.`;
populateData(obj[props], key, value, path + p, Array.isArray(obj));

@@ -367,12 +351,11 @@ }

// }
for (var i = 0; i < Object.keys(dataPerSchema).length; i++) {
var key = Object.keys(dataPerSchema)[i];
var value = dataPerSchema[key];
for (let i = 0; i < Object.keys(dataPerSchema).length; i++) {
const key = Object.keys(dataPerSchema)[i];
const value = dataPerSchema[key];
populateData(this.schema, key, value, '');
}
return data;
};
return Serialize;
}());
}
}
exports.Serialize = Serialize;
//# sourceMappingURL=serialize.js.map

@@ -61,1 +61,2 @@ /** -128 to 127 (1 byte) */

};
//# sourceMappingURL=views.d.ts.map
{
"name": "@geckos.io/typed-array-buffer-schema",
"version": "1.0.2",
"version": "1.0.3",
"description": "A Schema based Object to Buffer converter",
"main": "lib/index.js",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"type": "commonjs",
"scripts": {
"test:ci": "npm i && npm run build && npm test && npm run bundle:tmp",
"start": "npm run dev",

@@ -13,6 +16,8 @@ "dev": "npm run build && npm-run-all --parallel dev:*",

"bundle": "webpack --config webpack.bundle.js",
"bundle:tmp": "webpack --config webpack.bundle.tmp.js",
"test": "jest --collectCoverage",
"clean": "rimraf lib",
"format": "prettier --write src/**/*.ts",
"prepublishOnly": "npm run build && npm test && npm run bundle"
"format": "prettier --write src/**/*.ts && prettier --write test/**/*.js",
"preReleaseHook": "prepublishOnly",
"prepublishOnly": "npm i && npm run build && npm test && npm run bundle"
},

@@ -41,13 +46,15 @@ "keywords": [

"dependencies": {
"lodash": "^4.17.19"
"@yandeu/prettier-config": "^0.0.2",
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/lodash": "^4.14.158",
"jest": "^26.1.0",
"nodemon": "^2.0.4",
"@types/lodash": "^4.14.177",
"jest": "^27.4.0",
"nodemon": "^2.0.15",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"ts-loader": "^8.0.3",
"typescript": "^3.9.7"
"ts-loader": "^9.2.6",
"typescript": "^4.5.2",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1"
},

@@ -57,2 +64,2 @@ "funding": {

}
}
}

@@ -122,2 +122,17 @@ <div align="center">

## Schema ID
Each Schema has an unique ID. To get the Schema ID from the Schema, Model or Buffer, use the helper functions listed below:
```ts
// get the schema id
const schemaId = BufferSchema.getIdFromSchema(schema)
// get the id of the top level schema (added via new Schema())
const modelId = BufferSchema.getIdFromModel(model)
// get the id of the top level schema
const bufferId = BufferSchema.getIdFromBuffer(buffer)
```
## DataViews

@@ -124,0 +139,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc