Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add .readI32 etc to TBufferedTransport

  • Loading branch information...
commit 4eae969bdb5d039a8559cea5a57eecff06ef906f 1 parent 4bfe87f
@wadey authored
Showing with 39 additions and 1 deletion.
  1. +39 −1 lib/thrift/transport.js
View
40 lib/thrift/transport.js
@@ -207,16 +207,54 @@ TBufferedTransport.prototype = {
open: function() {},
close: function() {},
- read: function(len) {
+ ensureAvailable: function(len) {
if (this.readCursor + len > this.writeCursor) {
throw new InputBufferUnderrunError();
}
+ },
+
+ read: function(len) {
+ this.ensureAvailable(len)
var buf = new Buffer(len);
this.inBuf.copy(buf, 0, this.readCursor, this.readCursor + len);
this.readCursor += len;
return buf;
},
+ readByte: function() {
+ this.ensureAvailable(1)
+ return this.inBuf[this.readCursor++];
+ },
+
+ readI16: function() {
+ this.ensureAvailable(2)
+ var i16 = binary.readI16(this.inBuf, this.readCursor);
+ this.readCursor += 2;
+ return i16;
+ },
+
+ readI32: function() {
+ this.ensureAvailable(4)
+ var i32 = binary.readI32(this.inBuf, this.readCursor);
+ this.readCursor += 4;
+ return i32;
+ },
+
+ readDouble: function() {
+ this.ensureAvailable(8)
+ var d = binary.readDouble(this.inBuf, this.readCursor);
+ this.readCursor += 8;
+ return d;
+ },
+
+ readString: function(len) {
+ this.ensureAvailable(len)
+ var str = this.inBuf.toString('utf8', this.readCursor, this.readCursor + len);
+ this.readCursor += len;
+ return str;
+ },
+
+
readAll: function() {
if (this.readCursor >= this.writeCursor) {
throw new InputBufferUnderrunError();
Please sign in to comment.
Something went wrong with that request. Please try again.