Skip to content

Commit

Permalink
Cleanup wire.encode api.
Browse files Browse the repository at this point in the history
  • Loading branch information
lsm committed Apr 13, 2016
1 parent eb5e559 commit edd46f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
8 changes: 3 additions & 5 deletions lib/message/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ var isBuffer = Buffer.isBuffer
* {
* type: 'PUB',
* event: 'some event or topic or channel',
* formatId: 'j', // The format id of message encoder.
* msg: 'the real message data',
* msgId: '.12345'
* }
* @param {String} [formatId] The format id of message encoder.
* Optional when `msg` is String or Buffer.
* @param {Function} [encodeMsg] Message encoding function
* @return {[type]} [description]
* @return {Buffer}
*/
exports.encode = function(pack, formatId, encodeMsg) {
exports.encode = function(pack, encodeMsg) {
var msg = pack.msg

if ('string' === typeof msg) {
Expand All @@ -27,7 +26,6 @@ exports.encode = function(pack, formatId, encodeMsg) {
} else if (isBuffer(msg)) {
pack.formatId = type.BUFFER
} else {
pack.formatId = formatId
pack.msg = encodeMsg(msg)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/message/type.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if ('undefined' === typeof Buffer) {
if ('undefined' === typeof Buffer)
Buffer = require('buffer').Buffer
}


exports.Buffer = Buffer

Expand Down
4 changes: 2 additions & 2 deletions lib/socket/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SocketChannel.prototype.reqChn = function(chn, event, msg, callback) {

SocketChannel.prototype.req = function(event, msg, callback) {
if (!this.queue.chn)
throw new Error('SocketMQ has no default channel name')
throw new Error('SocketChannel has no default channel name')
this.reqChn(this.queue.chn, event, msg, callback || function() {})
}

Expand All @@ -36,7 +36,7 @@ SocketChannel.prototype.pubChn = function(chn, event, msg) {

SocketChannel.prototype.pub = function(event, msg) {
if (!this.queue.chn)
throw new Error('SocketMQ has no default channel name')
throw new Error('SocketChannel has no default channel name')
this.pubChn(this.queue.chn, event, msg)
}

Expand Down
3 changes: 2 additions & 1 deletion lib/socket/msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ exports.setMsgEncoder = function(encoder, formatId) {
return encode({
type: type,
event: event,
formatId: formatId,
msg: msg,
meta: meta
}, formatId, encodeMsg)
}, encodeMsg)
}
this.queue.decode = function(buf) {
return decode(buf, decodeMsg)
Expand Down

0 comments on commit edd46f3

Please sign in to comment.