Comparing version 0.1.9 to 0.1.10
@@ -245,2 +245,5 @@ /* | ||
this.socket = socket; | ||
if (this.get_option('tcp_no_delay', false) && this.socket.setNoDelay) { | ||
this.socket.setNoDelay(true); | ||
} | ||
this.socket.on('data', this.input.bind(this)); | ||
@@ -301,2 +304,5 @@ this.socket.on('error', this.on_error.bind(this)); | ||
Connection.prototype.attach_receiver = function (options) { | ||
if (this.get_option('tcp_no_delay', true) && this.socket.setNoDelay) { | ||
this.socket.setNoDelay(true); | ||
} | ||
return this.session_policy.get_session().attach_receiver(options); | ||
@@ -303,0 +309,0 @@ }; |
@@ -308,3 +308,3 @@ /* | ||
this.drain = false; | ||
this.set_credit_window(this.get_option('credit_window', 1000)); | ||
this.set_credit_window(this.get_option('credit_window', 100)); | ||
if (this.get_option('autoaccept', true)) { | ||
@@ -311,0 +311,0 @@ this.observers.on('message', auto_accept); |
@@ -331,7 +331,2 @@ /* | ||
} | ||
if (msg.application_properties) { | ||
for (var key in msg.application_properties) { | ||
add_property_shortcut(msg, 'application_properties', key); | ||
} | ||
} | ||
return msg; | ||
@@ -338,0 +333,0 @@ }; |
@@ -80,3 +80,3 @@ /* | ||
} | ||
while (offset < buffer.length && !this.read_complete) { | ||
while (offset < (buffer.length - 4) && !this.read_complete) { | ||
var frame_size = buffer.readUInt32BE(offset); | ||
@@ -83,0 +83,0 @@ log.io('[%s] got frame of size %d', this.identifier, frame_size); |
241
lib/types.js
@@ -25,5 +25,11 @@ /* | ||
function Typed(type, value) { | ||
function Typed(type, value, code, descriptor) { | ||
this.type = type; | ||
this.value = value; | ||
if (code) { | ||
this.array_constructor = {'typecode':code}; | ||
if (descriptor) { | ||
this.array_constructor.descriptor = descriptor; | ||
} | ||
} | ||
} | ||
@@ -47,87 +53,54 @@ | ||
function hex(i) { | ||
return Number(i).toString(16); | ||
} | ||
var types = {'by_code':{}}; | ||
Object.defineProperty(types, 'MAX_UINT', {value: 4294967295, writable: false, configurable: false}); | ||
Object.defineProperty(types, 'MAX_USHORT', {value: 65535, writable: false, configurable: false}); | ||
function define_type(name, typecode, annotations, empty_value) { | ||
function TypeDesc(name, typecode, props, empty_value) { | ||
this.name = name; | ||
this.typecode = typecode; | ||
var subcategory = typecode >>> 4; | ||
var t; | ||
if (subcategory === 0x4) { | ||
// constructors for 'empty' types don't take a value | ||
t = function () { | ||
this.type = t; | ||
this.value = empty_value; | ||
}; | ||
} else if (subcategory === 0xE || subcategory === 0xF) { | ||
t = function (v, code, descriptor) { | ||
this.type = t; | ||
this.value = v; | ||
this.array_constructor = {'typecode':code}; | ||
if (descriptor) { | ||
this.array_constructor.descriptor = descriptor; | ||
} | ||
}; | ||
} else { | ||
t = function (v) { | ||
this.type = t; | ||
this.value = v; | ||
}; | ||
} | ||
t.typecode = typecode; | ||
t.prototype = Object.create(Typed.prototype); | ||
t.toString = function () { | ||
return name + '#' + hex(typecode); | ||
}; | ||
switch (subcategory) { | ||
case 0x4: | ||
t.width = 0; | ||
t.category = CAT_FIXED; | ||
this.width = 0; | ||
this.category = CAT_FIXED; | ||
break; | ||
case 0x5: | ||
t.width = 1; | ||
t.category = CAT_FIXED; | ||
this.width = 1; | ||
this.category = CAT_FIXED; | ||
break; | ||
case 0x6: | ||
t.width = 2; | ||
t.category = CAT_FIXED; | ||
this.width = 2; | ||
this.category = CAT_FIXED; | ||
break; | ||
case 0x7: | ||
t.width = 4; | ||
t.category = CAT_FIXED; | ||
this.width = 4; | ||
this.category = CAT_FIXED; | ||
break; | ||
case 0x8: | ||
t.width = 8; | ||
t.category = CAT_FIXED; | ||
this.width = 8; | ||
this.category = CAT_FIXED; | ||
break; | ||
case 0x9: | ||
t.width = 16; | ||
t.category = CAT_FIXED; | ||
this.width = 16; | ||
this.category = CAT_FIXED; | ||
break; | ||
case 0xA: | ||
t.width = 1; | ||
t.category = CAT_VARIABLE; | ||
this.width = 1; | ||
this.category = CAT_VARIABLE; | ||
break; | ||
case 0xB: | ||
t.width = 4; | ||
t.category = CAT_VARIABLE; | ||
this.width = 4; | ||
this.category = CAT_VARIABLE; | ||
break; | ||
case 0xC: | ||
t.width = 1; | ||
t.category = CAT_COMPOUND; | ||
this.width = 1; | ||
this.category = CAT_COMPOUND; | ||
break; | ||
case 0xD: | ||
t.width = 4; | ||
t.category = CAT_COMPOUND; | ||
this.width = 4; | ||
this.category = CAT_COMPOUND; | ||
break; | ||
case 0xE: | ||
t.width = 1; | ||
t.category = CAT_ARRAY; | ||
this.width = 1; | ||
this.category = CAT_ARRAY; | ||
break; | ||
case 0xF: | ||
t.width = 4; | ||
t.category = CAT_ARRAY; | ||
this.width = 4; | ||
this.category = CAT_ARRAY; | ||
break; | ||
@@ -138,30 +111,49 @@ default: | ||
} | ||
// not used at present: | ||
// | ||
//if (t.category === CAT_FIXED) { | ||
// t.prototype.encoded_size = function () { | ||
// return this.type.width; | ||
// } | ||
//} else if (t.category === CAT_VARIABLE) { | ||
// t.prototype.encoded_size = function () { | ||
// return this.type.width + this.value.length; | ||
// } | ||
//} else if (t.category === CAT_COMPOUND) { | ||
// t.prototype.encoded_size = function () { | ||
// var s = this.type.width*2; | ||
// for (i in this.value) { | ||
// s += 1/*typecode*/ + i.encoded_size();//what if i is described???? | ||
// } | ||
// return s; | ||
// } | ||
//} | ||
if (annotations) { | ||
for (var a in annotations) { | ||
t[a] = annotations[a]; | ||
if (props) { | ||
if (props.read) { | ||
this.read = props.read; | ||
} | ||
if (props.write) { | ||
this.write = props.write; | ||
} | ||
if (props.encoding) { | ||
this.encoding = props.encoding; | ||
} | ||
} | ||
var t = this; | ||
if (subcategory === 0x4) { | ||
// 'empty' types don't take a value | ||
this.create = function () { | ||
return new Typed(t, empty_value); | ||
}; | ||
} else if (subcategory === 0xE || subcategory === 0xF) { | ||
this.create = function (v, code, descriptor) { | ||
return new Typed(t, v, code, descriptor); | ||
}; | ||
} else { | ||
this.create = function (v) { | ||
return new Typed(t, v); | ||
}; | ||
} | ||
} | ||
TypeDesc.prototype.toString = function () { | ||
return this.name + '#' + hex(this.typecode); | ||
}; | ||
function hex(i) { | ||
return Number(i).toString(16); | ||
} | ||
var types = {'by_code':{}}; | ||
Object.defineProperty(types, 'MAX_UINT', {value: 4294967295, writable: false, configurable: false}); | ||
Object.defineProperty(types, 'MAX_USHORT', {value: 65535, writable: false, configurable: false}); | ||
function define_type(name, typecode, annotations, empty_value) { | ||
var t = new TypeDesc(name, typecode, annotations, empty_value); | ||
t.create.typecode = t.typecode;//hack | ||
types.by_code[t.typecode] = t; | ||
types[name] = t; | ||
return t; | ||
types[name] = t.create; | ||
} | ||
@@ -348,22 +340,22 @@ | ||
types.wrap_boolean = function(v) { | ||
return v ? new types.True() : new types.False(); | ||
return v ? types.True() : types.False(); | ||
}; | ||
types.wrap_ulong = function(l) { | ||
if (Buffer.isBuffer(l)) { | ||
if (buffer_zero(l, 8, false)) return new types.Ulong0(); | ||
return buffer_zero(l, 7, false) ? new types.SmallUlong(l[7]) : new types.Ulong(l); | ||
if (buffer_zero(l, 8, false)) return types.Ulong0(); | ||
return buffer_zero(l, 7, false) ? types.SmallUlong(l[7]) : types.Ulong(l); | ||
} else { | ||
if (l === 0) return new types.Ulong0(); | ||
else return l > 255 ? new types.Ulong(l) : new types.SmallUlong(l); | ||
if (l === 0) return types.Ulong0(); | ||
else return l > 255 ? types.Ulong(l) : types.SmallUlong(l); | ||
} | ||
}; | ||
types.wrap_uint = function(l) { | ||
if (l === 0) return new types.Uint0(); | ||
else return l > 255 ? new types.Uint(l) : new types.SmallUint(l); | ||
if (l === 0) return types.Uint0(); | ||
else return l > 255 ? types.Uint(l) : types.SmallUint(l); | ||
}; | ||
types.wrap_ushort = function(l) { | ||
return new types.Ushort(l); | ||
return types.Ushort(l); | ||
}; | ||
types.wrap_ubyte = function(l) { | ||
return new types.Ubyte(l); | ||
return types.Ubyte(l); | ||
}; | ||
@@ -374,46 +366,46 @@ types.wrap_long = function(l) { | ||
if (buffer_zero(l, 7, negFlag) && (l[7] & 0x80) === (negFlag ? 0x80 : 0)) { | ||
return new types.SmallLong(negFlag ? -((l[7] ^ 0xff) + 1) : l[7]); | ||
return types.SmallLong(negFlag ? -((l[7] ^ 0xff) + 1) : l[7]); | ||
} | ||
return new types.Long(l); | ||
return types.Long(l); | ||
} else { | ||
return l > 127 || l < -128 ? new types.Long(l) : new types.SmallLong(l); | ||
return l > 127 || l < -128 ? types.Long(l) : types.SmallLong(l); | ||
} | ||
}; | ||
types.wrap_int = function(l) { | ||
return l > 127 || l < -128 ? new types.Int(l) : new types.SmallInt(l); | ||
return l > 127 || l < -128 ? types.Int(l) : types.SmallInt(l); | ||
}; | ||
types.wrap_short = function(l) { | ||
return new types.Short(l); | ||
return types.Short(l); | ||
}; | ||
types.wrap_byte = function(l) { | ||
return new types.Byte(l); | ||
return types.Byte(l); | ||
}; | ||
types.wrap_float = function(l) { | ||
return new types.Float(l); | ||
return types.Float(l); | ||
}; | ||
types.wrap_double = function(l) { | ||
return new types.Double(l); | ||
return types.Double(l); | ||
}; | ||
types.wrap_timestamp = function(l) { | ||
return new types.Timestamp(l); | ||
return types.Timestamp(l); | ||
}; | ||
types.wrap_char = function(v) { | ||
return new types.CharUTF32(v); | ||
return types.CharUTF32(v); | ||
}; | ||
types.wrap_uuid = function(v) { | ||
return new types.Uuid(v); | ||
return types.Uuid(v); | ||
}; | ||
types.wrap_binary = function (s) { | ||
return s.length > 255 ? new types.Vbin32(s) : new types.Vbin8(s); | ||
return s.length > 255 ? types.Vbin32(s) : types.Vbin8(s); | ||
}; | ||
types.wrap_string = function (s) { | ||
return s.length > 255 ? new types.Str32(s) : new types.Str8(s); | ||
return s.length > 255 ? types.Str32(s) : types.Str8(s); | ||
}; | ||
types.wrap_symbol = function (s) { | ||
return s.length > 255 ? new types.Sym32(s) : new types.Sym8(s); | ||
return s.length > 255 ? types.Sym32(s) : types.Sym8(s); | ||
}; | ||
types.wrap_list = function(l) { | ||
if (l.length === 0) return new types.List0(); | ||
if (l.length === 0) return types.List0(); | ||
var items = l.map(types.wrap); | ||
return new types.List32(items); | ||
return types.List32(items); | ||
}; | ||
@@ -426,3 +418,3 @@ types.wrap_map = function(m, key_wrapper) { | ||
} | ||
return new types.Map32(items); | ||
return types.Map32(items); | ||
}; | ||
@@ -434,4 +426,5 @@ types.wrap_symbolic_map = function(m) { | ||
if (code) { | ||
return new types.Array32(l, code, descriptors); | ||
return types.Array32(l, code, descriptors); | ||
} else { | ||
console.trace('An array must specify a type for its elements'); | ||
throw new errors.TypeError('An array must specify a type for its elements'); | ||
@@ -445,3 +438,3 @@ } | ||
} else if (t === 'boolean') { | ||
return o ? new types.True() : new types.False(); | ||
return o ? types.True() : types.False(); | ||
} else if (t === 'number' || o instanceof Number) { | ||
@@ -451,3 +444,3 @@ if (isNaN(o)) { | ||
} else if (Math.floor(o) - o !== 0) { | ||
return new types.Double(o); | ||
return types.Double(o); | ||
} else if (o > 0) { | ||
@@ -473,3 +466,3 @@ if (o < MAX_UINT) { | ||
} else if (t === 'undefined' || o === null) { | ||
return new types.Null(); | ||
return types.Null(); | ||
} else if (Array.isArray(o)) { | ||
@@ -543,2 +536,3 @@ return types.wrap_list(o); | ||
/* | ||
types.described = function (descriptor, typedvalue) { | ||
@@ -554,3 +548,3 @@ var o = Object.create(typedvalue); | ||
}; | ||
*/ | ||
types.described_nc = function (descriptor, o) { | ||
@@ -565,2 +559,3 @@ if (descriptor.length) { | ||
}; | ||
types.described = types.described_nc; | ||
@@ -638,7 +633,7 @@ function get_type(code) { | ||
if (type.width === 0) { | ||
return new type(); | ||
return type.create(); | ||
} else if (type.category === CAT_FIXED) { | ||
return new type(this.read_fixed_width(type)); | ||
return type.create(this.read_fixed_width(type)); | ||
} else if (type.category === CAT_VARIABLE) { | ||
return new type(this.read_variable_width(type)); | ||
return type.create(this.read_variable_width(type)); | ||
} else if (type.category === CAT_COMPOUND) { | ||
@@ -675,3 +670,3 @@ return this.read_compound(type); | ||
var limits = this.read_size_count(type.width); | ||
return new type(this.read_n(limits.count)); | ||
return type.create(this.read_n(limits.count)); | ||
}; | ||
@@ -682,3 +677,3 @@ | ||
var constructor = this.read_constructor(); | ||
return new type(this.read_array_items(limits.count, get_type(constructor.typecode)), constructor.typecode, constructor.descriptor); | ||
return type.create(this.read_array_items(limits.count, get_type(constructor.typecode)), constructor.typecode, constructor.descriptor); | ||
}; | ||
@@ -826,3 +821,3 @@ | ||
if (value[i] === undefined || value[i] === null) { | ||
this.write(new types.Null); | ||
this.write(types.Null()); | ||
} else { | ||
@@ -900,3 +895,3 @@ this.write(value[i]); | ||
} else { | ||
return new types.Null(); | ||
return types.Null(); | ||
} | ||
@@ -903,0 +898,0 @@ } |
{ | ||
"name" : "rhea", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "reactive AMQP 1.0 library", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/grs/rhea", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
336187
7282