@cloudamqp/amqp-client
Version:
AMQP 0-9-1 client, both for browsers (WebSocket) and node (TCP Socket)
166 lines • 7.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Writer = exports.ConfirmMethod = exports.TxMethod = exports.BasicMethod = exports.QueueMethod = exports.ExchangeMethod = exports.ChannelMethod = exports.ConnectionMethod = exports.ClassId = exports.End = exports.Type = void 0;
const amqp_view_js_1 = require("./amqp-view.js");
var Type;
(function (Type) {
Type[Type["METHOD"] = 1] = "METHOD";
Type[Type["HEADER"] = 2] = "HEADER";
Type[Type["BODY"] = 3] = "BODY";
Type[Type["HEARTBEAT"] = 8] = "HEARTBEAT";
})(Type || (exports.Type = Type = {}));
var End;
(function (End) {
End[End["CODE"] = 206] = "CODE";
})(End || (exports.End = End = {}));
var ClassId;
(function (ClassId) {
ClassId[ClassId["CONNECTION"] = 10] = "CONNECTION";
ClassId[ClassId["CHANNEL"] = 20] = "CHANNEL";
ClassId[ClassId["EXCHANGE"] = 40] = "EXCHANGE";
ClassId[ClassId["QUEUE"] = 50] = "QUEUE";
ClassId[ClassId["BASIC"] = 60] = "BASIC";
ClassId[ClassId["TX"] = 90] = "TX";
ClassId[ClassId["CONFIRM"] = 85] = "CONFIRM";
})(ClassId || (exports.ClassId = ClassId = {}));
var ConnectionMethod;
(function (ConnectionMethod) {
ConnectionMethod[ConnectionMethod["START"] = 10] = "START";
ConnectionMethod[ConnectionMethod["START_OK"] = 11] = "START_OK";
ConnectionMethod[ConnectionMethod["SECURE"] = 20] = "SECURE";
ConnectionMethod[ConnectionMethod["SECURE_OK"] = 21] = "SECURE_OK";
ConnectionMethod[ConnectionMethod["TUNE"] = 30] = "TUNE";
ConnectionMethod[ConnectionMethod["TUNE_OK"] = 31] = "TUNE_OK";
ConnectionMethod[ConnectionMethod["OPEN"] = 40] = "OPEN";
ConnectionMethod[ConnectionMethod["OPEN_OK"] = 41] = "OPEN_OK";
ConnectionMethod[ConnectionMethod["CLOSE"] = 50] = "CLOSE";
ConnectionMethod[ConnectionMethod["CLOSE_OK"] = 51] = "CLOSE_OK";
ConnectionMethod[ConnectionMethod["BLOCKED"] = 60] = "BLOCKED";
ConnectionMethod[ConnectionMethod["UNBLOCKED"] = 61] = "UNBLOCKED";
ConnectionMethod[ConnectionMethod["UPDATE_SECRET"] = 70] = "UPDATE_SECRET";
ConnectionMethod[ConnectionMethod["UPDATE_SECRET_OK"] = 71] = "UPDATE_SECRET_OK";
})(ConnectionMethod || (exports.ConnectionMethod = ConnectionMethod = {}));
var ChannelMethod;
(function (ChannelMethod) {
ChannelMethod[ChannelMethod["OPEN"] = 10] = "OPEN";
ChannelMethod[ChannelMethod["OPEN_OK"] = 11] = "OPEN_OK";
ChannelMethod[ChannelMethod["FLOW"] = 20] = "FLOW";
ChannelMethod[ChannelMethod["FLOW_OK"] = 21] = "FLOW_OK";
ChannelMethod[ChannelMethod["CLOSE"] = 40] = "CLOSE";
ChannelMethod[ChannelMethod["CLOSE_OK"] = 41] = "CLOSE_OK";
})(ChannelMethod || (exports.ChannelMethod = ChannelMethod = {}));
var ExchangeMethod;
(function (ExchangeMethod) {
ExchangeMethod[ExchangeMethod["DECLARE"] = 10] = "DECLARE";
ExchangeMethod[ExchangeMethod["DECLARE_OK"] = 11] = "DECLARE_OK";
ExchangeMethod[ExchangeMethod["DELETE"] = 20] = "DELETE";
ExchangeMethod[ExchangeMethod["DELETE_OK"] = 21] = "DELETE_OK";
ExchangeMethod[ExchangeMethod["BIND"] = 30] = "BIND";
ExchangeMethod[ExchangeMethod["BIND_OK"] = 31] = "BIND_OK";
ExchangeMethod[ExchangeMethod["UNBIND"] = 40] = "UNBIND";
ExchangeMethod[ExchangeMethod["UNBIND_OK"] = 51] = "UNBIND_OK";
})(ExchangeMethod || (exports.ExchangeMethod = ExchangeMethod = {}));
var QueueMethod;
(function (QueueMethod) {
QueueMethod[QueueMethod["DECLARE"] = 10] = "DECLARE";
QueueMethod[QueueMethod["DECLARE_OK"] = 11] = "DECLARE_OK";
QueueMethod[QueueMethod["BIND"] = 20] = "BIND";
QueueMethod[QueueMethod["BIND_OK"] = 21] = "BIND_OK";
QueueMethod[QueueMethod["PURGE"] = 30] = "PURGE";
QueueMethod[QueueMethod["PURGE_OK"] = 31] = "PURGE_OK";
QueueMethod[QueueMethod["DELETE"] = 40] = "DELETE";
QueueMethod[QueueMethod["DELETE_OK"] = 41] = "DELETE_OK";
QueueMethod[QueueMethod["UNBIND"] = 50] = "UNBIND";
QueueMethod[QueueMethod["UNBIND_OK"] = 51] = "UNBIND_OK";
})(QueueMethod || (exports.QueueMethod = QueueMethod = {}));
var BasicMethod;
(function (BasicMethod) {
BasicMethod[BasicMethod["QOS"] = 10] = "QOS";
BasicMethod[BasicMethod["QOS_OK"] = 11] = "QOS_OK";
BasicMethod[BasicMethod["CONSUME"] = 20] = "CONSUME";
BasicMethod[BasicMethod["CONSUME_OK"] = 21] = "CONSUME_OK";
BasicMethod[BasicMethod["CANCEL"] = 30] = "CANCEL";
BasicMethod[BasicMethod["CANCEL_OK"] = 31] = "CANCEL_OK";
BasicMethod[BasicMethod["PUBLISH"] = 40] = "PUBLISH";
BasicMethod[BasicMethod["RETURN"] = 50] = "RETURN";
BasicMethod[BasicMethod["DELIVER"] = 60] = "DELIVER";
BasicMethod[BasicMethod["GET"] = 70] = "GET";
BasicMethod[BasicMethod["GET_OK"] = 71] = "GET_OK";
BasicMethod[BasicMethod["GET_EMPTY"] = 72] = "GET_EMPTY";
BasicMethod[BasicMethod["ACK"] = 80] = "ACK";
BasicMethod[BasicMethod["REJECT"] = 90] = "REJECT";
BasicMethod[BasicMethod["RECOVER_ASYNC"] = 100] = "RECOVER_ASYNC";
BasicMethod[BasicMethod["RECOVER"] = 110] = "RECOVER";
BasicMethod[BasicMethod["RECOVER_OK"] = 111] = "RECOVER_OK";
BasicMethod[BasicMethod["NACK"] = 120] = "NACK";
})(BasicMethod || (exports.BasicMethod = BasicMethod = {}));
var TxMethod;
(function (TxMethod) {
TxMethod[TxMethod["SELECT"] = 10] = "SELECT";
TxMethod[TxMethod["SELECT_OK"] = 11] = "SELECT_OK";
TxMethod[TxMethod["COMMIT"] = 20] = "COMMIT";
TxMethod[TxMethod["COMMIT_OK"] = 21] = "COMMIT_OK";
TxMethod[TxMethod["ROLLBACK"] = 30] = "ROLLBACK";
TxMethod[TxMethod["ROLLBACK_OK"] = 31] = "ROLLBACK_OK";
})(TxMethod || (exports.TxMethod = TxMethod = {}));
var ConfirmMethod;
(function (ConfirmMethod) {
ConfirmMethod[ConfirmMethod["SELECT"] = 10] = "SELECT";
ConfirmMethod[ConfirmMethod["SELECT_OK"] = 11] = "SELECT_OK";
})(ConfirmMethod || (exports.ConfirmMethod = ConfirmMethod = {}));
class Writer {
constructor(options) {
this.view = new amqp_view_js_1.AMQPView(new ArrayBuffer(options.bufferSize));
this.offset = 0;
this.writeUint8(options.type);
this.writeUint16(options.channel);
this.writeUint32(options.frameSize ?? 0);
this.writeUint16(options.classId);
this.writeUint16(options.method);
}
finalize() {
const currentFrameSize = this.view.getUint32(3);
if (currentFrameSize === 0) {
const value = this.offset - 7;
this.view.setUint32(3, value);
}
this.view.setUint8(this.offset, End.CODE);
this.offset += 1;
}
getBuffer() {
return this.view.buffer;
}
toUint8Array() {
return new Uint8Array(this.view.buffer, 0, this.offset);
}
writeUint8(value) {
this.view.setUint8(this.offset, value);
this.offset += 1;
}
writeUint16(value) {
this.view.setUint16(this.offset, value);
this.offset += 2;
}
writeUint32(value) {
this.view.setUint32(this.offset, value);
this.offset += 4;
}
writeUint64(value) {
this.view.setUint64(this.offset, value);
this.offset += 8;
}
writeShortString(value) {
const bytesWritten = this.view.setShortString(this.offset, value);
this.offset += bytesWritten;
}
writeLongString(value) {
const bytesWritten = this.view.setLongString(this.offset, value);
this.offset += bytesWritten;
}
writeTable(table) {
const bytesWritten = this.view.setTable(this.offset, table);
this.offset += bytesWritten;
}
}
exports.Writer = Writer;
//# sourceMappingURL=amqp-frame.js.map