Skip to content

Commit

Permalink
Merge pull request #4 from node-modules/overwrite
Browse files Browse the repository at this point in the history
Fix 2 input bugs
  • Loading branch information
fengmk2 committed Aug 5, 2014
2 parents cddd474 + ea8faf4 commit 2839572
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ proto._readExternalContents = function() {
}

proto._readArrayItems = function (obj) {
debug('>> _readArrayItems | position = %s', this.in.position().toString(16));
// (int)<size> values[size]
var size = this.readInt();

Expand All @@ -390,7 +391,7 @@ proto._readArrayItems = function (obj) {
obj.$.push(this._readFieldValue({type: type}));
}

debug('< _readArrayItems | size = %d, arr = %j', size, obj.$);
debug('<< _readArrayItems | size = %d, arr = %j', size, obj.$);
return obj;
}

Expand All @@ -410,6 +411,7 @@ proto._readFieldValue = function (field) {
// `[` // array
// `L' // object
debug('> _readFieldValue | field = %j', field);

switch (field.type) {
case 'B':
return this.in.getInt8();
Expand All @@ -428,15 +430,8 @@ proto._readFieldValue = function (field) {
case 'Z':
return this.in.get() !== 0;
case 'L':
return this._readContent();
case '[':
var obj = {
$class: {
name: field.classname,
},
$: []
};
return this._readArrayItems(obj);
return this._readContent();
default:
throw new Error('Illegal field type: ' + JSON.stringify(field));
}
Expand Down
Binary file added test/fixtures/out/NCommand.bin
Binary file not shown.
Binary file added test/fixtures/out/NCommand2.bin
Binary file not shown.
15 changes: 15 additions & 0 deletions test/input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,20 @@ describe('input.test.js', function () {
datumId: 'some-datumId'
});
});

it('read NCommand', function() {
ObjectInputStream.read(utils.bytes('NCommand')).should.eql({
isNewVersion: false,
id: '10.62.50.148:2923:0',
name: 'queryServerlist',
params: null });

ObjectInputStream.read(utils.bytes('NCommand2')).should.eql({
isNewVersion: false,
id: null,
name: 'queryServerlist',
params: ['abc'] });
});

});
});

0 comments on commit 2839572

Please sign in to comment.