Use shared code from rabbitmq-amqp1.0-common

This commit is contained in:
Jean-Sébastien Pédron 2017-01-11 16:07:14 +01:00
parent b5ea0fbcf2
commit 5fc5abcc07
20 changed files with 15 additions and 1306 deletions

View File

@ -2,21 +2,12 @@ PROJECT = amqp10_client
PROJECT_DESCRIPTION = AMQP 1.0 client from the RabbitMQ Project
PROJECT_MOD = amqp10_client_app
define PROJECT_APP_EXTRA_KEYS
{broker_version_requirements, []}
endef
BUILD_DEPS = rabbitmq_codegen rabbit_common
BUILD_DEPS = rabbit_common
DEPS = amqp10_common
TEST_DEPS = rabbit rabbitmq_amqp1_0 rabbitmq_ct_helpers
DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk
EXTRA_SOURCES += include/rabbit_amqp1_0_framing.hrl \
src/rabbit_amqp1_0_framing0.erl
.DEFAULT_GOAL = all
$(PROJECT).d:: $(EXTRA_SOURCES)
# FIXME: Use erlang.mk patched for RabbitMQ, while waiting for PRs to be
# reviewed and merged.
@ -26,32 +17,6 @@ ERLANG_MK_COMMIT = rabbitmq-tmp
include rabbitmq-components.mk
include erlang.mk
# --------------------------------------------------------------------
# Framing sources generation.
# --------------------------------------------------------------------
PYTHON ?= python
CODEGEN = $(CURDIR)/codegen.py
CODEGEN_DIR ?= $(DEPS_DIR)/rabbitmq_codegen
CODEGEN_AMQP = $(CODEGEN_DIR)/amqp_codegen.py
CODEGEN_SPECS = spec/messaging.xml spec/security.xml spec/transport.xml \
spec/transactions.xml
include/rabbit_amqp1_0_framing.hrl:: $(CODEGEN) $(CODEGEN_AMQP) \
$(CODEGEN_SPECS)
$(gen_verbose) env PYTHONPATH=$(CODEGEN_DIR) \
$(PYTHON) $(CODEGEN) hrl $(CODEGEN_SPECS) > $@
src/rabbit_amqp1_0_framing0.erl:: $(CODEGEN) $(CODEGEN_AMQP) \
$(CODEGEN_SPECS)
$(gen_verbose) env PYTHONPATH=$(CODEGEN_DIR) \
$(PYTHON) $(CODEGEN) erl $(CODEGEN_SPECS) > $@
clean:: clean-extra-sources
clean-extra-sources:
$(gen_verbose) rm -f $(EXTRA_SOURCES)
# --------------------------------------------------------------------
# ActiveMQ for the testsuite.
# --------------------------------------------------------------------

View File

@ -1,126 +0,0 @@
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import re
from xml.dom.minidom import parse
def safe(str):
return str.replace('-', '_')
class AMQPType:
def __init__(self, dom):
self.name = safe(dom.getAttribute('name'))
self.source = dom.getAttribute('source')
self.desc = dom.getElementsByTagName('descriptor')[0].getAttribute('name')
self.code = dom.getElementsByTagName('descriptor')[0].getAttribute('code')
self.number = parse_code(self.code)
self.fields = [safe(el.getAttribute('name')) for el in
dom.getElementsByTagName('field')]
# These are 'restricted' types, rather than composite, so they
# do not have defined fields.
if self.desc in ['amqp:data:binary', 'amqp:amqp-sequence:list',
'amqp:amqp-value:*', 'amqp:application-properties:map',
'amqp:delivery-annotations:map',
'amqp:message-annotations:map', 'amqp:footer:map']:
self.fields = ['content']
def define(self):
return ('SYMBOL_%s' % self.name.upper(), self.desc)
class AMQPDefines:
def __init__(self, dom):
self.name = safe(dom.getAttribute('name'))
self.source = dom.getAttribute('source')
self.options = [(self.name.upper() + '_' +
(safe(el.getAttribute('name')).upper()),
el.getAttribute('value')) for el in
dom.getElementsByTagName('choice')]
def print_erl(types):
print("""-module(rabbit_amqp1_0_framing0).
-export([record_for/1, fields/1, encode/1, symbol_for/1, number_for/1]).
-include("rabbit_amqp1_0.hrl").""")
for t in types:
print("""record_for({symbol, <<"%s">>}) ->
#'v1_0.%s'{};""" % (t.desc, t.name))
if t.code:
print("""record_for({_, %d}) ->
#'v1_0.%s'{};""" % (t.number, t.name))
print("%% %s\n" % t.code)
print("""record_for(Other) -> exit({unknown, Other}).
""")
for t in types:
print("""fields(#'v1_0.%s'{}) -> record_info(fields, 'v1_0.%s');""" % (t.name, t.name))
print("""fields(_Other) -> unknown.
""")
for t in types:
print("""encode(Frame = #'v1_0.%s'{}) ->
rabbit_amqp1_0_framing:encode_described('%s', %s, Frame);""" % (t.name, t.source, t.number))
print("""encode(undefined) -> null;
encode(Other) -> Other.
""")
for t in types:
print("""symbol_for(#'v1_0.%s'{}) ->
{symbol, <<"%s">>};""" % (t.name, t.desc))
print("""symbol_for(Other) -> exit({unknown, Other}).
""")
for t in types:
print("""number_for(#'v1_0.%s'{}) ->
{ulong, %s};""" % (t.name, t.number))
print("""number_for(Other) -> exit({unknown, Other}).""")
def print_hrl(types, defines):
for t in types:
print("""-record('v1_0.%s', {%s}).""" % (t.name, ", ".join(t.fields)))
print_define(t.define(), 'symbol')
for d in defines:
if len(d.options) > 0:
print(""" %% %s""" % (d.name))
for opt in d.options:
print_define(opt, d.source)
def print_define(opt, source):
(name, value) = opt
if source == 'symbol':
quoted = '<<"%s">>' % value
else:
quoted = value
print("""-define(V_1_0_%s, {%s, %s}).""" % (name, source, quoted))
def want_type(el):
descriptors = el.getElementsByTagName('descriptor')
return len(descriptors) > 0
def want_define(el):
klass = el.getAttribute('class')
return klass == 'restricted'
def parse_code(code):
res = re.match('0x([0-9a-fA-F]{8,8}):0x([0-9a-fA-F]{8,8})', code)
return res and int(res.group(1) + res.group(2), 16)
types = []
defines = []
mode = sys.argv[1]
for file in sys.argv[2:]:
tree = parse(file)
types.extend([AMQPType(el) for el in tree.getElementsByTagName('type')
if want_type(el)])
defines.extend([AMQPDefines(el) for el in tree.getElementsByTagName('type')
if want_define(el)])
if mode == 'erl':
print_erl(types)
elif mode == 'hrl':
print_hrl(types, defines)
else:
raise "Mode != erl or hrl"

View File

@ -1,55 +0,0 @@
%%-define(debug, true).
-ifdef(debug).
-define(DEBUG0(F), ?SAFE(io:format(F, []))).
-define(DEBUG(F, A), ?SAFE(io:format(F, A))).
-else.
-define(DEBUG0(F), ok).
-define(DEBUG(F, A), ok).
-endif.
-define(pprint(F), io:format("~p~n", [rabbit_amqp1_0_framing:pprint(F)])).
-define(SAFE(F),
((fun() ->
try F
catch __T:__E ->
io:format("~p:~p thrown debugging~n~p~n",
[__T, __E, erlang:get_stacktrace()])
end
end)())).
%% General consts
-define(FRAME_1_0_MIN_SIZE, 512).
-define(SEND_ROLE, false).
-define(RECV_ROLE, true).
%% Encoding
-define(DESCRIBED, 0:8).
-define(DESCRIBED_BIN, <<?DESCRIBED>>).
-include_lib("rabbit_amqp1_0_framing.hrl").
-define(INFO_ITEMS, [pid,
auth_mechanism,
host,
frame_max,
timeout,
user,
state,
recv_oct,
recv_cnt,
send_oct,
send_cnt,
ssl,
ssl_protocol,
ssl_key_exchange,
ssl_cipher,
ssl_hash,
peer_cert_issuer,
peer_cert_subject,
peer_cert_validity,
node]).

View File

@ -38,6 +38,7 @@ endif
# base of the topic branch.
dep_amqp_client = git_rmq rabbitmq-erlang-client $(current_rmq_ref) $(base_rmq_ref) master
dep_amqp10_common = git_rmq rabbitmq-amqp1.0-common $(current_rmq_ref) $(base_rmq_ref) master
dep_rabbit = git_rmq rabbitmq-server $(current_rmq_ref) $(base_rmq_ref) master
dep_rabbit_common = git_rmq rabbitmq-common $(current_rmq_ref) $(base_rmq_ref) master
dep_rabbitmq_amqp1_0 = git_rmq rabbitmq-amqp1.0 $(current_rmq_ref) $(base_rmq_ref) master
@ -106,6 +107,7 @@ dep_ranch_commit = 1.3.0
dep_webmachine_commit = 1.10.8p2
RABBITMQ_COMPONENTS = amqp_client \
amqp10_common \
rabbit \
rabbit_common \
rabbitmq_amqp1_0 \

View File

@ -1,168 +0,0 @@
<?xml version="1.0"?>
<!--
Copyright Bank of America, N.A., Barclays Bank PLC, Cisco Systems, Credit
Suisse, Deutsche Boerse, Envoy Technologies Inc., Goldman Sachs, HCL
Technologies Ltd, IIT Software GmbH, iMatix Corporation, INETCO Systems Limited,
Informatica Corporation, JPMorgan Chase & Co., Kaazing Corporation, N.A,
Microsoft Corporation, my-Channels, Novell, Progress Software, Red Hat Inc.,
Software AG, Solace Systems Inc., StormMQ Ltd., Tervela Inc., TWIST Process
Innovations Ltd, GoPivotal, Inc., and WS02 Inc. 2006-2011. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<amqp name="messaging" xmlns="http://www.amqp.org/schema/amqp.xsd">
<section name="message-format">
<type name="header" class="composite" source="list" provides="section">
<descriptor name="amqp:header:list" code="0x00000000:0x00000070"/>
<field name="durable" type="boolean"/>
<field name="priority" type="ubyte"/>
<field name="ttl" type="milliseconds"/>
<field name="first-acquirer" type="boolean"/>
<field name="delivery-count" type="uint"/>
</type>
<type name="delivery-annotations" class="restricted" source="annotations" provides="section">
<descriptor name="amqp:delivery-annotations:map" code="0x00000000:0x00000071"/>
</type>
<type name="message-annotations" class="restricted" source="annotations" provides="section">
<descriptor name="amqp:message-annotations:map" code="0x00000000:0x00000072"/>
</type>
<type name="properties" class="composite" source="list" provides="section">
<descriptor name="amqp:properties:list" code="0x00000000:0x00000073"/>
<field name="message-id" type="*" requires="message-id"/>
<field name="user-id" type="binary"/>
<field name="to" type="*" requires="address"/>
<field name="subject" type="string"/>
<field name="reply-to" type="*" requires="address"/>
<field name="correlation-id" type="*" requires="message-id"/>
<field name="content-type" type="symbol"/>
<field name="content-encoding" type="symbol"/>
<field name="absolute-expiry-time" type="timestamp"/>
<field name="creation-time" type="timestamp"/>
<field name="group-id" type="string"/>
<field name="group-sequence" type="sequence-no"/>
<field name="reply-to-group-id" type="string"/>
</type>
<type name="application-properties" class="restricted" source="map" provides="section">
<descriptor name="amqp:application-properties:map" code="0x00000000:0x00000074"/>
</type>
<type name="data" class="restricted" source="binary" provides="section">
<descriptor name="amqp:data:binary" code="0x00000000:0x00000075"/>
</type>
<type name="amqp-sequence" class="restricted" source="list" provides="section">
<descriptor name="amqp:amqp-sequence:list" code="0x00000000:0x00000076"/>
</type>
<type name="amqp-value" class="restricted" source="*" provides="section">
<descriptor name="amqp:amqp-value:*" code="0x00000000:0x00000077"/>
</type>
<type name="footer" class="restricted" source="annotations" provides="section">
<descriptor name="amqp:footer:map" code="0x00000000:0x00000078"/>
</type>
<type name="annotations" class="restricted" source="map"/>
<type name="message-id-ulong" class="restricted" source="ulong" provides="message-id"/>
<type name="message-id-uuid" class="restricted" source="uuid" provides="message-id"/>
<type name="message-id-binary" class="restricted" source="binary" provides="message-id"/>
<type name="message-id-string" class="restricted" source="string" provides="message-id"/>
<type name="address-string" class="restricted" source="string" provides="address"/>
<definition name="MESSAGE-FORMAT" value="0"/>
</section>
<section name="delivery-state">
<type name="received" class="composite" source="list" provides="delivery-state">
<descriptor name="amqp:received:list" code="0x00000000:0x00000023"/>
<field name="section-number" type="uint" mandatory="true"/>
<field name="section-offset" type="ulong" mandatory="true"/>
</type>
<type name="accepted" class="composite" source="list" provides="delivery-state, outcome">
<descriptor name="amqp:accepted:list" code="0x00000000:0x00000024"/>
</type>
<type name="rejected" class="composite" source="list" provides="delivery-state, outcome">
<descriptor name="amqp:rejected:list" code="0x00000000:0x00000025"/>
<field name="error" type="error"/>
</type>
<type name="released" class="composite" source="list" provides="delivery-state, outcome">
<descriptor name="amqp:released:list" code="0x00000000:0x00000026"/>
</type>
<type name="modified" class="composite" source="list" provides="delivery-state, outcome">
<descriptor name="amqp:modified:list" code="0x00000000:0x00000027"/>
<field name="delivery-failed" type="boolean"/>
<field name="undeliverable-here" type="boolean"/>
<field name="message-annotations" type="fields"/>
</type>
</section>
<section name="addressing">
<type name="source" class="composite" source="list" provides="source">
<descriptor name="amqp:source:list" code="0x00000000:0x00000028"/>
<field name="address" type="*" requires="address"/>
<field name="durable" type="terminus-durability" default="none"/>
<field name="expiry-policy" type="terminus-expiry-policy" default="session-end"/>
<field name="timeout" type="seconds" default="0"/>
<field name="dynamic" type="boolean" default="false"/>
<field name="dynamic-node-properties" type="node-properties"/>
<field name="distribution-mode" type="symbol" requires="distribution-mode"/>
<field name="filter" type="filter-set"/>
<field name="default-outcome" type="*" requires="outcome"/>
<field name="outcomes" type="symbol" multiple="true"/>
<field name="capabilities" type="symbol" multiple="true"/>
</type>
<type name="target" class="composite" source="list" provides="target">
<descriptor name="amqp:target:list" code="0x00000000:0x00000029"/>
<field name="address" type="*" requires="address"/>
<field name="durable" type="terminus-durability" default="none"/>
<field name="expiry-policy" type="terminus-expiry-policy" default="session-end"/>
<field name="timeout" type="seconds" default="0"/>
<field name="dynamic" type="boolean" default="false"/>
<field name="dynamic-node-properties" type="node-properties"/>
<field name="capabilities" type="symbol" multiple="true"/>
</type>
<type name="terminus-durability" class="restricted" source="uint">
<choice name="none" value="0"/>
<choice name="configuration" value="1"/>
<choice name="unsettled-state" value="2"/>
</type>
<type name="terminus-expiry-policy" class="restricted" source="symbol">
<choice name="link-detach" value="link-detach"/>
<choice name="session-end" value="session-end"/>
<choice name="connection-close" value="connection-close"/>
<choice name="never" value="never"/>
</type>
<type name="std-dist-mode" class="restricted" source="symbol" provides="distribution-mode">
<choice name="move" value="move"/>
<choice name="copy" value="copy"/>
</type>
<type name="filter-set" class="restricted" source="map"/>
<type name="node-properties" class="restricted" source="fields"/>
<type name="delete-on-close" class="composite" source="list" provides="lifetime-policy">
<descriptor name="amqp:delete-on-close:list" code="0x00000000:0x0000002b"/>
</type>
<type name="delete-on-no-links" class="composite" source="list" provides="lifetime-policy">
<descriptor name="amqp:delete-on-no-links:list" code="0x00000000:0x0000002c"/>
</type>
<type name="delete-on-no-messages" class="composite" source="list" provides="lifetime-policy">
<descriptor name="amqp:delete-on-no-messages:list" code="0x00000000:0x0000002d"/>
</type>
<type name="delete-on-no-links-or-messages" class="composite" source="list" provides="lifetime-policy">
<descriptor name="amqp:delete-on-no-links-or-messages:list" code="0x00000000:0x0000002e"/>
</type>
</section>
</amqp>

View File

@ -1,76 +0,0 @@
<?xml version="1.0"?>
<!--
Copyright Bank of America, N.A., Barclays Bank PLC, Cisco Systems, Credit
Suisse, Deutsche Boerse, Envoy Technologies Inc., Goldman Sachs, HCL
Technologies Ltd, IIT Software GmbH, iMatix Corporation, INETCO Systems Limited,
Informatica Corporation, JPMorgan Chase & Co., Kaazing Corporation, N.A,
Microsoft Corporation, my-Channels, Novell, Progress Software, Red Hat Inc.,
Software AG, Solace Systems Inc., StormMQ Ltd., Tervela Inc., TWIST Process
Innovations Ltd, GoPivotal, Inc., and WS02 Inc. 2006-2011. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<amqp name="security" xmlns="http://www.amqp.org/schema/amqp.xsd">
<section name="tls">
<definition name="TLS-MAJOR" value="1"/>
<definition name="TLS-MINOR" value="0"/>
<definition name="TLS-REVISION" value="0"/>
</section>
<section name="sasl">
<type name="sasl-mechanisms" class="composite" source="list" provides="sasl-frame">
<descriptor name="amqp:sasl-mechanisms:list" code="0x00000000:0x00000040"/>
<field name="sasl-server-mechanisms" type="symbol" mandatory="true" multiple="true"/>
</type>
<type name="sasl-init" class="composite" source="list" provides="sasl-frame">
<descriptor name="amqp:sasl-init:list" code="0x00000000:0x00000041"/>
<field name="mechanism" type="symbol" mandatory="true"/>
<field name="initial-response" type="binary"/>
<field name="hostname" type="string"/>
</type>
<type name="sasl-challenge" class="composite" source="list" provides="sasl-frame">
<descriptor name="amqp:sasl-challenge:list" code="0x00000000:0x00000042"/>
<field name="challenge" type="binary" mandatory="true"/>
</type>
<type name="sasl-response" class="composite" source="list" provides="sasl-frame">
<descriptor name="amqp:sasl-response:list" code="0x00000000:0x00000043"/>
<field name="response" type="binary" mandatory="true"/>
</type>
<type name="sasl-outcome" class="composite" source="list" provides="sasl-frame">
<descriptor name="amqp:sasl-outcome:list" code="0x00000000:0x00000044"/>
<field name="code" type="sasl-code" mandatory="true"/>
<field name="additional-data" type="binary"/>
</type>
<type name="sasl-code" class="restricted" source="ubyte">
<choice name="ok" value="0"/>
<choice name="auth" value="1"/>
<choice name="sys" value="2"/>
<choice name="sys-perm" value="3"/>
<choice name="sys-temp" value="4"/>
</type>
<definition name="SASL-MAJOR" value="1"/>
<definition name="SASL-MINOR" value="0"/>
<definition name="SASL-REVISION" value="0"/>
</section>
</amqp>

View File

@ -1,73 +0,0 @@
<?xml version="1.0"?>
<!--
Copyright Bank of America, N.A., Barclays Bank PLC, Cisco Systems, Credit
Suisse, Deutsche Boerse, Envoy Technologies Inc., Goldman Sachs, HCL
Technologies Ltd, IIT Software GmbH, iMatix Corporation, INETCO Systems Limited,
Informatica Corporation, JPMorgan Chase & Co., Kaazing Corporation, N.A,
Microsoft Corporation, my-Channels, Novell, Progress Software, Red Hat Inc.,
Software AG, Solace Systems Inc., StormMQ Ltd., Tervela Inc., TWIST Process
Innovations Ltd, GoPivotal, Inc., and WS02 Inc. 2006-2011. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<amqp name="transactions" xmlns="http://www.amqp.org/schema/amqp.xsd">
<section name="coordination">
<type name="coordinator" class="composite" source="list" provides="target">
<descriptor name="amqp:coordinator:list" code="0x00000000:0x00000030"/>
<field name="capabilities" type="symbol" requires="txn-capability" multiple="true"/>
</type>
<type name="declare" class="composite" source="list">
<descriptor name="amqp:declare:list" code="0x00000000:0x00000031"/>
<field name="global-id" type="*" requires="global-tx-id"/>
</type>
<type name="discharge" class="composite" source="list">
<descriptor name="amqp:discharge:list" code="0x00000000:0x00000032"/>
<field name="txn-id" type="*" mandatory="true" requires="txn-id"/>
<field name="fail" type="boolean"/>
</type>
<type name="transaction-id" class="restricted" source="binary" provides="txn-id"/>
<type name="declared" class="composite" source="list" provides="delivery-state, outcome">
<descriptor name="amqp:declared:list" code="0x00000000:0x00000033"/>
<field name="txn-id" type="*" mandatory="true" requires="txn-id"/>
</type>
<type name="transactional-state" class="composite" source="list" provides="delivery-state">
<descriptor name="amqp:transactional-state:list" code="0x00000000:0x00000034"/>
<field name="txn-id" type="*" mandatory="true" requires="txn-id"/>
<field name="outcome" type="*" requires="outcome"/>
</type>
<type name="txn-capability" class="restricted" source="symbol" provides="txn-capability">
<choice name="local-transactions" value="amqp:local-transactions"/>
<choice name="distributed-transactions" value="amqp:distributed-transactions"/>
<choice name="promotable-transactions" value="amqp:promotable-transactions"/>
<choice name="multi-txns-per-ssn" value="amqp:multi-txns-per-ssn"/>
<choice name="multi-ssns-per-txn" value="amqp:multi-ssns-per-txn"/>
</type>
<type name="transaction-error" class="restricted" source="symbol" provides="error-condition">
<choice name="unknown-id" value="amqp:transaction:unknown-id"/>
<choice name="transaction-rollback" value="amqp:transaction:rollback"/>
<choice name="transaction-timeout" value="amqp:transaction:timeout"/>
</type>
</section>
</amqp>

View File

@ -1,200 +0,0 @@
<?xml version="1.0"?>
<!--
Copyright Bank of America, N.A., Barclays Bank PLC, Cisco Systems, Credit
Suisse, Deutsche Boerse, Envoy Technologies Inc., Goldman Sachs, HCL
Technologies Ltd, IIT Software GmbH, iMatix Corporation, INETCO Systems Limited,
Informatica Corporation, JPMorgan Chase & Co., Kaazing Corporation, N.A,
Microsoft Corporation, my-Channels, Novell, Progress Software, Red Hat Inc.,
Software AG, Solace Systems Inc., StormMQ Ltd., Tervela Inc., TWIST Process
Innovations Ltd, GoPivotal, Inc., and WS02 Inc. 2006-2011. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<amqp name="transport" xmlns="http://www.amqp.org/schema/amqp.xsd">
<section name="performatives">
<type name="open" class="composite" source="list" provides="frame">
<descriptor name="amqp:open:list" code="0x00000000:0x00000010"/>
<field name="container-id" type="string" mandatory="true"/>
<field name="hostname" type="string"/>
<field name="max-frame-size" type="uint" default="4294967295"/>
<field name="channel-max" type="ushort" default="65535"/>
<field name="idle-time-out" type="milliseconds"/>
<field name="outgoing-locales" type="ietf-language-tag" multiple="true"/>
<field name="incoming-locales" type="ietf-language-tag" multiple="true"/>
<field name="offered-capabilities" type="symbol" multiple="true"/>
<field name="desired-capabilities" type="symbol" multiple="true"/>
<field name="properties" type="fields"/>
</type>
<type name="begin" class="composite" source="list" provides="frame">
<descriptor name="amqp:begin:list" code="0x00000000:0x00000011"/>
<field name="remote-channel" type="ushort"/>
<field name="next-outgoing-id" type="transfer-number" mandatory="true"/>
<field name="incoming-window" type="uint" mandatory="true"/>
<field name="outgoing-window" type="uint" mandatory="true"/>
<field name="handle-max" type="handle" default="4294967295"/>
<field name="offered-capabilities" type="symbol" multiple="true"/>
<field name="desired-capabilities" type="symbol" multiple="true"/>
<field name="properties" type="fields"/>
</type>
<type name="attach" class="composite" source="list" provides="frame">
<descriptor name="amqp:attach:list" code="0x00000000:0x00000012"/>
<field name="name" type="string" mandatory="true"/>
<field name="handle" type="handle" mandatory="true"/>
<field name="role" type="role" mandatory="true"/>
<field name="snd-settle-mode" type="sender-settle-mode" default="mixed"/>
<field name="rcv-settle-mode" type="receiver-settle-mode" default="first"/>
<field name="source" type="*" requires="source"/>
<field name="target" type="*" requires="target"/>
<field name="unsettled" type="map"/>
<field name="incomplete-unsettled" type="boolean" default="false"/>
<field name="initial-delivery-count" type="sequence-no"/>
<field name="max-message-size" type="ulong"/>
<field name="offered-capabilities" type="symbol" multiple="true"/>
<field name="desired-capabilities" type="symbol" multiple="true"/>
<field name="properties" type="fields"/>
</type>
<type name="flow" class="composite" source="list" provides="frame">
<descriptor name="amqp:flow:list" code="0x00000000:0x00000013"/>
<field name="next-incoming-id" type="transfer-number"/>
<field name="incoming-window" type="uint" mandatory="true"/>
<field name="next-outgoing-id" type="transfer-number" mandatory="true"/>
<field name="outgoing-window" type="uint" mandatory="true"/>
<field name="handle" type="handle"/>
<field name="delivery-count" type="sequence-no"/>
<field name="link-credit" type="uint"/>
<field name="available" type="uint"/>
<field name="drain" type="boolean" default="false"/>
<field name="echo" type="boolean" default="false"/>
<field name="properties" type="fields"/>
</type>
<type name="transfer" class="composite" source="list" provides="frame">
<descriptor name="amqp:transfer:list" code="0x00000000:0x00000014"/>
<field name="handle" type="handle" mandatory="true"/>
<field name="delivery-id" type="delivery-number"/>
<field name="delivery-tag" type="delivery-tag"/>
<field name="message-format" type="message-format"/>
<field name="settled" type="boolean"/>
<field name="more" type="boolean" default="false"/>
<field name="rcv-settle-mode" type="receiver-settle-mode"/>
<field name="state" type="*" requires="delivery-state"/>
<field name="resume" type="boolean" default="false"/>
<field name="aborted" type="boolean" default="false"/>
<field name="batchable" type="boolean" default="false"/>
</type>
<type name="disposition" class="composite" source="list" provides="frame">
<descriptor name="amqp:disposition:list" code="0x00000000:0x00000015"/>
<field name="role" type="role" mandatory="true"/>
<field name="first" type="delivery-number" mandatory="true"/>
<field name="last" type="delivery-number"/>
<field name="settled" type="boolean" default="false"/>
<field name="state" type="*" requires="delivery-state"/>
<field name="batchable" type="boolean" default="false"/>
</type>
<type name="detach" class="composite" source="list" provides="frame">
<descriptor name="amqp:detach:list" code="0x00000000:0x00000016"/>
<field name="handle" type="handle" mandatory="true"/>
<field name="closed" type="boolean" default="false"/>
<field name="error" type="error"/>
</type>
<type name="end" class="composite" source="list" provides="frame">
<descriptor name="amqp:end:list" code="0x00000000:0x00000017"/>
<field name="error" type="error"/>
</type>
<type name="close" class="composite" source="list" provides="frame">
<descriptor name="amqp:close:list" code="0x00000000:0x00000018"/>
<field name="error" type="error"/>
</type>
</section>
<section name="definitions">
<type name="role" class="restricted" source="boolean">
<choice name="sender" value="false"/>
<choice name="receiver" value="true"/>
</type>
<type name="sender-settle-mode" class="restricted" source="ubyte">
<choice name="unsettled" value="0"/>
<choice name="settled" value="1"/>
<choice name="mixed" value="2"/>
</type>
<type name="receiver-settle-mode" class="restricted" source="ubyte">
<choice name="first" value="0"/>
<choice name="second" value="1"/>
</type>
<type name="handle" class="restricted" source="uint"/>
<type name="seconds" class="restricted" source="uint"/>
<type name="milliseconds" class="restricted" source="uint"/>
<type name="delivery-tag" class="restricted" source="binary"/>
<type name="delivery-number" class="restricted" source="sequence-no"/>
<type name="transfer-number" class="restricted" source="sequence-no"/>
<type name="sequence-no" class="restricted" source="uint"/>
<type name="message-format" class="restricted" source="uint"/>
<type name="ietf-language-tag" class="restricted" source="symbol"/>
<type name="fields" class="restricted" source="map"/>
<type name="error" class="composite" source="list">
<descriptor name="amqp:error:list" code="0x00000000:0x0000001d"/>
<field name="condition" type="symbol" mandatory="true" requires="error-condition"/>
<field name="description" type="string"/>
<field name="info" type="fields"/>
</type>
<type name="amqp-error" class="restricted" source="symbol" provides="error-condition">
<choice name="internal-error" value="amqp:internal-error"/>
<choice name="not-found" value="amqp:not-found"/>
<choice name="unauthorized-access" value="amqp:unauthorized-access"/>
<choice name="decode-error" value="amqp:decode-error"/>
<choice name="resource-limit-exceeded" value="amqp:resource-limit-exceeded"/>
<choice name="not-allowed" value="amqp:not-allowed"/>
<choice name="invalid-field" value="amqp:invalid-field"/>
<choice name="not-implemented" value="amqp:not-implemented"/>
<choice name="resource-locked" value="amqp:resource-locked"/>
<choice name="precondition-failed" value="amqp:precondition-failed"/>
<choice name="resource-deleted" value="amqp:resource-deleted"/>
<choice name="illegal-state" value="amqp:illegal-state"/>
<choice name="frame-size-too-small" value="amqp:frame-size-too-small"/>
</type>
<type name="connection-error" class="restricted" source="symbol" provides="error-condition">
<choice name="connection-forced" value="amqp:connection:forced"/>
<choice name="framing-error" value="amqp:connection:framing-error"/>
<choice name="redirect" value="amqp:connection:redirect"/>
</type>
<type name="session-error" class="restricted" source="symbol" provides="error-condition">
<choice name="window-violation" value="amqp:session:window-violation"/>
<choice name="errant-link" value="amqp:session:errant-link"/>
<choice name="handle-in-use" value="amqp:session:handle-in-use"/>
<choice name="unattached-handle" value="amqp:session:unattached-handle"/>
</type>
<type name="link-error" class="restricted" source="symbol" provides="error-condition">
<choice name="detach-forced" value="amqp:link:detach-forced"/>
<choice name="transfer-limit-exceeded" value="amqp:link:transfer-limit-exceeded"/>
<choice name="message-size-exceeded" value="amqp:link:message-size-exceeded"/>
<choice name="redirect" value="amqp:link:redirect"/>
<choice name="stolen" value="amqp:link:stolen"/>
</type>
<definition name="PORT" value="5672"/>
<definition name="SECURE-PORT" value="5671"/>
<definition name="MAJOR" value="1"/>
<definition name="MINOR" value="0"/>
<definition name="REVISION" value="0"/>
<definition name="MIN-MAX-FRAME-SIZE" value="512"/>
</section>
</amqp>

View File

@ -1,125 +0,0 @@
<?xml version="1.0"?>
<!--
Copyright Bank of America, N.A., Barclays Bank PLC, Cisco Systems, Credit
Suisse, Deutsche Boerse, Envoy Technologies Inc., Goldman Sachs, HCL
Technologies Ltd, IIT Software GmbH, iMatix Corporation, INETCO Systems Limited,
Informatica Corporation, JPMorgan Chase & Co., Kaazing Corporation, N.A,
Microsoft Corporation, my-Channels, Novell, Progress Software, Red Hat Inc.,
Software AG, Solace Systems Inc., StormMQ Ltd., Tervela Inc., TWIST Process
Innovations Ltd, GoPivotal, Inc., and WS02 Inc. 2006-2011. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<amqp name="types" xmlns="http://www.amqp.org/schema/amqp.xsd">
<section name="encodings">
<type name="null" class="primitive">
<encoding code="0x40" category="fixed" width="0"/>
</type>
<type name="boolean" class="primitive">
<encoding code="0x56" category="fixed" width="1"/>
<encoding name="true" code="0x41" category="fixed" width="0"/>
<encoding name="false" code="0x42" category="fixed" width="0"/>
</type>
<type name="ubyte" class="primitive">
<encoding code="0x50" category="fixed" width="1"/>
</type>
<type name="ushort" class="primitive">
<encoding code="0x60" category="fixed" width="2"/>
</type>
<type name="uint" class="primitive">
<encoding code="0x70" category="fixed" width="4"/>
<encoding name="smalluint" code="0x52" category="fixed" width="1"/>
<encoding name="uint0" code="0x43" category="fixed" width="0"/>
</type>
<type name="ulong" class="primitive">
<encoding code="0x80" category="fixed" width="8"/>
<encoding name="smallulong" code="0x53" category="fixed" width="1"/>
<encoding name="ulong0" code="0x44" category="fixed" width="0"/>
</type>
<type name="byte" class="primitive">
<encoding code="0x51" category="fixed" width="1"/>
</type>
<type name="short" class="primitive">
<encoding code="0x61" category="fixed" width="2"/>
</type>
<type name="int" class="primitive">
<encoding code="0x71" category="fixed" width="4"/>
<encoding name="smallint" code="0x54" category="fixed" width="1"/>
</type>
<type name="long" class="primitive">
<encoding code="0x81" category="fixed" width="8"/>
<encoding name="smalllong" code="0x55" category="fixed" width="1"/>
</type>
<type name="float" class="primitive">
<encoding name="ieee-754" code="0x72" category="fixed" width="4"/>
</type>
<type name="double" class="primitive">
<encoding name="ieee-754" code="0x82" category="fixed" width="8"/>
</type>
<type name="decimal32" class="primitive">
<encoding name="ieee-754" code="0x74" category="fixed" width="4"/>
</type>
<type name="decimal64" class="primitive">
<encoding name="ieee-754" code="0x84" category="fixed" width="8"/>
</type>
<type name="decimal128" class="primitive">
<encoding name="ieee-754" code="0x94" category="fixed" width="16"/>
</type>
<type name="char" class="primitive">
<encoding name="utf32" code="0x73" category="fixed" width="4"/>
</type>
<type name="timestamp" class="primitive">
<encoding name="ms64" code="0x83" category="fixed" width="8"/>
</type>
<type name="uuid" class="primitive">
<encoding code="0x98" category="fixed" width="16"/>
</type>
<type name="binary" class="primitive">
<encoding name="vbin8" code="0xa0" category="variable" width="1"/>
<encoding name="vbin32" code="0xb0" category="variable" width="4"/>
</type>
<type name="string" class="primitive">
<encoding name="str8-utf8" code="0xa1" category="variable" width="1"/>
<encoding name="str32-utf8" code="0xb1" category="variable" width="4"/>
</type>
<type name="symbol" class="primitive">
<encoding name="sym8" code="0xa3" category="variable" width="1"/>
<encoding name="sym32" code="0xb3" category="variable" width="4"/>
</type>
<type name="list" class="primitive">
<encoding name="list0" code="0x45" category="fixed" width="0"/>
<encoding name="list8" code="0xc0" category="compound" width="1"/>
<encoding name="list32" code="0xd0" category="compound" width="4"/>
</type>
<type name="map" class="primitive">
<encoding name="map8" code="0xc1" category="compound" width="1"/>
<encoding name="map32" code="0xd1" category="compound" width="4"/>
</type>
<type name="array" class="primitive">
<encoding name="array8" code="0xe0" category="array" width="1"/>
<encoding name="array32" code="0xf0" category="array" width="4"/>
</type>
</section>
</amqp>

View File

@ -3,7 +3,7 @@
-behaviour(gen_fsm).
-include("amqp10_client.hrl").
-include("rabbit_amqp1_0_framing.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
%% Public API.
-export([open/2,

View File

@ -3,7 +3,7 @@
-behaviour(gen_fsm).
-include("amqp10_client.hrl").
-include("rabbit_amqp1_0_framing.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

View File

@ -1,7 +1,7 @@
-module(amqp10_client_link).
-include("amqp10_client.hrl").
-include("rabbit_amqp1_0_framing.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-export([
sender/3,

View File

@ -3,7 +3,7 @@
-behaviour(gen_fsm).
-include("amqp10_client.hrl").
-include("rabbit_amqp1_0_framing.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
%% Public API.
-export(['begin'/1,

View File

@ -1,6 +1,6 @@
-module(amqp10_client_types).
-include("rabbit_amqp1_0_framing.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-export([
unpack/1,

View File

@ -20,7 +20,7 @@
set_properties/2
]).
-include("rabbit_amqp1_0_framing.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-type maybe(T) :: T | undefined.

View File

@ -1,135 +0,0 @@
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (the "License"); you may not use this file except in
%% compliance with the License. You may obtain a copy of the License
%% at http://www.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and
%% limitations under the License.
%%
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is GoPivotal, Inc.
%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
%%
-module(rabbit_amqp1_0_binary_generator).
-export([generate/1, build_frame/2, build_frame/3,
build_heartbeat_frame/0]).
-include("rabbit_amqp1_0.hrl").
-spec generate(tuple()) -> iolist().
-spec build_frame(integer(), iolist()) -> iolist().
-define(AMQP_FRAME_TYPE, 0).
-define(DOFF, 2).
-define(VAR_1_LIMIT, 16#FF).
build_frame(Channel, Payload) ->
build_frame(Channel, ?AMQP_FRAME_TYPE, Payload).
build_frame(Channel, FrameType, Payload) ->
Size = iolist_size(Payload) + 8, % frame header and no extension
[ <<Size:32/unsigned, 2:8, FrameType:8, Channel:16/unsigned>>, Payload ].
build_heartbeat_frame() ->
%% length is inclusive
<<8:32, ?DOFF:8, ?AMQP_FRAME_TYPE:8, 0:16>>.
generate({described, Descriptor, Value}) ->
DescBin = generate(Descriptor),
ValueBin = generate(Value),
[ ?DESCRIBED_BIN, DescBin, ValueBin ];
generate(null) -> <<16#40>>;
generate(true) -> <<16#41>>;
generate(false) -> <<16#42>>;
%% some integral types have a compact encoding as a byte; this is in
%% particular for the descriptors of AMQP types, which have the domain
%% bits set to zero and values < 256.
generate({ubyte, V}) -> <<16#50,V:8/unsigned>>;
generate({ushort, V}) -> <<16#60,V:16/unsigned>>;
generate({uint, V}) when V =:= 0 -> <<16#43>>;
generate({uint, V}) when V < 256 -> <<16#52,V:8/unsigned>>;
generate({uint, V}) -> <<16#70,V:32/unsigned>>;
generate({ulong, V}) when V =:= 0 -> <<16#44>>;
generate({ulong, V}) when V < 256 -> <<16#53,V:8/unsigned>>;
generate({ulong, V}) -> <<16#80,V:64/unsigned>>;
generate({byte, V}) -> <<16#51,V:8/signed>>;
generate({short, V}) -> <<16#61,V:16/signed>>;
generate({int, V}) when V<128 andalso V>-129 -> <<16#54,V:8/signed>>;
generate({int, V}) -> <<16#71,V:32/signed>>;
generate({long, V}) when V<128 andalso V>-129 -> <<16#55,V:8/signed>>;
generate({long, V}) -> <<16#81,V:64/signed>>;
generate({float, V}) -> <<16#72,V:32/float>>;
generate({double, V}) -> <<16#82,V:64/float>>;
generate({char, V}) -> <<16#73,V:4/binary>>;
generate({timestamp,V}) -> <<16#83,V:64/signed>>;
generate({uuid, V}) -> <<16#98,V:16/binary>>;
generate({utf8, V}) when size(V) < ?VAR_1_LIMIT -> [<<16#a1,(size(V)):8>>, V];
generate({utf8, V}) -> [<<16#b1,(size(V)):32>>, V];
generate({symbol, V}) -> [<<16#a3,(size(V)):8>>, V];
generate({binary, V}) ->
Size = iolist_size(V),
if Size < ?VAR_1_LIMIT -> [<<16#a0,Size:8>>, V];
true -> [<<16#b0,Size:32>>, V]
end;
generate({list, []}) ->
<<16#45>>;
generate({list, List}) ->
Count = length(List),
Compound = lists:map(fun generate/1, List),
S = iolist_size(Compound),
%% If the list contains less than (256 - 1) elements and if the
%% encoded size (including the encoding of "Count", thus S + 1
%% in the test) is less than 256 bytes, we use the short form.
%% Otherwise, we use the large form.
if Count >= (256 - 1) orelse (S + 1) >= 256 ->
[<<16#d0, (S + 4):32/unsigned, Count:32/unsigned>>, Compound];
true ->
[<<16#c0, (S + 1):8/unsigned, Count:8/unsigned>>, Compound]
end;
generate({map, ListOfPairs}) ->
Count = length(ListOfPairs) * 2,
Compound = lists:map(fun ({Key, Val}) ->
[(generate(Key)),
(generate(Val))]
end, ListOfPairs),
S = iolist_size(Compound),
%% See generate({list, ...}) for an explanation of this test.
if Count >= (256 - 1) orelse (S + 1) >= 256 ->
[<<16#d1, (S + 4):32, Count:32>>, Compound];
true ->
[<<16#c1, (S + 1):8, Count:8>>, Compound]
end;
generate({array, Type, List}) ->
Count = length(List),
Body = iolist_to_binary(
[constructor(Type), [generate(Type, I) || I <- List]]),
S = size(Body),
%% See generate({list, ...}) for an explanation of this test.
if Count >= (256 - 1) orelse (S + 1) >= 256 ->
[<<16#f0, (S + 4):32/unsigned, Count:32/unsigned>>, Body];
true ->
[<<16#e0, (S + 1):8/unsigned, Count:8/unsigned>>, Body]
end;
generate({as_is, TypeCode, Bin}) ->
<<TypeCode, Bin>>.
%% TODO again these are a stub to get SASL working. New codec? Will
%% that ever happen? If not we really just need to split generate/1
%% up into things like these...
constructor(symbol) ->
<<16#a3>>.
generate(symbol, Value) ->
[<<(size(Value)):8>>, Value].

View File

@ -1,154 +0,0 @@
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (the "License"); you may not use this file except in
%% compliance with the License. You may obtain a copy of the License
%% at http://www.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and
%% limitations under the License.
%%
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is GoPivotal, Inc.
%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
%%
-module(rabbit_amqp1_0_binary_parser).
-export([parse/1, parse_all/1]).
-include("rabbit_amqp1_0.hrl").
-spec parse(binary()) -> tuple().
parse_all(ValueBin) when is_binary(ValueBin) ->
lists:reverse(parse_all([], parse(ValueBin))).
parse_all(Acc, {Value, <<>>}) -> [Value | Acc];
parse_all(Acc, {Value, Rest}) -> parse_all([Value | Acc], parse(Rest)).
parse(<<?DESCRIBED,Rest/binary>>) ->
parse_described(Rest);
parse(Rest) ->
parse_primitive0(Rest).
parse_described(Bin) ->
{Descriptor, Rest1} = parse(Bin),
{Value, Rest2} = parse(Rest1),
{{described, Descriptor, Value}, Rest2}.
parse_primitive0(<<Type,Rest/binary>>) ->
parse_primitive(Type, Rest).
%% Constants
parse_primitive(16#40, Rest) -> {null, Rest};
parse_primitive(16#41, Rest) -> {true, Rest};
parse_primitive(16#42, Rest) -> {false, Rest};
parse_primitive(16#43, Rest) -> {{uint, 0}, Rest};
parse_primitive(16#44, Rest) -> {{ulong, 0}, Rest};
%% Fixed-widths. Most integral types have a compact encoding as a byte.
parse_primitive(16#50, <<V:8/unsigned, R/binary>>) -> {{ubyte, V}, R};
parse_primitive(16#51, <<V:8/signed, R/binary>>) -> {{byte, V}, R};
parse_primitive(16#52, <<V:8/unsigned, R/binary>>) -> {{uint, V}, R};
parse_primitive(16#53, <<V:8/unsigned, R/binary>>) -> {{ulong, V}, R};
parse_primitive(16#54, <<V:8/signed, R/binary>>) -> {{int, V}, R};
parse_primitive(16#55, <<V:8/signed, R/binary>>) -> {{long, V}, R};
parse_primitive(16#56, <<0:8/unsigned, R/binary>>) -> {false, R};
parse_primitive(16#56, <<1:8/unsigned, R/binary>>) -> {true, R};
parse_primitive(16#60, <<V:16/unsigned, R/binary>>) -> {{ushort, V}, R};
parse_primitive(16#61, <<V:16/signed, R/binary>>) -> {{short, V}, R};
parse_primitive(16#70, <<V:32/unsigned, R/binary>>) -> {{uint, V}, R};
parse_primitive(16#71, <<V:32/signed, R/binary>>) -> {{int, V}, R};
parse_primitive(16#72, <<V:32/float, R/binary>>) -> {{float, V}, R};
parse_primitive(16#73, <<Utf32:4/binary,R/binary>>) -> {{char, Utf32}, R};
parse_primitive(16#80, <<V:64/unsigned, R/binary>>) -> {{ulong, V}, R};
parse_primitive(16#81, <<V:64/signed, R/binary>>) -> {{long, V}, R};
parse_primitive(16#82, <<V:64/float, R/binary>>) -> {{double, V}, R};
parse_primitive(16#83, <<TS:64/signed, R/binary>>) -> {{timestamp, TS}, R};
parse_primitive(16#98, <<Uuid:16/binary,R/binary>>) -> {{uuid, Uuid}, R};
%% Variable-widths
parse_primitive(16#a0,<<S:8/unsigned, V:S/binary,R/binary>>)-> {{binary, V}, R};
parse_primitive(16#a1,<<S:8/unsigned, V:S/binary,R/binary>>)-> {{utf8, V}, R};
parse_primitive(16#a3,<<S:8/unsigned, V:S/binary,R/binary>>)-> {{symbol, V}, R};
parse_primitive(16#b3,<<S:32/unsigned,V:S/binary,R/binary>>)-> {{symbol, V}, R};
parse_primitive(16#b0,<<S:32/unsigned,V:S/binary,R/binary>>)-> {{binary, V}, R};
parse_primitive(16#b1,<<S:32/unsigned,V:S/binary,R/binary>>)-> {{utf8, V}, R};
%% Compounds
parse_primitive(16#45, R) ->
{{list, []}, R};
parse_primitive(16#c0,<<S:8/unsigned,CountAndValue:S/binary,R/binary>>) ->
{{list, parse_compound(8, CountAndValue)}, R};
parse_primitive(16#c1,<<S:8/unsigned,CountAndValue:S/binary,R/binary>>) ->
List = parse_compound(8, CountAndValue),
{{map, mapify(List)}, R};
parse_primitive(16#d0,<<S:32/unsigned,CountAndValue:S/binary,R/binary>>) ->
{{list, parse_compound(32, CountAndValue)}, R};
parse_primitive(16#d1,<<S:32/unsigned,CountAndValue:S/binary,R/binary>>) ->
List = parse_compound(32, CountAndValue),
{{map, mapify(List)}, R};
%% Arrays
parse_primitive(16#e0,<<S:8/unsigned,CountAndV:S/binary,R/binary>>) ->
{{array, parse_array(8, CountAndV)}, R};
parse_primitive(16#f0,<<S:32/unsigned,CountAndV:S/binary,R/binary>>) ->
{{array, parse_array(32, CountAndV)}, R};
%% NaN or +-inf
parse_primitive(16#72, <<V:32, R/binary>>) ->
{{as_is, 16#72, <<V:32>>}, R};
parse_primitive(16#82, <<V:64, R/binary>>) ->
{{as_is, 16#82, <<V:64>>}, R};
%% decimals
parse_primitive(16#74, <<V:32, R/binary>>) ->
{{as_is, 16#74, <<V:32>>}, R};
parse_primitive(16#84, <<V:64, R/binary>>) ->
{{as_is, 16#84, <<V:64>>}, R};
parse_primitive(16#94, <<V:128, R/binary>>) ->
{{as_is, 16#94, <<V:128>>}, R};
parse_primitive(Type, _) ->
throw({primitive_type_unsupported, Type}).
parse_compound(UnitSize, Bin) ->
<<Count:UnitSize, Bin1/binary>> = Bin,
parse_compound1(Count, Bin1, []).
parse_compound1(0, <<>>, List) ->
lists:reverse(List);
parse_compound1(_Left, <<>>, List) ->
case application:get_env(rabbitmq_amqp1_0, protocol_strict_mode) of
{ok, false} -> lists:reverse(List); %% ignore miscount
{ok, true} -> throw(compound_datatype_miscount)
end;
parse_compound1(Count, Bin, Acc) ->
{Value, Rest} = parse(Bin),
parse_compound1(Count - 1, Rest, [Value | Acc]).
parse_array(UnitSize, Bin) ->
<<Count:UnitSize, Bin1/binary>> = Bin,
parse_array1(Count, Bin1).
parse_array1(Count, <<?DESCRIBED,Rest/binary>>) ->
{Descriptor, Rest1} = parse(Rest),
List = parse_array1(Count, Rest1),
lists:map(fun (Value) ->
{described, Descriptor, Value}
end, List);
parse_array1(Count, <<Type,ArrayBin/binary>>) ->
parse_array2(Count, Type, ArrayBin, []).
parse_array2(0, _Type, <<>>, Acc) ->
lists:reverse(Acc);
parse_array2(Count, Type, Bin, Acc) ->
{Value, Rest} = parse_primitive(Type, Bin),
parse_array2(Count - 1, Type, Rest, [Value | Acc]).
mapify([]) ->
[];
mapify([Key, Value | Rest]) ->
[{Key, Value} | mapify(Rest)].

View File

@ -1,147 +0,0 @@
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (the "License"); you may not use this file except in
%% compliance with the License. You may obtain a copy of the License
%% at http://www.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and
%% limitations under the License.
%%
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is GoPivotal, Inc.
%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
%%
-module(rabbit_amqp1_0_framing).
-export([encode/1, encode_described/3, decode/1, version/0,
symbol_for/1, number_for/1, encode_bin/1, decode_bin/1, pprint/1]).
%% debug
-export([fill_from_list/2, fill_from_map/2]).
-include("rabbit_amqp1_0.hrl").
version() ->
{1, 0, 0}.
%% These are essentially in lieu of code generation ..
fill_from_list(Record, Fields) ->
{Res, _} = lists:foldl(
fun (Field, {Record1, Num}) ->
DecodedField = decode(Field),
{setelement(Num, Record1, DecodedField),
Num + 1}
end,
{Record, 2}, Fields),
Res.
fill_from_map(Record, Fields) ->
{Res, _} = lists:foldl(
fun (Key, {Record1, Num}) ->
case proplists:get_value(Key, Fields) of
undefined ->
{Record1, Num+1};
Value ->
{setelement(Num, Record1, decode(Value)), Num+1}
end
end,
{Record, 2}, keys(Record)),
Res.
fill_from(F = #'v1_0.data'{}, Field) ->
F#'v1_0.data'{content = Field};
fill_from(F = #'v1_0.amqp_value'{}, Field) ->
F#'v1_0.amqp_value'{content = Field}.
keys(Record) ->
[{symbol, symbolify(K)} || K <- rabbit_amqp1_0_framing0:fields(Record)].
symbolify(FieldName) when is_atom(FieldName) ->
re:replace(atom_to_list(FieldName), "_", "-", [{return,binary}, global]).
%% TODO: in fields of composite types with multiple=true, "a null
%% value and a zero-length array (with a correct type for its
%% elements) both describe an absence of a value and should be treated
%% as semantically identical." (see section 1.3)
%% A sequence comes as an arbitrary list of values; it's not a
%% composite type.
decode({described, Descriptor, {list, Fields}}) ->
case rabbit_amqp1_0_framing0:record_for(Descriptor) of
#'v1_0.amqp_sequence'{} ->
#'v1_0.amqp_sequence'{content = [decode(F) || F <- Fields]};
Else ->
fill_from_list(Else, Fields)
end;
decode({described, Descriptor, {map, Fields}}) ->
case rabbit_amqp1_0_framing0:record_for(Descriptor) of
#'v1_0.application_properties'{} ->
#'v1_0.application_properties'{content = decode_map(Fields)};
#'v1_0.delivery_annotations'{} ->
#'v1_0.delivery_annotations'{content = decode_map(Fields)};
#'v1_0.message_annotations'{} ->
#'v1_0.message_annotations'{content = decode_map(Fields)};
#'v1_0.footer'{} ->
#'v1_0.footer'{content = decode_map(Fields)};
Else ->
fill_from_map(Else, Fields)
end;
decode({described, Descriptor, {binary, Field}}) ->
case rabbit_amqp1_0_framing0:record_for(Descriptor) of
#'v1_0.amqp_value'{} ->
#'v1_0.amqp_value'{content = {binary, Field}};
#'v1_0.data'{} ->
#'v1_0.data'{content = Field}
end;
decode({described, Descriptor, Field}) ->
fill_from(rabbit_amqp1_0_framing0:record_for(Descriptor), Field);
decode(null) ->
undefined;
decode(Other) ->
Other.
decode_map(Fields) ->
[{decode(K), decode(V)} || {K, V} <- Fields].
encode_described(list, CodeNumber, Frame) ->
{described, {ulong, CodeNumber},
{list, lists:map(fun encode/1, tl(tuple_to_list(Frame)))}};
encode_described(map, CodeNumber, Frame) ->
{described, {ulong, CodeNumber},
{map, lists:zip(keys(Frame),
lists:map(fun encode/1, tl(tuple_to_list(Frame))))}};
encode_described(binary, CodeNumber, #'v1_0.data'{content = Content}) ->
{described, {ulong, CodeNumber}, {binary, Content}};
encode_described('*', CodeNumber, #'v1_0.amqp_value'{content = Content}) ->
{described, {ulong, CodeNumber}, Content};
encode_described(annotations, CodeNumber, Frame) ->
encode_described(map, CodeNumber, Frame).
encode(X) ->
rabbit_amqp1_0_framing0:encode(X).
encode_bin(X) ->
rabbit_amqp1_0_binary_generator:generate(encode(X)).
decode_bin(X) -> [decode(PerfDesc) || PerfDesc <- decode_bin0(X)].
decode_bin0(<<>>) -> [];
decode_bin0(X) -> {PerfDesc, Rest} = rabbit_amqp1_0_binary_parser:parse(X),
[PerfDesc | decode_bin0(Rest)].
symbol_for(X) ->
rabbit_amqp1_0_framing0:symbol_for(X).
number_for(X) ->
rabbit_amqp1_0_framing0:number_for(X).
pprint(Thing) when is_tuple(Thing) ->
case rabbit_amqp1_0_framing0:fields(Thing) of
unknown -> Thing;
Names -> [T|L] = tuple_to_list(Thing),
{T, lists:zip(Names, [pprint(I) || I <- L])}
end;
pprint(Other) -> Other.

View File

@ -19,7 +19,7 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include("rabbit_amqp1_0_framing.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-compile(export_all).

View File

@ -19,8 +19,9 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-include("amqp10_client.hrl").
-include("rabbit_amqp1_0_framing.hrl").
-compile(export_all).
@ -68,11 +69,11 @@ end_per_suite(Config) ->
]).
start_amqp10_client_app(Config) ->
application:start(amqp10_client),
?assertMatch({ok, _}, application:ensure_all_started(amqp10_client)),
Config.
stop_amqp10_client_app(Config) ->
application:stop(amqp10_client),
ok = application:stop(amqp10_client),
Config.
%% -------------------------------------------------------------------