format.js 948 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. //
  3. //
  4. // Stringifying various things
  5. 'use strict';
  6. var defs = require('./defs');
  7. var format = require('util').format;
  8. var HEARTBEAT = require('./frame').HEARTBEAT;
  9. module.exports.closeMessage = function(close) {
  10. var code = close.fields.replyCode;
  11. return format('%d (%s) with message "%s"',
  12. code, defs.constant_strs[code],
  13. close.fields.replyText);
  14. }
  15. module.exports.methodName = function(id) {
  16. return defs.info(id).name;
  17. };
  18. module.exports.inspect = function(frame, showFields) {
  19. if (frame === HEARTBEAT) {
  20. return '<Heartbeat>';
  21. }
  22. else if (!frame.id) {
  23. return format('<Content channel:%d size:%d>',
  24. frame.channel, frame.size);
  25. }
  26. else {
  27. var info = defs.info(frame.id);
  28. return format('<%s channel:%d%s>', info.name, frame.channel,
  29. (showFields)
  30. ? ' ' + JSON.stringify(frame.fields, undefined, 2)
  31. : '');
  32. }
  33. }