Skip to content
Browse files

Use --bare compilation.

  • Loading branch information...
1 parent b8d04f4 commit 869aaf0e72efb41a44243d036dd6ec8b869958d4 @wvanbergen committed
Showing with 59 additions and 140 deletions.
  1. +1 −1 Cakefile
  2. +19 −19 lib/backend_message.js
  3. +15 −99 lib/buffer.js
  4. +12 −9 lib/connection.js
  5. +12 −12 lib/frontend_message.js
View
2 Cakefile
@@ -2,7 +2,7 @@
print = (data) -> console.log data.toString().trim()
task 'build', ->
- exec 'mkdir -p lib && coffee -c -o lib src'
+ exec 'mkdir -p lib && coffee -c -o --bare lib src'
task 'clean', ->
exec 'rm -rf lib'
View
38 lib/backend_message.js
@@ -31,11 +31,11 @@ BackendMessage.Authentication = (function(_super) {
Authentication.prototype.typeId = 82;
Authentication.prototype.read = function(buffer) {
- this.method = buffer.readUInt32(0);
+ this.method = buffer.readUInt32BE(0);
if (this.method === AuthenticationMethods.MD5_PASSWORD) {
- return this.salt = buffer.readUInt32(4);
+ return this.salt = buffer.readUInt32BE(4);
} else if (this.method === AuthenticationMethods.CRYPT_PASSWORD) {
- return this.salt = buffer.readUInt16(4);
+ return this.salt = buffer.readUInt16BE(4);
}
};
@@ -54,8 +54,8 @@ BackendMessage.BackendKeyData = (function(_super) {
BackendKeyData.prototype.typeId = 75;
BackendKeyData.prototype.read = function(buffer) {
- this.pid = buffer.readUInt32(0);
- return this.key = buffer.readUInt32(4);
+ this.pid = buffer.readUInt32BE(0);
+ return this.key = buffer.readUInt32BE(4);
};
return BackendKeyData;
@@ -92,7 +92,7 @@ BackendMessage.NotificationResponse = (function(_super) {
NotificationResponse.prototype.typeId = 65;
NotificationResponse.prototype.read = function(buffer) {
- this.pid = buffer.readUInt32(4);
+ this.pid = buffer.readUInt32BE(4);
this.channel = buffer.readZeroTerminatedString(4);
return this.payload = buffer.readZeroTerminatedString(this.channel.length + 5);
};
@@ -128,24 +128,24 @@ BackendMessage.RowDescription = (function(_super) {
RowDescription.prototype.read = function(buffer) {
var fieldDescriptor, formatCode, i, modifier, name, numberOfFields, pos, size, tableFieldIndex, tableOID, typeOID, _i, _results;
- numberOfFields = buffer.readUInt16(0);
+ numberOfFields = buffer.readUInt16BE(0);
pos = 2;
this.columns = [];
_results = [];
for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
name = buffer.readZeroTerminatedString(pos);
pos += Buffer.byteLength(name) + 1;
- tableOID = buffer.readUInt32(pos);
+ tableOID = buffer.readUInt32BE(pos);
pos += 4;
- tableFieldIndex = buffer.readUInt16(pos);
+ tableFieldIndex = buffer.readUInt16BE(pos);
pos += 2;
- typeOID = buffer.readUInt32(pos);
+ typeOID = buffer.readUInt32BE(pos);
pos += 4;
- size = buffer.readUInt16(pos);
+ size = buffer.readUInt16BE(pos);
pos += 2;
- modifier = buffer.readUInt32(pos);
+ modifier = buffer.readUInt32BE(pos);
pos += 4;
- formatCode = buffer.readUInt16(pos);
+ formatCode = buffer.readUInt16BE(pos);
pos += 2;
fieldDescriptor = {
name: name,
@@ -179,14 +179,14 @@ BackendMessage.DataRow = (function(_super) {
DataRow.prototype.read = function(buffer) {
var data, i, length, numberOfFields, pos, _i, _results;
- numberOfFields = buffer.readUInt16(0);
+ numberOfFields = buffer.readUInt16BE(0);
pos = 2;
this.values = [];
_results = [];
for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
- length = buffer.readUInt32(pos);
+ length = buffer.readUInt32BE(pos);
pos += 4;
- if (length === -1) {
+ if (length === 4294967295) {
data = null;
} else {
data = buffer.slice(pos, pos + length);
@@ -246,13 +246,13 @@ BackendMessage.ParameterDescription = (function(_super) {
ParameterDescription.prototype.read = function(buffer) {
var count, i;
- count = buffer.readUInt16(0);
+ count = buffer.readUInt16BE(0);
return this.parameterTypes = (function() {
var _i, _results;
_results = [];
for (i = _i = 0; 0 <= count ? _i < count : _i > count; i = 0 <= count ? ++_i : --_i) {
- _results.push(buffer.readUInt32(2 + i * 4));
+ _results.push(buffer.readUInt32BE(2 + i * 4));
}
return _results;
})();
@@ -368,7 +368,7 @@ BackendMessage.CopyInResponse = (function(_super) {
this.globalFormatType = buffer.readUInt8(0);
this.fieldFormatTypes = [];
- numberOfFields = buffer.readUInt16(1);
+ numberOfFields = buffer.readUInt16BE(1);
pos = 3;
_results = [];
for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
View
114 lib/buffer.js
@@ -1,108 +1,24 @@
// Generated by CoffeeScript 1.6.2
-var Buffer, _base, _base1, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
+var Buffer;
Buffer = require('buffer').Buffer;
-if ((_ref = (_base = Buffer.prototype).writeUInt8) == null) {
- _base.writeUInt8 = function(number, offset) {
- this[offset] = number & 0xff;
- return void 0;
- };
-}
+Buffer.prototype.writeZeroTerminatedString = function(str, offset, encoding) {
+ var written;
-if ((_ref1 = (_base1 = Buffer.prototype).writeUInt16) == null) {
- _base1.writeUInt16 = function(number, offset, endian) {
- return this._writeUInt(2, number, offset, endian);
- };
-}
+ written = this.write(str, offset, null, encoding);
+ this.writeUInt8(0, offset + written);
+ return written + 1;
+};
-if ((_ref2 = (_base2 = Buffer.prototype).writeUInt32) == null) {
- _base2.writeUInt32 = function(number, offset, endian) {
- return this._writeUInt(4, number, offset, endian);
- };
-}
+Buffer.prototype.readZeroTerminatedString = function(offset, encoding) {
+ var endIndex;
-if ((_ref3 = (_base3 = Buffer.prototype)._writeUInt) == null) {
- _base3._writeUInt = function(bytes, number, offset, endian) {
- var currentOffset, encodingPositions, index, _i, _j, _k, _len, _ref4, _ref5, _results, _results1;
-
- encodingPositions = endian === 'little' ? (function() {
- _results = [];
- for (var _i = offset, _ref4 = offset + bytes - 1; offset <= _ref4 ? _i <= _ref4 : _i >= _ref4; offset <= _ref4 ? _i++ : _i--){ _results.push(_i); }
- return _results;
- }).apply(this) : (function() {
- _results1 = [];
- for (var _j = _ref5 = offset + bytes - 1; _ref5 <= offset ? _j <= offset : _j >= offset; _ref5 <= offset ? _j++ : _j--){ _results1.push(_j); }
- return _results1;
- }).apply(this);
- for (index = _k = 0, _len = encodingPositions.length; _k < _len; index = ++_k) {
- currentOffset = encodingPositions[index];
- this[currentOffset] = (number >> (8 * index)) & 0xff;
- }
- return void 0;
- };
-}
-
-if ((_ref4 = (_base4 = Buffer.prototype).writeZeroTerminatedString) == null) {
- _base4.writeZeroTerminatedString = function(str, offset, encoding) {
- var written;
-
- written = this.write(str, offset, null, encoding);
- this.writeUInt8(0, offset + written);
- return written + 1;
- };
-}
-
-if ((_ref5 = (_base5 = Buffer.prototype).readUInt8) == null) {
- _base5.readUInt8 = function(offset) {
- return this[offset];
- };
-}
-
-if ((_ref6 = (_base6 = Buffer.prototype).readUInt16) == null) {
- _base6.readUInt16 = function(offset, endian) {
- return this._readUInt(2, offset, endian);
- };
-}
-
-if ((_ref7 = (_base7 = Buffer.prototype).readUInt32) == null) {
- _base7.readUInt32 = function(offset, endian) {
- return this._readUInt(4, offset, endian);
- };
-}
-
-if ((_ref8 = (_base8 = Buffer.prototype)._readUInt) == null) {
- _base8._readUInt = function(bytes, offset, endian) {
- var currentOffset, encodingPositions, index, number, _i, _j, _k, _len, _ref10, _ref9, _results, _results1;
-
- encodingPositions = endian === 'little' ? (function() {
- _results = [];
- for (var _i = offset, _ref9 = offset + bytes - 1; offset <= _ref9 ? _i <= _ref9 : _i >= _ref9; offset <= _ref9 ? _i++ : _i--){ _results.push(_i); }
- return _results;
- }).apply(this) : (function() {
- _results1 = [];
- for (var _j = _ref10 = offset + bytes - 1; _ref10 <= offset ? _j <= offset : _j >= offset; _ref10 <= offset ? _j++ : _j--){ _results1.push(_j); }
- return _results1;
- }).apply(this);
- number = 0;
- for (index = _k = 0, _len = encodingPositions.length; _k < _len; index = ++_k) {
- currentOffset = encodingPositions[index];
- number = (this[currentOffset] << (index * 8)) | number;
- }
- return number;
- };
-}
-
-if ((_ref9 = (_base9 = Buffer.prototype).readZeroTerminatedString) == null) {
- _base9.readZeroTerminatedString = function(offset, encoding) {
- var endIndex;
-
- endIndex = offset;
- while (endIndex < this.length && this[endIndex] !== 0x00) {
- endIndex++;
- }
- return this.toString('ascii', offset, endIndex);
- };
-}
+ endIndex = offset;
+ while (endIndex < this.length && this[endIndex] !== 0x00) {
+ endIndex++;
+ }
+ return this.toString('ascii', offset, endIndex);
+};
exports.Buffer = Buffer;
View
21 lib/connection.js
@@ -328,17 +328,20 @@ Connection = (function(_super) {
buffer.copy(bufferedData, this.incomingData.length);
this.incomingData = bufferedData;
}
- size = this.incomingData.readUInt32(1);
_results = [];
- while (this.incomingData.length >= 5 && size + 1 <= this.incomingData.length) {
- message = BackendMessage.fromBuffer(this.incomingData.slice(0, size + 1));
- if (this.debug) {
- console.log('<=', message.event, message);
+ while (this.incomingData.length >= 5) {
+ size = this.incomingData.readUInt32BE(1);
+ if (size + 1 <= this.incomingData.length) {
+ message = BackendMessage.fromBuffer(this.incomingData.slice(0, size + 1));
+ if (this.debug) {
+ console.log('<=', message.event, message);
+ }
+ this.emit('message', message);
+ this.emit(message.event, message);
+ _results.push(this.incomingData = this.incomingData.slice(size + 1));
+ } else {
+ _results.push(void 0);
}
- this.emit('message', message);
- this.emit(message.event, message);
- this.incomingData = this.incomingData.slice(size + 1);
- _results.push(size = this.incomingData.readUInt32(1));
}
return _results;
};
View
24 lib/frontend_message.js
@@ -34,7 +34,7 @@ FrontendMessage = (function() {
} else {
pos = 0;
}
- messageBuffer.writeUInt32(payloadBuffer.length + 4, pos);
+ messageBuffer.writeUInt32BE(payloadBuffer.length + 4, pos);
payloadBuffer.copy(messageBuffer, pos + 4);
return messageBuffer;
};
@@ -61,7 +61,7 @@ FrontendMessage.Startup = (function(_super) {
pos = 0;
pl = new Buffer(8192);
- pl.writeUInt32(this.protocol, pos);
+ pl.writeUInt32BE(this.protocol, pos);
pos += 4;
if (this.user) {
pos += pl.writeZeroTerminatedString('user', pos);
@@ -100,7 +100,7 @@ FrontendMessage.SSLRequest = (function(_super) {
var pl;
pl = new Buffer(4);
- pl.writeUInt32(this.sslMagicNumber, 0);
+ pl.writeUInt32BE(this.sslMagicNumber, 0);
return pl;
};
@@ -171,9 +171,9 @@ FrontendMessage.CancelRequest = (function(_super) {
var b;
b = new Buffer(12);
- b.writeUInt32(this.cancelRequestMagicNumber, 0);
- b.writeUInt32(this.backendPid, 4);
- b.writeUInt32(this.backendKey, 8);
+ b.writeUInt32BE(this.cancelRequestMagicNumber, 0);
+ b.writeUInt32BE(this.backendPid, 4);
+ b.writeUInt32BE(this.backendKey, 8);
return b;
};
@@ -292,7 +292,7 @@ FrontendMessage.Execute = (function(_super) {
b = new Buffer(5 + this.portal.length);
pos = b.writeZeroTerminatedString(this.portal, 0);
- b.writeUInt32(this.maxRows, pos);
+ b.writeUInt32BE(this.maxRows, pos);
return b;
};
@@ -342,12 +342,12 @@ FrontendMessage.Parse = (function(_super) {
b = new Buffer(8192);
pos = b.writeZeroTerminatedString(this.name, 0);
pos += b.writeZeroTerminatedString(this.sql, pos);
- b.writeUInt16(this.parameterTypes.length, pos);
+ b.writeUInt16BE(this.parameterTypes.length, pos);
pos += 2;
_ref1 = this.parameterTypes;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
paramType = _ref1[_i];
- b.writeUInt32(paramType, pos);
+ b.writeUInt32BE(paramType, pos);
pos += 4;
}
return b.slice(0, pos);
@@ -381,13 +381,13 @@ FrontendMessage.Bind = (function(_super) {
pos = 0;
pos += b.writeZeroTerminatedString(this.portal, pos);
pos += b.writeZeroTerminatedString(this.preparedStatement, pos);
- b.writeUInt16(0x00, pos);
- b.writeUInt16(this.parameterValues.length, pos + 2);
+ b.writeUInt16BE(0x00, pos);
+ b.writeUInt16BE(this.parameterValues.length, pos + 2);
pos += 4;
_ref1 = this.parameterValues;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
value = _ref1[_i];
- b.writeUInt32(value.length, pos);
+ b.writeUInt32BE(value.length, pos);
pos += 4;
pos += b.write(value, pos);
}

0 comments on commit 869aaf0

Please sign in to comment.
Something went wrong with that request. Please try again.