UNPKG

891 BJavaScriptView Raw
1//
2//
3//
4
5// Stringifying various things
6
7var defs = require('./defs');
8var format = require('util').format;
9var Frames = require('./frame');
10var inherits = require('util').inherits;
11
12module.exports.closeMessage = function(close) {
13 return close.fields.replyCode + ' - ' + close.fields.replyText;
14}
15
16module.exports.methodName = function(id) {
17 return defs.info(id).name;
18};
19
20function inspectFrame(frame, showFields) {
21 if (frame === Frames.Heartbeat) {
22 return '<Heartbeat>';
23 }
24 else if (!frame.id) {
25 return format('<Content channel:%d size:%d>',
26 frame.channel, frame.size);
27 }
28 else {
29 var info = defs.info(frame.id);
30 return format('<%s channel:%d%s>', info.name, frame.channel,
31 (showFields)
32 ? ' ' + JSON.stringify(frame.fields, undefined, 2)
33 : '');
34 }
35}
36
37module.exports.inspect = inspectFrame;