Skip to content

Commit

Permalink
Merge pull request tulios#686 from Collaborne/pr/jsdoc-encoder-writeA…
Browse files Browse the repository at this point in the history
…rray

Document the parameters of `writeArray` and `writeNullableArray`
  • Loading branch information
Nevon authored Apr 6, 2020
2 parents c7ed777 + 71c5db8 commit fe4d73d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/protocol/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,22 @@ module.exports = class Encoder {
return this
}

/**
* @param {any[]} array
* @param {'int32'|'number'|'string'|'object'} [type]
*/
writeNullableArray(array, type) {
// A null value is encoded with length of -1 and there are no following bytes
// On the context of this library, empty array and null are the same thing
const length = array.length !== 0 ? array.length : -1
return this.writeArray(array, type, length)
}

/**
* @param {any[]} array
* @param {'int32'|'number'|'string'|'object'} [type]
* @param {number} [length]
*/
writeArray(array, type, length) {
const arrayLength = length == null ? array.length : length
this.writeInt32(arrayLength)
Expand All @@ -228,7 +237,6 @@ module.exports = class Encoder {
} else {
array.forEach(value => {
switch (typeof value) {
case 'int32':
case 'number':
this.writeInt32(value)
break
Expand Down

0 comments on commit fe4d73d

Please sign in to comment.