Einkaufslisten anzeigen, Datenbankeinbindung
This commit is contained in:
2
express-server/node_modules/buffer-writer/.npmignore
generated
vendored
Normal file
2
express-server/node_modules/buffer-writer/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
benchmark/versions/
|
||||
node_modules
|
4
express-server/node_modules/buffer-writer/.travis.yml
generated
vendored
Normal file
4
express-server/node_modules/buffer-writer/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
- 0.9
|
19
express-server/node_modules/buffer-writer/LICENSE
generated
vendored
Normal file
19
express-server/node_modules/buffer-writer/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
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.
|
48
express-server/node_modules/buffer-writer/README.md
generated
vendored
Normal file
48
express-server/node_modules/buffer-writer/README.md
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
# buffer-writer
|
||||
|
||||
[](http://travis-ci.org/brianc/node-buffer-writer)
|
||||
|
||||
Fast & efficient buffer writer used to keep memory usage low by internally recycling a single large buffer.
|
||||
|
||||
Used as the binary protocol writer in [node-postgres](https://github.com/brianc/node-postgres)
|
||||
|
||||
Since postgres requires big endian encoding, this only writes big endian numbers for now, but can & probably will easily be extended to write little endian as well.
|
||||
|
||||
I'll admit this has a few postgres specific things I might need to take out in the future, such as `addHeader`
|
||||
|
||||
## api
|
||||
|
||||
`var writer = new (require('buffer-writer')());`
|
||||
|
||||
### writer.addInt32(num)
|
||||
|
||||
Writes a 4-byte big endian binary encoded number to the end of the buffer.
|
||||
|
||||
### writer.addInt16(num)
|
||||
|
||||
Writes a 2-byte big endian binary encoded number to the end of the buffer.
|
||||
|
||||
### writer.addCString(string)
|
||||
|
||||
Writes a string to the buffer `utf8` encoded and adds a null character (`\0`) at the end.
|
||||
|
||||
### var buffer = writer.addHeader(char)
|
||||
|
||||
Writes the 5 byte PostgreSQL required header to the beginning of the buffer. (1 byte for character, 1 BE Int32 for length of the buffer)
|
||||
|
||||
### var buffer = writer.join()
|
||||
|
||||
Collects all data in the writer and joins it into a single, new buffer.
|
||||
|
||||
### var buffer = writer.flush(char)
|
||||
|
||||
Writes the 5 byte postgres required message header, collects all data in the writer and joins it into a single, new buffer, and then resets the writer.
|
||||
|
||||
## thoughts
|
||||
|
||||
This is kind of node-postgres specific. If you're interested in using this for a more general purpose thing, lemme know.
|
||||
I would love to work with you on getting this more reusable for your needs.
|
||||
|
||||
## license
|
||||
|
||||
MIT
|
86
express-server/node_modules/buffer-writer/benchmark/index.js
generated
vendored
Normal file
86
express-server/node_modules/buffer-writer/benchmark/index.js
generated
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var bench = require('bench');
|
||||
var async = require('async');
|
||||
var rmdir = require('rmdir');
|
||||
var ok = require('okay');
|
||||
var cloned = require('cloned');
|
||||
cloned.workingDir = __dirname + '/versions';
|
||||
|
||||
exports.compare = {
|
||||
'math': function() {
|
||||
var two = 1 + 1;
|
||||
},
|
||||
'another': function() {
|
||||
var yay = 2 + 2;
|
||||
}
|
||||
};
|
||||
|
||||
var clone = function(rev, cb) {
|
||||
var outputDir = path.join(cloned.workingDir, rev);
|
||||
console.log(outputDir)
|
||||
if(fs.existsSync(outputDir)) {
|
||||
return cb(null, {
|
||||
rev: rev,
|
||||
dir: outputDir
|
||||
});
|
||||
}
|
||||
console.log('cloning version ' + rev);
|
||||
cloned(rev, ok(cb, function(dir) {
|
||||
console.log('cloned version ' + rev + ' to ' + dir);
|
||||
cb(null, {
|
||||
rev: rev,
|
||||
dir: dir
|
||||
});
|
||||
}));
|
||||
};
|
||||
|
||||
var versions = [
|
||||
'ef599d3'
|
||||
];
|
||||
|
||||
var scripts = fs.readdirSync(__dirname).filter(function(x) {
|
||||
return x.indexOf('benchmark') > 0;
|
||||
});
|
||||
|
||||
if(process.argv[2]) {
|
||||
scripts = [process.argv[2]]
|
||||
}
|
||||
|
||||
|
||||
var run = function() {
|
||||
async.map(versions, clone, function(err, results) {
|
||||
if(err) throw err;
|
||||
exports.compare = { };
|
||||
var suites = [];
|
||||
scripts.forEach(function(script) {
|
||||
for(var i = 0; i < results.length; i++) {
|
||||
var result = results[i];
|
||||
var benchPath = path.join(result.dir, 'benchmark', script);
|
||||
var suite = {};
|
||||
suites.push(suite);
|
||||
if(fs.existsSync(benchPath)) {
|
||||
var bench = require(benchPath);
|
||||
suite[script + '@' + result.rev] = bench;
|
||||
} else {
|
||||
console.log('%s missing at revision %s', benchPath, result.rev);
|
||||
}
|
||||
}
|
||||
suite[script + '@HEAD'] = require(__dirname + '/' + script);
|
||||
});
|
||||
var compare = function(suite, cb) {
|
||||
console.log('running...')
|
||||
bench.compare(suite, null, null, null, function(err, data) {
|
||||
if(err) return cb(err);
|
||||
bench.show(data);
|
||||
cb(null);
|
||||
});
|
||||
}
|
||||
async.eachSeries(suites, compare, function(err, res) {
|
||||
console.log('all suites done')
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
run();
|
31
express-server/node_modules/buffer-writer/benchmark/int-16-benchmark.js
generated
vendored
Normal file
31
express-server/node_modules/buffer-writer/benchmark/int-16-benchmark.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
var Writer = require(__dirname + '/../');
|
||||
|
||||
module.exports = function() {
|
||||
var writer = new Writer();
|
||||
writer.addInt16(-100000000);
|
||||
writer.addInt16(-1000);
|
||||
writer.addInt16(-1);
|
||||
writer.addInt16(0);
|
||||
writer.addInt16(1);
|
||||
writer.addInt16(1000);
|
||||
writer.addInt16(1000000000);
|
||||
writer.addInt16(-100000000);
|
||||
writer.addInt16(-100000000);
|
||||
writer.addInt16(-1000);
|
||||
writer.addInt16(-1);
|
||||
writer.addInt16(0);
|
||||
writer.addInt16(1);
|
||||
writer.addInt16(1000);
|
||||
writer.addInt16(1000000000);
|
||||
writer.addInt16(-1000);
|
||||
writer.addInt16(-1);
|
||||
writer.addInt16(0);
|
||||
writer.addInt16(1);
|
||||
writer.addInt16(1000);
|
||||
writer.addInt16(1000000000);
|
||||
};
|
||||
|
||||
if(!module.parent) {
|
||||
module.exports();
|
||||
console.log('benchmark ok');
|
||||
}
|
17
express-server/node_modules/buffer-writer/benchmark/int-32-benchmark.js
generated
vendored
Normal file
17
express-server/node_modules/buffer-writer/benchmark/int-32-benchmark.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
var Writer = require(__dirname + '/../');
|
||||
|
||||
module.exports = function() {
|
||||
var writer = new Writer();
|
||||
writer.addInt32(-10000000000000);
|
||||
writer.addInt32(-1000);
|
||||
writer.addInt32(-1);
|
||||
writer.addInt32(0);
|
||||
writer.addInt32(1);
|
||||
writer.addInt32(1000);
|
||||
writer.addInt32(10000000000000);
|
||||
};
|
||||
|
||||
if(!module.parent) {
|
||||
module.exports();
|
||||
console.log('benchmark ok');
|
||||
}
|
16
express-server/node_modules/buffer-writer/benchmark/join-benchmark.js
generated
vendored
Normal file
16
express-server/node_modules/buffer-writer/benchmark/join-benchmark.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
var Writer = require(__dirname + '/../');
|
||||
|
||||
var writer = new Writer();
|
||||
writer.addCString('hello');
|
||||
writer.addCString('something else, really');
|
||||
writer.addInt32(38013);
|
||||
writer.addCString('and that\'s all she wrote, folks\n...\n...not really');
|
||||
|
||||
module.exports = function() {
|
||||
writer.join(0x50);
|
||||
};
|
||||
|
||||
if(!module.parent) {
|
||||
module.exports();
|
||||
console.log('benchmark ok');
|
||||
}
|
23
express-server/node_modules/buffer-writer/benchmark/resize-benchmark.js
generated
vendored
Normal file
23
express-server/node_modules/buffer-writer/benchmark/resize-benchmark.js
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
var Writer = require(__dirname + '/../');
|
||||
|
||||
var string = "";
|
||||
for(var i = 0; i < 10; i++) {
|
||||
string += 'Once upon a time long ago there lived a little programming language named JavaScript';
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
var writer = new Writer(4);
|
||||
writer.addCString(string);
|
||||
writer.addCString(string);
|
||||
writer.addCString(string);
|
||||
writer.addCString(string);
|
||||
writer.addCString(string);
|
||||
writer.addCString(string);
|
||||
writer.addCString(string);
|
||||
writer.addCString(string);
|
||||
};
|
||||
|
||||
if(!module.parent) {
|
||||
module.exports();
|
||||
console.log('benchmark ok');
|
||||
}
|
14
express-server/node_modules/buffer-writer/benchmark/small-benchmark.js
generated
vendored
Normal file
14
express-server/node_modules/buffer-writer/benchmark/small-benchmark.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
var Writer = require(__dirname + '/../');
|
||||
|
||||
module.exports = function() {
|
||||
var writer = new Writer();
|
||||
writer.addInt32(10);
|
||||
writer.addInt16(5);
|
||||
writer.addCString('test');
|
||||
writer.flush('X');
|
||||
};
|
||||
|
||||
if(!module.parent) {
|
||||
module.exports();
|
||||
console.log('benchmark ok');
|
||||
}
|
129
express-server/node_modules/buffer-writer/index.js
generated
vendored
Normal file
129
express-server/node_modules/buffer-writer/index.js
generated
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
//binary data writer tuned for creating
|
||||
//postgres message packets as effeciently as possible by reusing the
|
||||
//same buffer to avoid memcpy and limit memory allocations
|
||||
var Writer = module.exports = function(size) {
|
||||
this.size = size || 1024;
|
||||
this.buffer = Buffer(this.size + 5);
|
||||
this.offset = 5;
|
||||
this.headerPosition = 0;
|
||||
};
|
||||
|
||||
//resizes internal buffer if not enough size left
|
||||
Writer.prototype._ensure = function(size) {
|
||||
var remaining = this.buffer.length - this.offset;
|
||||
if(remaining < size) {
|
||||
var oldBuffer = this.buffer;
|
||||
// exponential growth factor of around ~ 1.5
|
||||
// https://stackoverflow.com/questions/2269063/buffer-growth-strategy
|
||||
var newSize = oldBuffer.length + (oldBuffer.length >> 1) + size;
|
||||
this.buffer = new Buffer(newSize);
|
||||
oldBuffer.copy(this.buffer);
|
||||
}
|
||||
};
|
||||
|
||||
Writer.prototype.addInt32 = function(num) {
|
||||
this._ensure(4);
|
||||
this.buffer[this.offset++] = (num >>> 24 & 0xFF);
|
||||
this.buffer[this.offset++] = (num >>> 16 & 0xFF);
|
||||
this.buffer[this.offset++] = (num >>> 8 & 0xFF);
|
||||
this.buffer[this.offset++] = (num >>> 0 & 0xFF);
|
||||
return this;
|
||||
};
|
||||
|
||||
Writer.prototype.addInt16 = function(num) {
|
||||
this._ensure(2);
|
||||
this.buffer[this.offset++] = (num >>> 8 & 0xFF);
|
||||
this.buffer[this.offset++] = (num >>> 0 & 0xFF);
|
||||
return this;
|
||||
};
|
||||
|
||||
//for versions of node requiring 'length' as 3rd argument to buffer.write
|
||||
var writeString = function(buffer, string, offset, len) {
|
||||
buffer.write(string, offset, len);
|
||||
};
|
||||
|
||||
//overwrite function for older versions of node
|
||||
if(Buffer.prototype.write.length === 3) {
|
||||
writeString = function(buffer, string, offset, len) {
|
||||
buffer.write(string, offset);
|
||||
};
|
||||
}
|
||||
|
||||
Writer.prototype.addCString = function(string) {
|
||||
//just write a 0 for empty or null strings
|
||||
if(!string) {
|
||||
this._ensure(1);
|
||||
} else {
|
||||
var len = Buffer.byteLength(string);
|
||||
this._ensure(len + 1); //+1 for null terminator
|
||||
writeString(this.buffer, string, this.offset, len);
|
||||
this.offset += len;
|
||||
}
|
||||
|
||||
this.buffer[this.offset++] = 0; // null terminator
|
||||
return this;
|
||||
};
|
||||
|
||||
Writer.prototype.addChar = function(c) {
|
||||
this._ensure(1);
|
||||
writeString(this.buffer, c, this.offset, 1);
|
||||
this.offset++;
|
||||
return this;
|
||||
};
|
||||
|
||||
Writer.prototype.addString = function(string) {
|
||||
string = string || "";
|
||||
var len = Buffer.byteLength(string);
|
||||
this._ensure(len);
|
||||
this.buffer.write(string, this.offset);
|
||||
this.offset += len;
|
||||
return this;
|
||||
};
|
||||
|
||||
Writer.prototype.getByteLength = function() {
|
||||
return this.offset - 5;
|
||||
};
|
||||
|
||||
Writer.prototype.add = function(otherBuffer) {
|
||||
this._ensure(otherBuffer.length);
|
||||
otherBuffer.copy(this.buffer, this.offset);
|
||||
this.offset += otherBuffer.length;
|
||||
return this;
|
||||
};
|
||||
|
||||
Writer.prototype.clear = function() {
|
||||
this.offset = 5;
|
||||
this.headerPosition = 0;
|
||||
this.lastEnd = 0;
|
||||
};
|
||||
|
||||
//appends a header block to all the written data since the last
|
||||
//subsequent header or to the beginning if there is only one data block
|
||||
Writer.prototype.addHeader = function(code, last) {
|
||||
var origOffset = this.offset;
|
||||
this.offset = this.headerPosition;
|
||||
this.buffer[this.offset++] = code;
|
||||
//length is everything in this packet minus the code
|
||||
this.addInt32(origOffset - (this.headerPosition+1));
|
||||
//set next header position
|
||||
this.headerPosition = origOffset;
|
||||
//make space for next header
|
||||
this.offset = origOffset;
|
||||
if(!last) {
|
||||
this._ensure(5);
|
||||
this.offset += 5;
|
||||
}
|
||||
};
|
||||
|
||||
Writer.prototype.join = function(code) {
|
||||
if(code) {
|
||||
this.addHeader(code, true);
|
||||
}
|
||||
return this.buffer.slice(code ? 0 : 5, this.offset);
|
||||
};
|
||||
|
||||
Writer.prototype.flush = function(code) {
|
||||
var result = this.join(code);
|
||||
this.clear();
|
||||
return result;
|
||||
};
|
61
express-server/node_modules/buffer-writer/package.json
generated
vendored
Normal file
61
express-server/node_modules/buffer-writer/package.json
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"_from": "buffer-writer@1.0.1",
|
||||
"_id": "buffer-writer@1.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-Iqk2kB4wKa/NdUfrRIfOtpejvwg=",
|
||||
"_location": "/buffer-writer",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "buffer-writer@1.0.1",
|
||||
"name": "buffer-writer",
|
||||
"escapedName": "buffer-writer",
|
||||
"rawSpec": "1.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pg"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz",
|
||||
"_shasum": "22a936901e3029afcd7547eb4487ceb697a3bf08",
|
||||
"_spec": "buffer-writer@1.0.1",
|
||||
"_where": "D:\\5CHITM\\Diplomarbeit\\smart-shopper\\SmartShopper\\express-server\\node_modules\\pg",
|
||||
"author": {
|
||||
"name": "Brian M. Carlson"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/brianc/node-buffer-writer/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "a fast, efficient buffer writer",
|
||||
"devDependencies": {
|
||||
"async": "~0.2.6",
|
||||
"bench": "~0.3.5",
|
||||
"benchmark": "~1.0.0",
|
||||
"cloned": "0.0.1",
|
||||
"microtime": "~0.3.3",
|
||||
"mocha": "~1.8.1",
|
||||
"okay": "0.0.2",
|
||||
"rmdir": "~1.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/brianc/node-buffer-writer#readme",
|
||||
"keywords": [
|
||||
"buffer",
|
||||
"writer",
|
||||
"builder"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "buffer-writer",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/brianc/node-buffer-writer.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "1.0.1"
|
||||
}
|
1
express-server/node_modules/buffer-writer/test/mocha.opts
generated
vendored
Normal file
1
express-server/node_modules/buffer-writer/test/mocha.opts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
--ui tdd
|
218
express-server/node_modules/buffer-writer/test/writer-tests.js
generated
vendored
Normal file
218
express-server/node_modules/buffer-writer/test/writer-tests.js
generated
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
var Writer = require(__dirname + "/../");
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('util');
|
||||
|
||||
assert.equalBuffers = function(actual, expected) {
|
||||
var spit = function(actual, expected) {
|
||||
console.log("");
|
||||
console.log("actual " + util.inspect(actual));
|
||||
console.log("expect " + util.inspect(expected));
|
||||
console.log("");
|
||||
};
|
||||
if(actual.length != expected.length) {
|
||||
spit(actual, expected);
|
||||
assert.equal(actual.length, expected.length);
|
||||
}
|
||||
for(var i = 0; i < actual.length; i++) {
|
||||
if(actual[i] != expected[i]) {
|
||||
spit(actual, expected);
|
||||
}
|
||||
assert.equal(actual[i],expected[i]);
|
||||
}
|
||||
};
|
||||
|
||||
suite('adding int32', function() {
|
||||
var testAddingInt32 = function(int, expectedBuffer) {
|
||||
test('writes ' + int, function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addInt32(int).join();
|
||||
assert.equalBuffers(result, expectedBuffer);
|
||||
});
|
||||
};
|
||||
|
||||
testAddingInt32(0, [0, 0, 0, 0]);
|
||||
testAddingInt32(1, [0, 0, 0, 1]);
|
||||
testAddingInt32(256, [0, 0, 1, 0]);
|
||||
test('writes largest int32', function() {
|
||||
//todo need to find largest int32 when I have internet access
|
||||
return false;
|
||||
});
|
||||
|
||||
test('writing multiple int32s', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addInt32(1).addInt32(10).addInt32(0).join();
|
||||
assert.equalBuffers(result, [0, 0, 0, 1, 0, 0, 0, 0x0a, 0, 0, 0, 0]);
|
||||
});
|
||||
|
||||
suite('having to resize the buffer', function() {
|
||||
test('after resize correct result returned', function() {
|
||||
var subject = new Writer(10);
|
||||
subject.addInt32(1).addInt32(1).addInt32(1);
|
||||
assert.equalBuffers(subject.join(), [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('int16', function() {
|
||||
test('writes 0', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addInt16(0).join();
|
||||
assert.equalBuffers(result, [0,0]);
|
||||
});
|
||||
|
||||
test('writes 400', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addInt16(400).join();
|
||||
assert.equalBuffers(result, [1, 0x90]);
|
||||
});
|
||||
|
||||
test('writes many', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addInt16(0).addInt16(1).addInt16(2).join();
|
||||
assert.equalBuffers(result, [0, 0, 0, 1, 0, 2]);
|
||||
});
|
||||
|
||||
test('resizes if internal buffer fills up', function() {
|
||||
var subject = new Writer(3);
|
||||
var result = subject.addInt16(2).addInt16(3).join();
|
||||
assert.equalBuffers(result, [0, 2, 0, 3]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('cString', function() {
|
||||
test('writes empty cstring', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addCString().join();
|
||||
assert.equalBuffers(result, [0]);
|
||||
});
|
||||
|
||||
test('writes two empty cstrings', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addCString("").addCString("").join();
|
||||
assert.equalBuffers(result, [0, 0]);
|
||||
});
|
||||
|
||||
|
||||
test('writes non-empty cstring', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addCString("!!!").join();
|
||||
assert.equalBuffers(result, [33, 33, 33, 0]);
|
||||
});
|
||||
|
||||
test('resizes if reached end', function() {
|
||||
var subject = new Writer(3);
|
||||
var result = subject.addCString("!!!").join();
|
||||
assert.equalBuffers(result, [33, 33, 33, 0]);
|
||||
});
|
||||
|
||||
test('writes multiple cstrings', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addCString("!").addCString("!").join();
|
||||
assert.equalBuffers(result, [33, 0, 33, 0]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('writes char', function() {
|
||||
var subject = new Writer(2);
|
||||
var result = subject.addChar('a').addChar('b').addChar('c').join();
|
||||
assert.equalBuffers(result, [0x61, 0x62, 0x63]);
|
||||
});
|
||||
|
||||
test('gets correct byte length', function() {
|
||||
var subject = new Writer(5);
|
||||
assert.equal(subject.getByteLength(), 0);
|
||||
subject.addInt32(0);
|
||||
assert.equal(subject.getByteLength(), 4);
|
||||
subject.addCString("!");
|
||||
assert.equal(subject.getByteLength(), 6);
|
||||
});
|
||||
|
||||
test('can add arbitrary buffer to the end', function() {
|
||||
var subject = new Writer(4);
|
||||
subject.addCString("!!!")
|
||||
var result = subject.add(Buffer("@@@")).join();
|
||||
assert.equalBuffers(result, [33, 33, 33, 0, 0x40, 0x40, 0x40]);
|
||||
});
|
||||
|
||||
suite('can write normal string', function() {
|
||||
var subject = new Writer(4);
|
||||
var result = subject.addString("!").join();
|
||||
assert.equalBuffers(result, [33]);
|
||||
test('can write cString too', function() {
|
||||
var result = subject.addCString("!").join();
|
||||
assert.equalBuffers(result, [33, 33, 0]);
|
||||
});
|
||||
test('can resize', function() {
|
||||
var result = subject.addString("!!").join();
|
||||
assert.equalBuffers(result, [33, 33, 0, 33, 33]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
suite('clearing', function() {
|
||||
var subject = new Writer();
|
||||
subject.addCString("@!!#!#");
|
||||
subject.addInt32(10401);
|
||||
test('clears', function() {
|
||||
subject.clear();
|
||||
assert.equalBuffers(subject.join(), []);
|
||||
});
|
||||
test('writing more', function() {
|
||||
var joinedResult = subject.addCString("!").addInt32(9).addInt16(2).join();
|
||||
assert.equalBuffers(joinedResult, [33, 0, 0, 0, 0, 9, 0, 2]);
|
||||
});
|
||||
test('returns result', function() {
|
||||
var flushedResult = subject.flush();
|
||||
assert.equalBuffers(flushedResult, [33, 0, 0, 0, 0, 9, 0, 2])
|
||||
});
|
||||
test('clears the writer', function() {
|
||||
assert.equalBuffers(subject.join(), [])
|
||||
assert.equalBuffers(subject.flush(), [])
|
||||
});
|
||||
});
|
||||
|
||||
test("resizing to much larger", function() {
|
||||
var subject = new Writer(2);
|
||||
var string = "!!!!!!!!";
|
||||
var result = subject.addCString(string).flush();
|
||||
assert.equalBuffers(result, [33, 33, 33, 33, 33, 33, 33, 33, 0]);
|
||||
});
|
||||
|
||||
suite("flush", function() {
|
||||
test('added as a hex code to a full writer', function() {
|
||||
var subject = new Writer(2);
|
||||
var result = subject.addCString("!").flush(0x50);
|
||||
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0]);
|
||||
});
|
||||
|
||||
test('added as a hex code to a non-full writer', function() {
|
||||
var subject = new Writer(10).addCString("!");
|
||||
var joinedResult = subject.join(0x50);
|
||||
var result = subject.flush(0x50);
|
||||
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0]);
|
||||
});
|
||||
|
||||
test('added as a hex code to a buffer which requires resizing', function() {
|
||||
var result = new Writer(2).addCString("!!!!!!!!").flush(0x50);
|
||||
assert.equalBuffers(result, [0x50, 0, 0, 0, 0x0D, 33, 33, 33, 33, 33, 33, 33, 33, 0]);
|
||||
});
|
||||
});
|
||||
|
||||
suite("header", function() {
|
||||
test('adding two packets with headers', function() {
|
||||
var subject = new Writer(10).addCString("!");
|
||||
subject.addHeader(0x50);
|
||||
subject.addCString("!!");
|
||||
subject.addHeader(0x40);
|
||||
subject.addCString("!");
|
||||
var result = subject.flush(0x10);
|
||||
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0, 0x40, 0, 0, 0, 7, 33, 33, 0, 0x10, 0, 0, 0, 6, 33, 0 ]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user