primer cambio

This commit is contained in:
beseira13
2026-01-19 12:12:38 -03:00
parent 5f59dba52d
commit 44990f015a
4759 changed files with 588702 additions and 0 deletions

483
node_modules/amqplib/bin/amqp-rabbitmq-0.9.1.json generated vendored Normal file
View File

@@ -0,0 +1,483 @@
{
"name": "AMQP",
"major-version": 0,
"minor-version": 9,
"revision": 1,
"port": 5672,
"copyright": [
"Copyright (C) 2008-2020 VMware, Inc. or its affiliates.\n",
"\n",
"Permission is hereby granted, free of charge, to any person\n",
"obtaining a copy of this file (the \"Software\"), to deal in the\n",
"Software without restriction, including without limitation the \n",
"rights to use, copy, modify, merge, publish, distribute, \n",
"sublicense, and/or sell copies of the Software, and to permit \n",
"persons to whom the Software is furnished to do so, subject to \n",
"the following conditions:\n",
"\n",
"The above copyright notice and this permission notice shall be\n",
"included in all copies or substantial portions of the Software.\n",
"\n",
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n",
"EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n",
"OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n",
"NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n",
"HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n",
"WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n",
"FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n",
"OTHER DEALINGS IN THE SOFTWARE.\n",
"\n",
"Class information entered from amqp_xml0-8.pdf and domain types from amqp-xml-doc0-9.pdf\n",
"Updated for 0-9-1 by Tony Garnock-Jones\n",
"\n",
"b3cb053f15e7b98808c0ccc67f23cb3e amqp_xml0-8.pdf\n",
"http://twiststandards.org/?option=com_docman&task=cat_view&gid=28&Itemid=90\n",
"8444db91e2949dbecfb2585e9eef6d64 amqp-xml-doc0-9.pdf\n",
"https://jira.amqp.org/confluence/download/attachments/720900/amqp-xml-doc0-9.pdf?version=1\n"],
"domains": [
["bit", "bit"],
["channel-id", "longstr"],
["class-id", "short"],
["consumer-tag", "shortstr"],
["delivery-tag", "longlong"],
["destination", "shortstr"],
["duration", "longlong"],
["exchange-name", "shortstr"],
["long", "long"],
["longlong", "longlong"],
["longstr", "longstr"],
["message-count", "long"],
["method-id", "short"],
["no-ack", "bit"],
["no-local", "bit"],
["octet", "octet"],
["offset", "longlong"],
["path", "shortstr"],
["peer-properties", "table"],
["queue-name", "shortstr"],
["redelivered", "bit"],
["reference", "longstr"],
["reject-code", "short"],
["reject-text", "shortstr"],
["reply-code", "short"],
["reply-text", "shortstr"],
["security-token", "longstr"],
["short", "short"],
["shortstr", "shortstr"],
["table", "table"],
["timestamp", "timestamp"]
],
"constants": [
{"name": "FRAME-METHOD", "value": 1},
{"name": "FRAME-HEADER", "value": 2},
{"name": "FRAME-BODY", "value": 3},
{"name": "FRAME-HEARTBEAT", "value": 8},
{"name": "FRAME-MIN-SIZE", "value": 4096},
{"name": "FRAME-END", "value": 206},
{"name": "REPLY-SUCCESS", "value": 200},
{"name": "CONTENT-TOO-LARGE", "value": 311, "class": "soft-error"},
{"name": "NO-ROUTE", "value": 312, "class": "soft-error"},
{"name": "NO-CONSUMERS", "value": 313, "class": "soft-error"},
{"name": "ACCESS-REFUSED", "value": 403, "class": "soft-error"},
{"name": "NOT-FOUND", "value": 404, "class": "soft-error"},
{"name": "RESOURCE-LOCKED", "value": 405, "class": "soft-error"},
{"name": "PRECONDITION-FAILED", "value": 406, "class": "soft-error"},
{"name": "CONNECTION-FORCED", "value": 320, "class": "hard-error"},
{"name": "INVALID-PATH", "value": 402, "class": "hard-error"},
{"name": "FRAME-ERROR", "value": 501, "class": "hard-error"},
{"name": "SYNTAX-ERROR", "value": 502, "class": "hard-error"},
{"name": "COMMAND-INVALID", "value": 503, "class": "hard-error"},
{"name": "CHANNEL-ERROR", "value": 504, "class": "hard-error"},
{"name": "UNEXPECTED-FRAME", "value": 505, "class": "hard-error"},
{"name": "RESOURCE-ERROR", "value": 506, "class": "hard-error"},
{"name": "NOT-ALLOWED", "value": 530, "class": "hard-error"},
{"name": "NOT-IMPLEMENTED", "value": 540, "class": "hard-error"},
{"name": "INTERNAL-ERROR", "value": 541, "class": "hard-error"}
],
"classes": [
{
"id": 60,
"methods": [{"id": 10,
"arguments": [{"type": "long", "name": "prefetch-size", "default-value": 0},
{"type": "short", "name": "prefetch-count", "default-value": 0},
{"type": "bit", "name": "global", "default-value": false}],
"name": "qos",
"synchronous" : true},
{"id": 11,
"arguments": [],
"name": "qos-ok"},
{"id": 20,
"arguments": [{"domain": "short", "name": "ticket", "default-value": 0},
{"domain": "queue-name", "name": "queue", "default-value": ""},
{"type": "shortstr", "name": "consumer-tag", "default-value": ""},
{"type": "bit", "name": "no-local", "default-value": false},
{"type": "bit", "name": "no-ack", "default-value": false},
{"type": "bit", "name": "exclusive", "default-value": false},
{"type": "bit", "name": "nowait", "default-value": false},
{"type": "table", "name": "arguments", "default-value": {}}],
"name": "consume",
"synchronous" : true},
{"id": 21,
"arguments": [{"type": "shortstr", "name": "consumer-tag"}],
"name": "consume-ok"},
{"id": 30,
"arguments": [{"type": "shortstr", "name": "consumer-tag"},
{"type": "bit", "name": "nowait", "default-value": false}],
"name": "cancel",
"synchronous" : true},
{"id": 31,
"arguments": [{"type": "shortstr", "name": "consumer-tag"}],
"name": "cancel-ok"},
{"content": true,
"id": 40,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "exchange-name", "name": "exchange", "default-value": ""},
{"type": "shortstr", "name": "routing-key", "default-value": ""},
{"type": "bit", "name": "mandatory", "default-value": false},
{"type": "bit", "name": "immediate", "default-value": false}],
"name": "publish"},
{"content": true,
"id": 50,
"arguments": [{"type": "short", "name": "reply-code"},
{"type": "shortstr", "name": "reply-text", "default-value": ""},
{"domain": "exchange-name", "name": "exchange"},
{"type": "shortstr", "name": "routing-key"}],
"name": "return"},
{"content": true,
"id": 60,
"arguments": [{"type": "shortstr", "name": "consumer-tag"},
{"type": "longlong", "name": "delivery-tag"},
{"type": "bit", "name": "redelivered", "default-value": false},
{"domain": "exchange-name", "name": "exchange"},
{"type": "shortstr", "name": "routing-key"}],
"name": "deliver"},
{"id": 70,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "queue-name", "name": "queue", "default-value": ""},
{"type": "bit", "name": "no-ack", "default-value": false}],
"name": "get",
"synchronous" : true},
{"content": true,
"id": 71,
"arguments": [{"type": "longlong", "name": "delivery-tag"},
{"type": "bit", "name": "redelivered", "default-value": false},
{"domain": "exchange-name", "name": "exchange"},
{"type": "shortstr", "name": "routing-key"},
{"domain": "message-count", "name": "message-count"}],
"name": "get-ok"},
{"id": 72,
"arguments": [{"type": "shortstr", "name": "cluster-id", "default-value": ""}],
"name": "get-empty"},
{"id": 80,
"arguments": [{"type": "longlong", "name": "delivery-tag", "default-value": 0},
{"type": "bit", "name": "multiple", "default-value": false}],
"name": "ack"},
{"id": 90,
"arguments": [{"type": "longlong", "name": "delivery-tag"},
{"type": "bit", "name": "requeue", "default-value": true}],
"name": "reject"},
{"id": 100,
"arguments": [{"type": "bit", "name": "requeue", "default-value": false}],
"name": "recover-async"},
{"id": 110,
"arguments": [{"type": "bit", "name": "requeue", "default-value": false}],
"name": "recover",
"synchronous" : true},
{"id": 111,
"arguments": [],
"name": "recover-ok"},
{"id": 120,
"arguments": [{"type": "longlong", "name": "delivery-tag", "default-value": 0},
{"type": "bit", "name": "multiple", "default-value": false},
{"type": "bit", "name": "requeue", "default-value": true}],
"name": "nack"}],
"name": "basic",
"properties": [{"type": "shortstr", "name": "content-type"},
{"type": "shortstr", "name": "content-encoding"},
{"type": "table", "name": "headers"},
{"type": "octet", "name": "delivery-mode"},
{"type": "octet", "name": "priority"},
{"type": "shortstr", "name": "correlation-id"},
{"type": "shortstr", "name": "reply-to"},
{"type": "shortstr", "name": "expiration"},
{"type": "shortstr", "name": "message-id"},
{"type": "timestamp", "name": "timestamp"},
{"type": "shortstr", "name": "type"},
{"type": "shortstr", "name": "user-id"},
{"type": "shortstr", "name": "app-id"},
{"type": "shortstr", "name": "cluster-id"}]
},
{
"id": 10,
"methods": [{"id": 10,
"arguments": [{"type": "octet", "name": "version-major", "default-value": 0},
{"type": "octet", "name": "version-minor", "default-value": 9},
{"domain": "peer-properties", "name": "server-properties"},
{"type": "longstr", "name": "mechanisms", "default-value": "PLAIN"},
{"type": "longstr", "name": "locales", "default-value": "en_US"}],
"name": "start",
"synchronous" : true},
{"id": 11,
"arguments": [{"domain": "peer-properties", "name": "client-properties"},
{"type": "shortstr", "name": "mechanism", "default-value": "PLAIN"},
{"type": "longstr", "name": "response"},
{"type": "shortstr", "name": "locale", "default-value": "en_US"}],
"name": "start-ok"},
{"id": 20,
"arguments": [{"type": "longstr", "name": "challenge"}],
"name": "secure",
"synchronous" : true},
{"id": 21,
"arguments": [{"type": "longstr", "name": "response"}],
"name": "secure-ok"},
{"id": 30,
"arguments": [{"type": "short", "name": "channel-max", "default-value": 0},
{"type": "long", "name": "frame-max", "default-value": 0},
{"type": "short", "name": "heartbeat", "default-value": 0}],
"name": "tune",
"synchronous" : true},
{"id": 31,
"arguments": [{"type": "short", "name": "channel-max", "default-value": 0},
{"type": "long", "name": "frame-max", "default-value": 0},
{"type": "short", "name": "heartbeat", "default-value": 0}],
"name": "tune-ok"},
{"id": 40,
"arguments": [{"type": "shortstr", "name": "virtual-host", "default-value": "/"},
{"type": "shortstr", "name": "capabilities", "default-value": ""},
{"type": "bit", "name": "insist", "default-value": false}],
"name": "open",
"synchronous" : true},
{"id": 41,
"arguments": [{"type": "shortstr", "name": "known-hosts", "default-value": ""}],
"name": "open-ok"},
{"id": 50,
"arguments": [{"type": "short", "name": "reply-code"},
{"type": "shortstr", "name": "reply-text", "default-value": ""},
{"type": "short", "name": "class-id"},
{"type": "short", "name": "method-id"}],
"name": "close",
"synchronous" : true},
{"id": 51,
"arguments": [],
"name": "close-ok"},
{"id": 60,
"arguments": [{"type": "shortstr", "name": "reason", "default-value": ""}],
"name": "blocked"},
{"id": 61,
"arguments": [],
"name": "unblocked"},
{"id": 70,
"arguments": [{"type": "longstr", "name": "new-secret"},
{"type": "shortstr", "name": "reason"}],
"name": "update-secret",
"synchronous" : true},
{"id": 71,
"arguments": [],
"name": "update-secret-ok"}
],
"name": "connection",
"properties": []
},
{
"id": 20,
"methods": [{"id": 10,
"arguments": [{"type": "shortstr", "name": "out-of-band", "default-value": ""}],
"name": "open",
"synchronous" : true},
{"id": 11,
"arguments": [{"type": "longstr", "name": "channel-id", "default-value": ""}],
"name": "open-ok"},
{"id": 20,
"arguments": [{"type": "bit", "name": "active"}],
"name": "flow",
"synchronous" : true},
{"id": 21,
"arguments": [{"type": "bit", "name": "active"}],
"name": "flow-ok"},
{"id": 40,
"arguments": [{"type": "short", "name": "reply-code"},
{"type": "shortstr", "name": "reply-text", "default-value": ""},
{"type": "short", "name": "class-id"},
{"type": "short", "name": "method-id"}],
"name": "close",
"synchronous" : true},
{"id": 41,
"arguments": [],
"name": "close-ok"}],
"name": "channel"
},
{
"id": 30,
"methods": [{"id": 10,
"arguments": [{"type": "shortstr", "name": "realm", "default-value": "/data"},
{"type": "bit", "name": "exclusive", "default-value": false},
{"type": "bit", "name": "passive", "default-value": true},
{"type": "bit", "name": "active", "default-value": true},
{"type": "bit", "name": "write", "default-value": true},
{"type": "bit", "name": "read", "default-value": true}],
"name": "request",
"synchronous" : true},
{"id": 11,
"arguments": [{"type": "short", "name": "ticket", "default-value": 1}],
"name": "request-ok"}],
"name": "access"
},
{
"id": 40,
"methods": [{"id": 10,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "exchange-name", "name": "exchange"},
{"type": "shortstr", "name": "type", "default-value": "direct"},
{"type": "bit", "name": "passive", "default-value": false},
{"type": "bit", "name": "durable", "default-value": false},
{"type": "bit", "name": "auto-delete", "default-value": false},
{"type": "bit", "name": "internal", "default-value": false},
{"type": "bit", "name": "nowait", "default-value": false},
{"type": "table", "name": "arguments", "default-value": {}}],
"name": "declare",
"synchronous" : true},
{"id": 11,
"arguments": [],
"name": "declare-ok"},
{"id": 20,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "exchange-name", "name": "exchange"},
{"type": "bit", "name": "if-unused", "default-value": false},
{"type": "bit", "name": "nowait", "default-value": false}],
"name": "delete",
"synchronous" : true},
{"id": 21,
"arguments": [],
"name": "delete-ok"},
{"id": 30,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "exchange-name", "name": "destination"},
{"domain": "exchange-name", "name": "source"},
{"type": "shortstr", "name": "routing-key", "default-value": ""},
{"type": "bit", "name": "nowait", "default-value": false},
{"type": "table", "name": "arguments", "default-value": {}}],
"name": "bind",
"synchronous" : true},
{"id": 31,
"arguments": [],
"name": "bind-ok"},
{"id": 40,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "exchange-name", "name": "destination"},
{"domain": "exchange-name", "name": "source"},
{"type": "shortstr", "name": "routing-key", "default-value": ""},
{"type": "bit", "name": "nowait", "default-value": false},
{"type": "table", "name": "arguments", "default-value": {}}],
"name": "unbind",
"synchronous" : true},
{"id": 51,
"arguments": [],
"name": "unbind-ok"}],
"name": "exchange"
},
{
"id": 50,
"methods": [{"id": 10,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "queue-name", "name": "queue", "default-value": ""},
{"type": "bit", "name": "passive", "default-value": false},
{"type": "bit", "name": "durable", "default-value": false},
{"type": "bit", "name": "exclusive", "default-value": false},
{"type": "bit", "name": "auto-delete", "default-value": false},
{"type": "bit", "name": "nowait", "default-value": false},
{"type": "table", "name": "arguments", "default-value": {}}],
"name": "declare",
"synchronous" : true},
{"id": 11,
"arguments": [{"domain": "queue-name", "name": "queue"},
{"domain": "message-count", "name": "message-count"},
{"type": "long", "name": "consumer-count"}],
"name": "declare-ok"},
{"id": 20,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "queue-name", "name": "queue", "default-value": ""},
{"domain": "exchange-name", "name": "exchange"},
{"type": "shortstr", "name": "routing-key", "default-value": ""},
{"type": "bit", "name": "nowait", "default-value": false},
{"type": "table", "name": "arguments", "default-value": {}}],
"name": "bind",
"synchronous" : true},
{"id": 21,
"arguments": [],
"name": "bind-ok"},
{"id": 30,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "queue-name", "name": "queue", "default-value": ""},
{"type": "bit", "name": "nowait", "default-value": false}],
"name": "purge",
"synchronous" : true},
{"id": 31,
"arguments": [{"domain": "message-count", "name": "message-count"}],
"name": "purge-ok"},
{"id": 40,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "queue-name", "name": "queue", "default-value": ""},
{"type": "bit", "name": "if-unused", "default-value": false},
{"type": "bit", "name": "if-empty", "default-value": false},
{"type": "bit", "name": "nowait", "default-value": false}],
"name": "delete",
"synchronous" : true},
{"id": 41,
"arguments": [{"domain": "message-count", "name": "message-count"}],
"name": "delete-ok"},
{"id": 50,
"arguments": [{"type": "short", "name": "ticket", "default-value": 0},
{"domain": "queue-name", "name": "queue", "default-value": ""},
{"domain": "exchange-name", "name": "exchange"},
{"type": "shortstr", "name": "routing-key", "default-value": ""},
{"type": "table", "name": "arguments", "default-value": {}}],
"name": "unbind",
"synchronous" : true},
{"id": 51,
"arguments": [],
"name": "unbind-ok"}
],
"name": "queue"
},
{
"id": 90,
"methods": [{"id": 10,
"arguments": [],
"name": "select",
"synchronous" : true},
{"id": 11,
"arguments": [],
"name": "select-ok"},
{"id": 20,
"arguments": [],
"name": "commit",
"synchronous" : true},
{"id": 21,
"arguments": [],
"name": "commit-ok"},
{"id": 30,
"arguments": [],
"name": "rollback",
"synchronous" : true},
{"id": 31,
"arguments": [],
"name": "rollback-ok"}],
"name": "tx"
},
{
"id": 85,
"methods": [{"id": 10,
"arguments": [
{"type": "bit", "name": "nowait", "default-value": false}],
"name": "select",
"synchronous": true},
{"id": 11,
"arguments": [],
"name": "select-ok"}],
"name": "confirm"
}
]
}

722
node_modules/amqplib/bin/generate-defs.js generated vendored Normal file
View File

@@ -0,0 +1,722 @@
var FS = require('fs');
var format = require('util').format;
var defs = require('./amqp-rabbitmq-0.9.1.json');
var FRAME_OVERHEAD = 8; // type + channel + size + frame-end
var METHOD_OVERHEAD = FRAME_OVERHEAD + 4;
// F_O + classId + methodId
var PROPERTIES_OVERHEAD = FRAME_OVERHEAD + 4 + 8 + 2;
// F_O + classId + weight + content size + flags
var out = process.stdout;
function printf() {
out.write(format.apply(format, arguments), 'utf8');
}
function nl() { out.write('\n'); }
function println() { printf.apply(printf, arguments); nl(); }
function isEmptyObject(val) {
return (val != null && typeof val === 'object' &&
Object.keys(val).length === 0);
}
function stringifyValue(val) {
return (isEmptyObject(val)) ? 'EMPTY_OBJECT' :
JSON.stringify(val);
}
var constants = {};
var constant_strs = {};
for (var i = 0, len = defs.constants.length; i < len; i++) {
var cdef = defs.constants[i];
constants[constantName(cdef)] = cdef.value;
constant_strs[cdef.value] = cdef.name;
}
function constantName(def) {
return def.name.replace(/-/g, '_');
}
function methodName(clazz, method) {
return initial(clazz.name) + method.name.split('-').map(initial).join('');
}
function propertyName(dashed) {
var parts = dashed.split('-');
return parts[0] + parts.slice(1).map(initial).join('');
}
function initial(part) {
return part.charAt(0).toUpperCase() + part.substr(1);
}
function argument(a) {
var type = a.type || domains[a.domain];
var friendlyName = propertyName(a.name);
return {type: type, name: friendlyName, default: a['default-value']};
}
var domains = {};
for (var i=0, len = defs.domains.length; i < len; i++) {
var dom = defs.domains[i];
domains[dom[0]] = dom[1];
}
var methods = {};
var propertieses = {};
for (var i = 0, len = defs.classes.length; i < len; i++) {
var clazz = defs.classes[i];
for (var j = 0, num = clazz.methods.length; j < num; j++) {
var method = clazz.methods[j];
var name = methodName(clazz, method);
var info = 'methodInfo' + name;
methods[name] = {
id: methodId(clazz, method),
name: name,
methodId: method.id,
clazzId: clazz.id,
clazz: clazz.name,
args: method['arguments'].map(argument),
isReply: method.answer,
encoder: 'encode' + name,
decoder: 'decode' + name,
info: info
};
}
if (clazz.properties && clazz.properties.length > 0) {
var name = propertiesName(clazz);
var props = clazz.properties;
propertieses[name] = {
id: clazz.id,
name: name,
encoder: 'encode' + name,
decoder: 'decode' + name,
info: 'propertiesInfo' + name,
args: props.map(argument),
};
}
}
// OK let's get emitting
println(
'/** @preserve This file is generated by the script\n',
'* ../bin/generate-defs.js, which is not in general included in a\n',
'* distribution, but is available in the source repository e.g. at\n',
'* https://github.com/amqp-node/amqplib/\n',
'*/');
println("'use strict';"); nl();
nl()
println('var codec = require("./codec");');
println('var ints = require("buffer-more-ints");');
println('var encodeTable = codec.encodeTable;');
println('var decodeFields = codec.decodeFields;');
nl();
println('var SCRATCH = Buffer.alloc(65536);');
println('var EMPTY_OBJECT = Object.freeze({});');
println('module.exports.constants = %s',
JSON.stringify(constants));
nl();
println('module.exports.constant_strs = %s',
JSON.stringify(constant_strs));
nl();
println('module.exports.FRAME_OVERHEAD = %d;', FRAME_OVERHEAD);
nl();
println('module.exports.decode = function(id, buf) {');
println('switch (id) {');
for (var m in methods) {
var method = methods[m];
println('case %d: return %s(buf);', method.id, method.decoder);
}
for (var p in propertieses) {
var props = propertieses[p];
println('case %d: return %s(buf);', props.id, props.decoder);
}
println('default: throw new Error("Unknown class/method ID");');
println('}}'); nl();
println('module.exports.encodeMethod =',
'function(id, channel, fields) {');
println('switch (id) {');
for (var m in methods) {
var method = methods[m];
println('case %d: return %s(channel, fields);',
method.id, method.encoder);
}
println('default: throw new Error("Unknown class/method ID");');
println('}}'); nl();
println('module.exports.encodeProperties ='
, 'function(id, channel, size, fields) {');
println('switch (id) {');
for (var p in propertieses) {
var props = propertieses[p];
println('case %d: return %s(channel, size, fields);',
props.id, props.encoder);
}
println('default: throw new Error("Unknown class/properties ID");');
println('}}'); nl();
println('module.exports.info = function(id) {');
println('switch(id) {');
for (var m in methods) {
var method = methods[m];
println('case %d: return %s; ', method.id, method.info);
}
for (var p in propertieses) {
var properties = propertieses[p];
println('case %d: return %s', properties.id, properties.info);
}
println('default: throw new Error("Unknown class/method ID");');
println('}}'); nl();
for (var m in methods) {
var method = methods[m];
println('module.exports.%s = %d;', m, method.id);
decoderFn(method); nl();
encoderFn(method); nl();
infoObj(method); nl();
}
for (var p in propertieses) {
var properties = propertieses[p];
println('module.exports.%s = %d;', p, properties.id);
encodePropsFn(properties); nl();
decodePropsFn(properties); nl();
infoObj(properties); nl();
}
function methodId(clazz, method) {
return (clazz.id << 16) + method.id;
}
function propertiesName(clazz) {
return initial(clazz.name) + 'Properties';
}
function valTypeTest(arg) {
switch (arg.type) {
// everything is booleany
case 'bit': return 'true'
case 'octet':
case 'short':
case 'long':
case 'longlong':
case 'timestamp': return "typeof val === 'number' && !isNaN(val)";
case 'shortstr': return "typeof val === 'string' &&" +
" Buffer.byteLength(val) < 256";
case 'longstr': return "Buffer.isBuffer(val)";
case 'table': return "typeof val === 'object'";
}
}
function typeDesc(t) {
switch (t) {
case 'bit': return 'booleany';
case 'octet':
case 'short':
case 'long':
case 'longlong':
case 'timestamp': return "a number (but not NaN)";
case 'shortstr': return "a string (up to 255 chars)";
case 'longstr': return "a Buffer";
case 'table': return "an object";
}
}
function defaultValueRepr(arg) {
switch (arg.type) {
case 'longstr':
return format("Buffer.from(%s)", JSON.stringify(arg.default));
default:
// assumes no tables as defaults
return JSON.stringify(arg.default);
}
}
// Emit code to assign the arg value to `val`.
function assignArg(a) {
println("val = fields['%s'];", a.name);
}
function assignOrDefault(a) {
println("val = fields['%s'];", a.name);
println("if (val === undefined) val = %s;", defaultValueRepr(a));
}
// Emit code for assigning an argument value to `val`, checking that
// it exists (if it does not have a default) and is the correct
// type.
function checkAssignArg(a) {
assignArg(a);
println('if (val === undefined) {');
if (a.default !== undefined) {
println('val = %s;', defaultValueRepr(a));
}
else {
println('throw new Error("Missing value for mandatory field \'%s\'");', a.name);
}
println('}'); // undefined test
println('else if (!(%s)) {', valTypeTest(a));
println('throw new TypeError(');
println('"Field \'%s\' is the wrong type; must be %s");',
a.name, typeDesc(a.type));
println('}'); // type test
}
// Emit code for encoding `val` as a table and assign to a fresh
// variable (based on the arg name). I use a scratch buffer to compose
// the encoded table, otherwise I'd have to do a size calculation pass
// first. I can get away with this only because 1. the encoding
// procedures are not re-entrant; and, 2. I copy the result into
// another buffer before returning. `scratchOffset`, `val`, `len` are
// expected to have been declared.
function assignTable(a) {
var varname = tableVar(a);
println(
"len = encodeTable(SCRATCH, val, scratchOffset);");
println('var %s = SCRATCH.slice(scratchOffset, scratchOffset + len);', varname);
println('scratchOffset += len;');
}
function tableVar(a) {
return a.name + '_encoded';
}
function stringLenVar(a) {
return a.name + '_len';
}
function assignStringLen(a) {
var v = stringLenVar(a);
// Assumes the value or default is in val
println("var %s = Buffer.byteLength(val, 'utf8');", v);
}
function encoderFn(method) {
var args = method['args'];
println('function %s(channel, fields) {', method.encoder);
println('var offset = 0, val = null, bits = 0, varyingSize = 0;');
println('var len, scratchOffset = 0;');
// Encoding is split into two parts. Some fields have a fixed size
// (e.g., integers of a specific width), while some have a size that
// depends on the datum (e.g., strings). Each field will therefore
// either 1. contribute to the fixed size; or 2. emit code to
// calculate the size (and possibly the encoded value, in the case
// of tables).
var fixedSize = METHOD_OVERHEAD;
var bitsInARow = 0;
for (var i=0, len = args.length; i < len; i++) {
var arg = args[i];
if (arg.type != 'bit') bitsInARow = 0;
switch (arg.type) {
// varying size
case 'shortstr':
checkAssignArg(arg);
assignStringLen(arg);
println("varyingSize += %s;", stringLenVar(arg));
fixedSize += 1;
break;
case 'longstr':
checkAssignArg(arg);
println("varyingSize += val.length;");
fixedSize += 4;
break;
case 'table':
// For a table we have to encode the table before we can see its
// length.
checkAssignArg(arg);
assignTable(arg);
println('varyingSize += %s.length;', tableVar(arg));
break;
// fixed size
case 'octet': fixedSize += 1; break;
case 'short': fixedSize += 2; break;
case 'long': fixedSize += 4; break;
case 'longlong': //fall through
case 'timestamp':
fixedSize += 8; break;
case 'bit':
bitsInARow ++;
// open a fresh pack o' bits
if (bitsInARow === 1) fixedSize += 1;
// just used a pack; reset
else if (bitsInARow === 8) bitsInARow = 0;
break;
}
}
println('var buffer = Buffer.alloc(%d + varyingSize);', fixedSize);
println('buffer[0] = %d;', constants.FRAME_METHOD);
println('buffer.writeUInt16BE(channel, 1);');
// skip size for now, we'll write it in when we know
println('buffer.writeUInt32BE(%d, 7);', method.id);
println('offset = 11;');
bitsInARow = 0;
for (var i = 0, len = args.length; i < len; i++) {
var a = args[i];
// Flush any collected bits before doing a new field
if (a.type != 'bit' && bitsInARow > 0) {
bitsInARow = 0;
println('buffer[offset] = bits; offset++; bits = 0;');
}
switch (a.type) {
case 'octet':
checkAssignArg(a);
println('buffer.writeUInt8(val, offset); offset++;');
break;
case 'short':
checkAssignArg(a);
println('buffer.writeUInt16BE(val, offset); offset += 2;');
break;
case 'long':
checkAssignArg(a);
println('buffer.writeUInt32BE(val, offset); offset += 4;');
break;
case 'longlong':
case 'timestamp':
checkAssignArg(a);
println('ints.writeUInt64BE(buffer, val, offset); offset += 8;');
break;
case 'bit':
checkAssignArg(a);
println('if (val) bits += %d;', 1 << bitsInARow);
if (bitsInARow === 7) { // I don't think this ever happens, but whatever
println('buffer[offset] = bits; offset++; bits = 0;');
bitsInARow = 0;
}
else bitsInARow++;
break;
case 'shortstr':
assignOrDefault(a);
println('buffer[offset] = %s; offset++;', stringLenVar(a));
println('buffer.write(val, offset, "utf8"); offset += %s;',
stringLenVar(a));
break;
case 'longstr':
assignOrDefault(a);
println('len = val.length;');
println('buffer.writeUInt32BE(len, offset); offset += 4;');
println('val.copy(buffer, offset); offset += len;');
break;
case 'table':
println('offset += %s.copy(buffer, offset);', tableVar(a));
break;
default: throw new Error("Unexpected argument type: " + a.type);
}
}
// Flush any collected bits at the end
if (bitsInARow > 0) {
println('buffer[offset] = bits; offset++;');
}
println('buffer[offset] = %d;', constants.FRAME_END);
// size does not include the frame header or frame end byte
println('buffer.writeUInt32BE(offset - 7, 3);');
println('return buffer;');
println('}');
}
function fieldsDecl(args) {
println('var fields = {');
for (var i=0, num=args.length; i < num; i++) {
println('%s: undefined,', args[i].name);
}
println('};');
}
function decoderFn(method) {
var args = method.args;
println('function %s(buffer) {', method.decoder);
println('var offset = 0, val, len;');
fieldsDecl(args);
var bitsInARow = 0;
for (var i=0, num=args.length; i < num; i++) {
var a = args[i];
var field = "fields['" + a.name + "']";
// Flush any collected bits before doing a new field
if (a.type != 'bit' && bitsInARow > 0) {
bitsInARow = 0;
println('offset++;');
}
switch (a.type) {
case 'octet':
println('val = buffer[offset]; offset++;');
break;
case 'short':
println('val = buffer.readUInt16BE(offset); offset += 2;');
break;
case 'long':
println('val = buffer.readUInt32BE(offset); offset += 4;');
break;
case 'longlong':
case 'timestamp':
println('val = ints.readUInt64BE(buffer, offset); offset += 8;');
break;
case 'bit':
var bit = 1 << bitsInARow;
println('val = !!(buffer[offset] & %d);', bit);
if (bitsInARow === 7) {
println('offset++;');
bitsInARow = 0;
}
else bitsInARow++;
break;
case 'longstr':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = buffer.subarray(offset, offset + len);');
println('offset += len;');
break;
case 'shortstr':
println('len = buffer.readUInt8(offset); offset++;');
println('val = buffer.toString("utf8", offset, offset + len);');
println('offset += len;');
break;
case 'table':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = decodeFields(buffer.subarray(offset, offset + len));');
println('offset += len;');
break;
default:
throw new TypeError("Unexpected type in argument list: " + a.type);
}
println('%s = val;', field);
}
println('return fields;');
println('}');
}
function infoObj(thing) {
var info = JSON.stringify({id: thing.id,
classId: thing.clazzId,
methodId: thing.methodId,
name: thing.name,
args: thing.args});
println('var %s = module.exports.%s = %s;',
thing.info, thing.info, info);
}
// The flags are laid out in groups of fifteen in a short (high to
// low bits), with a continuation bit (at 0) and another group
// following if there's more than fifteen. Presence and absence
// are conflated with true and false, for bit fields (i.e., if the
// flag for the field is set, it's true, otherwise false).
//
// However, none of that is actually used in AMQP 0-9-1. The only
// instance of properties -- basic properties -- has 14 fields, none
// of them bits.
function flagAt(index) {
return 1 << (15 - index);
}
function encodePropsFn(props) {
println('function %s(channel, size, fields) {', props.encoder);
println('var offset = 0, flags = 0, val, len;');
println('var scratchOffset = 0, varyingSize = 0;');
var fixedSize = PROPERTIES_OVERHEAD;
var args = props.args;
function incVarying(by) {
println("varyingSize += %d;", by);
}
for (var i=0, num=args.length; i < num; i++) {
var p = args[i];
assignArg(p);
println("if (val != undefined) {");
println("if (%s) {", valTypeTest(p));
switch (p.type) {
case 'shortstr':
assignStringLen(p);
incVarying(1);
println('varyingSize += %s;', stringLenVar(p));
break;
case 'longstr':
incVarying(4);
println('varyingSize += val.length;');
break;
case 'table':
assignTable(p);
println('varyingSize += %s.length;', tableVar(p));
break;
case 'octet': incVarying(1); break;
case 'short': incVarying(2); break;
case 'long': incVarying(4); break;
case 'longlong': // fall through
case 'timestamp':
incVarying(8); break;
// no case for bit, as they are accounted for in the flags
}
println('} else {');
println('throw new TypeError(');
println('"Field \'%s\' is the wrong type; must be %s");',
p.name, typeDesc(p.type));
println('}');
println('}');
}
println('var buffer = Buffer.alloc(%d + varyingSize);', fixedSize);
println('buffer[0] = %d', constants.FRAME_HEADER);
println('buffer.writeUInt16BE(channel, 1);');
// content class ID and 'weight' (== 0)
println('buffer.writeUInt32BE(%d, 7);', props.id << 16);
// skip frame size for now, we'll write it in when we know.
// body size
println('ints.writeUInt64BE(buffer, size, 11);');
println('flags = 0;');
// we'll write the flags later too
println('offset = 21;');
for (var i=0, num=args.length; i < num; i++) {
var p = args[i];
var flag = flagAt(i);
assignArg(p);
println("if (val != undefined) {");
if (p.type === 'bit') { // which none of them are ..
println('if (val) flags += %d;', flag);
}
else {
println('flags += %d;', flag);
// %%% FIXME only slightly different to the method args encoding
switch (p.type) {
case 'octet':
println('buffer.writeUInt8(val, offset); offset++;');
break;
case 'short':
println('buffer.writeUInt16BE(val, offset); offset += 2;');
break;
case 'long':
println('buffer.writeUInt32BE(val, offset); offset += 4;');
break;
case 'longlong':
case 'timestamp':
println('ints.writeUInt64BE(buffer, val, offset);');
println('offset += 8;');
break;
case 'shortstr':
var v = stringLenVar(p);
println('buffer[offset] = %s; offset++;', v);
println("buffer.write(val, offset, 'utf8');");
println("offset += %s;", v);
break;
case 'longstr':
println('buffer.writeUInt32BE(val.length, offset);');
println('offset += 4;');
println('offset += val.copy(buffer, offset);');
break;
case 'table':
println('offset += %s.copy(buffer, offset);', tableVar(p));
break;
default: throw new Error("Unexpected argument type: " + p.type);
}
}
println('}'); // != undefined
}
println('buffer[offset] = %d;', constants.FRAME_END);
// size does not include the frame header or frame end byte
println('buffer.writeUInt32BE(offset - 7, 3);');
println('buffer.writeUInt16BE(flags, 19);');
println('return buffer.subarray(0, offset + 1);');
println('}');
}
function decodePropsFn(props) {
var args = props.args;
println('function %s(buffer) {', props.decoder);
println('var flags, offset = 2, val, len;');
println('flags = buffer.readUInt16BE(0);');
println('if (flags === 0) return {};');
fieldsDecl(args);
for (var i=0, num=args.length; i < num; i++) {
var p = argument(args[i]);
var field = "fields['" + p.name + "']";
println('if (flags & %d) {', flagAt(i));
if (p.type === 'bit') {
println('%d = true;', field);
}
else {
switch (p.type) {
case 'octet':
println('val = buffer[offset]; offset++;');
break;
case 'short':
println('val = buffer.readUInt16BE(offset); offset += 2;');
break;
case 'long':
println('val = buffer.readUInt32BE(offset); offset += 4;');
break;
case 'longlong':
case 'timestamp':
println('val = ints.readUInt64BE(buffer, offset); offset += 8;');
break;
case 'longstr':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = buffer.subarray(offset, offset + len);');
println('offset += len;');
break;
case 'shortstr':
println('len = buffer.readUInt8(offset); offset++;');
println('val = buffer.toString("utf8", offset, offset + len);');
println('offset += len;');
break;
case 'table':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = decodeFields(buffer.subarray(offset, offset + len));');
println('offset += len;');
break;
default:
throw new TypeError("Unexpected type in argument list: " + p.type);
}
println('%s = val;', field);
}
println('}');
}
println('return fields;');
println('}');
}