first commit

This commit is contained in:
developertrinidad08
2023-01-16 18:11:14 -03:00
commit 7e6cf29479
233 changed files with 26791 additions and 0 deletions

15
node_modules/binarypack/.npmignore generated vendored Normal file
View File

@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
node_modules
npm-debug.log

22
node_modules/binarypack/LICENSE generated vendored Normal file
View File

@ -0,0 +1,22 @@
Copyright (c) 2012 Eric Zhang, http://binaryjs.com
(The MIT License)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

6
node_modules/binarypack/README.md generated vendored Normal file
View File

@ -0,0 +1,6 @@
BinaryPack for Node.js
========
BinaryPack is 95% MessagePack. The protocol has been extended to support distinct string and binary types.
Inspired by: https://github.com/cuzic/MessagePack-JS

334
node_modules/binarypack/lib/binarypack.js generated vendored Normal file
View File

@ -0,0 +1,334 @@
var BufferCursor = require('buffercursor');
var BufferBuilder = require('./bufferbuilder');
BinaryPack = {
unpack: function(data){
var unpacker = new BinaryPack.Unpacker(data);
return unpacker.unpack();
},
pack: function(data){
var packer = new BinaryPack.Packer();
var buffer = packer.pack(data);
return buffer;
}
};
BinaryPack.Unpacker = function(buffer){
this.cursor = new BufferCursor(buffer);
this.length = buffer.length;
}
BinaryPack.Unpacker.prototype.unpack = function(){
var type = this.cursor.readUInt8();
if (type < 0x80){
var positive_fixnum = type;
return positive_fixnum;
} else if ((type ^ 0xe0) < 0x20){
var negative_fixnum = (type ^ 0xe0) - 0x20;
return negative_fixnum;
}
var size;
if ((size = type ^ 0xa0) <= 0x0f){
return this.readraw(size);
} else if ((size = type ^ 0xb0) <= 0x0f){
return this.readstring(size);
} else if ((size = type ^ 0x90) <= 0x0f){
return this.readarray(size);
} else if ((size = type ^ 0x80) <= 0x0f){
return this.readmap(size);
}
switch(type){
case 0xc0:
return null;
case 0xc1:
return undefined;
case 0xc2:
return false;
case 0xc3:
return true;
case 0xca:
return this.cursor.readFloatBE();
case 0xcb:
return this.cursor.readDoubleBE();
case 0xcc:
return this.cursor.readUInt8();
case 0xcd:
return this.cursor.readUInt16BE();
case 0xce:
return this.cursor.readUInt32BE();
case 0xcf:
return this.readUInt64();
case 0xd0:
return this.cursor.readInt8();
case 0xd1:
return this.cursor.readInt16BE();
case 0xd2:
return this.cursor.readInt32BE();
case 0xd3:
return this.readInt64();
case 0xd4:
return undefined;
case 0xd5:
return undefined;
case 0xd6:
return undefined;
case 0xd7:
return undefined;
case 0xd8:
size = this.cursor.readUInt16BE();
return this.readstring(size);
case 0xd9:
size = this.cursor.readUInt32BE();
return this.readstring(size);
case 0xda:
size = this.cursor.readUInt16BE();
return this.readraw(size);
case 0xdb:
size = this.cursor.readUInt32BE();
return this.readraw(size);
case 0xdc:
size = this.cursor.readUInt16BE();
return this.readarray(size);
case 0xdd:
size = this.cursor.readUInt32BE();
return this.readarray(size);
case 0xde:
size = this.cursor.readUInt16BE();
return this.readmap(size);
case 0xdf:
size = this.cursor.readUInt32BE();
return this.readmap(size);
}
}
BinaryPack.Unpacker.prototype.readUInt64 = function(){
var bytes = this.cursor.slice(8);
return ((((((bytes[0] * 256 +
bytes[1]) * 256 +
bytes[2]) * 256 +
bytes[3]) * 256 +
bytes[4]) * 256 +
bytes[5]) * 256 +
bytes[6]) * 256 +
bytes[7];
}
BinaryPack.Unpacker.prototype.readInt64 = function(){
var uint64 = this.readInt64();
return (uint64 < Math.pow(2, 63) ) ? uint64 : uint64 - Math.pow(2, 64);
}
BinaryPack.Unpacker.prototype.readraw = function(size){
return this.cursor.slice(size).buffer;
}
BinaryPack.Unpacker.prototype.readstring = function(size){
return this.cursor.toString('utf8', size);
}
BinaryPack.Unpacker.prototype.readarray = function(size){
var objects = new Array(size);
for(var i = 0; i < size ; i++){
objects[i] = this.unpack();
}
return objects;
}
BinaryPack.Unpacker.prototype.readmap = function(size){
var map = {};
for(var i = 0; i < size ; i++){
var key = this.unpack();
var value = this.unpack();
map[key] = value;
}
return map;
}
BinaryPack.Packer = function(){
this.bufferBuilder = new BufferBuilder();
}
BinaryPack.Packer.prototype.pack = function(value){
var type = typeof(value);
if (type == 'string'){
this.pack_string(value);
} else if (type == 'number'){
if (Math.floor(value) === value){
this.pack_integer(value);
} else{
this.pack_double(value);
}
} else if (type == 'boolean'){
if (value === true){
this.bufferBuilder.append(0xc3, 2);
} else if (value === false){
this.bufferBuilder.append(0xc2, 2);
}
} else if (type == 'undefined'){
this.bufferBuilder.append(0xc0, 2);
} else if (type == 'object'){
if (value === null){
this.bufferBuilder.append(0xc0, 2);
} else {
var constructor = value.constructor;
if (constructor == Array){
this.pack_array(value);
} else if (Buffer.isBuffer(value)) {
this.pack_bin(value);
} else if (constructor == Object){
this.pack_object(value);
} else if (constructor == Date){
this.pack_string(value.toString());
} else if (typeof value.toBinaryPack == 'function'){
this.bufferBuilder.append(value.toBinaryPack(), 1);
} else {
throw new Error('Type "' + constructor.toString() + '" not yet supported');
}
}
} else {
throw new Error('Type "' + type + '" not yet supported');
}
return this.bufferBuilder.getBuffer();
}
BinaryPack.Packer.prototype.pack_bin = function(blob){
var length = blob.length || blob.byteLength || blob.size;
if (length <= 0x0f){
this.bufferBuilder.append(0xa0 + length, 2);
} else if (length <= 0xffff){
this.bufferBuilder.append(0xda, 2) ;
this.bufferBuilder.append(length, 3);
} else if (length <= 0xffffffff){
this.bufferBuilder.append(0xdb, 2);
this.bufferBuilder.append(length, 4);
} else{
throw new Error('Invalid length');
return;
}
this.bufferBuilder.append(blob, 1);
}
BinaryPack.Packer.prototype.pack_string = function(str){
var length = Buffer.byteLength(str);
if (length <= 0x0f){
this.bufferBuilder.append(0xb0 + length, 2);
} else if (length <= 0xffff){
this.bufferBuilder.append(0xd8, 2) ;
this.bufferBuilder.append(length, 3);
} else if (length <= 0xffffffff){
this.bufferBuilder.append(0xd9, 2);
this.bufferBuilder.append(length, 4);
} else{
throw new Error('Invalid length');
return;
}
this.bufferBuilder.append(str, 0);
}
BinaryPack.Packer.prototype.pack_array = function(ary){
var length = ary.length;
if (length <= 0x0f){
this.bufferBuilder.append(0x90 + length, 2);
} else if (length <= 0xffff){
this.bufferBuilder.append(0xdc, 2)
this.bufferBuilder.append(length, 3);
} else if (length <= 0xffffffff){
this.bufferBuilder.append(0xdd, 2);
this.bufferBuilder.append(length, 4);
} else{
throw new Error('Invalid length');
}
for(var i = 0; i < length ; i++){
this.pack(ary[i]);
}
}
BinaryPack.Packer.prototype.pack_integer = function(num){
if ( -0x20 <= num && num <= 0x7f){
this.bufferBuilder.append(num & 0xff, 2);
} else if (0x00 <= num && num <= 0xff){
this.bufferBuilder.append(0xcc, 2);
this.bufferBuilder.append(num, 2);
} else if (-0x80 <= num && num <= 0x7f){
this.bufferBuilder.append(0xd0, 2);
this.bufferBuilder.append(num, 5);
} else if ( 0x0000 <= num && num <= 0xffff){
this.bufferBuilder.append(0xcd, 2);
this.bufferBuilder.append(num, 3);
} else if (-0x8000 <= num && num <= 0x7fff){
this.bufferBuilder.append(0xd1, 2);
this.bufferBuilder.append(num, 6);
} else if ( 0x00000000 <= num && num <= 0xffffffff){
this.bufferBuilder.append(0xce, 2);
this.bufferBuilder.append(num, 4);
} else if (-0x80000000 <= num && num <= 0x7fffffff){
this.bufferBuilder.append(0xd2, 2);
this.bufferBuilder.append(num, 7);
} else if (-0x8000000000000000 <= num && num <= 0x7FFFFFFFFFFFFFFF){
this.bufferBuilder.append(0xd3, 2);
this.pack_int64(num);
} else if (0x0000000000000000 <= num && num <= 0xFFFFFFFFFFFFFFFF){
this.bufferBuilder.append(0xcf);
this.pack_uint64(num);
} else{
throw new Error('Invalid integer');
}
}
BinaryPack.Packer.prototype.pack_double = function(num){
this.bufferBuilder.append(0xcb, 2);
this.bufferBuilder.append(num, 9);
}
BinaryPack.Packer.prototype.pack_object = function(obj){
var keys = Object.keys(obj);
var length = keys.length;
if (length <= 0x0f){
this.bufferBuilder.append(0x80 + length, 2);
} else if (length <= 0xffff){
this.bufferBuilder.append(0xde, 2);
this.bufferBuilder.append(length, 3);
} else if (length <= 0xffffffff){
this.bufferBuilder.append(0xdf, 2);
this.bufferBuilder.append(length, 4);
} else{
throw new Error('Invalid length');
}
for(var prop in obj){
if (obj.hasOwnProperty(prop)){
this.pack(prop);
this.pack(obj[prop]);
}
}
}
BinaryPack.Packer.prototype.pack_int64 = function(num){
var high = Math.floor(num / Math.pow(2, 32));
var low = num % Math.pow(2, 32);
this.bufferBuilder.append((high & 0xff000000) >>> 24, 2);
this.bufferBuilder.append((high & 0x00ff0000) >>> 16, 2);
this.bufferBuilder.append((high & 0x0000ff00) >>> 8, 2);
this.bufferBuilder.append((high & 0x000000ff), 2);
this.bufferBuilder.append((low & 0xff000000) >>> 24, 2);
this.bufferBuilder.append((low & 0x00ff0000) >>> 16, 2);
this.bufferBuilder.append((low & 0x0000ff00) >>> 8, 2);
this.bufferBuilder.append((low & 0x000000ff), 2);
}
BinaryPack.Packer.prototype.pack_uint64 = function(num){
var high = num / Math.pow(2, 32);
var low = num % Math.pow(2, 32);
this.bufferBuilder.append((high & 0xff000000) >>> 24, 2);
this.bufferBuilder.append((high & 0x00ff0000) >>> 16, 2);
this.bufferBuilder.append((high & 0x0000ff00) >>> 8, 2);
this.bufferBuilder.append((high & 0x000000ff), 2);
this.bufferBuilder.append((low & 0xff000000) >>> 24, 2);
this.bufferBuilder.append((low & 0x00ff0000) >>> 16, 2);
this.bufferBuilder.append((low & 0x0000ff00) >>> 8, 2);
this.bufferBuilder.append((low & 0x000000ff), 2);
}
module.exports = BinaryPack;

82
node_modules/binarypack/lib/bufferbuilder.js generated vendored Normal file
View File

@ -0,0 +1,82 @@
var BufferCursor = require('buffercursor');
function BufferBuilder(){
this._pieces = [];
this._length = 0;
}
BufferBuilder.prototype._sizes = [null, null, 1, 2, 4, 1, 2, 4, 4, 8];
// Accepts numbers, strings, and buffers
BufferBuilder.prototype.append = function(data, type) {
// Types (Numbers are BE)
// 0: String
// 1: Buffer
// 2: UInt8
// 3: UInt16
// 4: UInt32
// 5: Int8
// 6: Int16
// 7: Int32
// 8: Float
// 9: Double
switch(type) {
case 0:
this._length += Buffer.byteLength(data);
break;
case 1:
this._length += data.length;
break;
default:
this._length += this._sizes[type];
};
this._pieces.push([data, type]);
};
BufferBuilder.prototype.getBuffer = function() {
var buffer = new Buffer(this._length);
var cursor = new BufferCursor(buffer);
for (var i = 0, ii = this._pieces.length; i < ii; i++) {
var tuple = this._pieces[i];
switch (tuple[1] /* type */) {
case 0:
cursor.write(tuple[0]);
break;
case 1:
var index = cursor.tell();
tuple[0].copy(buffer, index);
cursor.seek(index + tuple[0].length);
break;
case 2:
cursor.writeUInt8(tuple[0]);
break;
case 3:
cursor.writeUInt16BE(tuple[0]);
break;
case 4:
cursor.writeUInt32BE(tuple[0]);
break;
case 5:
cursor.writeInt8(tuple[0]);
break;
case 6:
cursor.writeInt16BE(tuple[0]);
break;
case 7:
cursor.writeInt32BE(tuple[0]);
break;
case 8:
cursor.writeFloatBE(tuple[0]);
break;
case 9:
cursor.writeDoubleBE(tuple[0]);
break;
default:
throw new Error('Unexpected type for `'+tuple[0]+'` in buffer builder');
}
}
return buffer;
};
module.exports = BufferBuilder;

19
node_modules/binarypack/package.json generated vendored Normal file
View File

@ -0,0 +1,19 @@
{
"name": "binarypack",
"description": "BinaryPack is a JSON-like binary serialization format",
"version": "0.0.4",
"homepage": "https://github.com/binaryjs/node-binarypack",
"author": "Eric Zhang",
"repository": {
"type": "git",
"url": "https://github.com/binaryjs/node-binarypack"
},
"main": "./lib/binarypack",
"engines": {
"node": ">=0.6.0"
},
"dependencies" : {
"buffercursor" : ">=0.0.3"
}
}