From cabb62c333032ec5a1a499e2336d8c6bb10aa580 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 3 Nov 2012 21:04:32 +0000 Subject: ditch superfluous type mapping in codegen --- codegen.py | 27 ++++++--------------------- src/rabbit_binary_generator.erl | 6 +++--- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/codegen.py b/codegen.py index 9483e854..68f530c2 100644 --- a/codegen.py +++ b/codegen.py @@ -24,18 +24,6 @@ from amqp_codegen import * import string import re -erlangTypeMap = { - 'octet': 'octet', - 'shortstr': 'shortstr', - 'longstr': 'longstr', - 'short': 'shortint', - 'long': 'longint', - 'longlong': 'longlongint', - 'bit': 'bit', - 'table': 'table', - 'timestamp': 'timestamp', -} - # Coming up with a proper encoding of AMQP tables in JSON is too much # hassle at this stage. Given that the only default value we are # interested in is for the empty table, we only support that. @@ -123,7 +111,7 @@ def printFileHeader(): def genErl(spec): def erlType(domain): - return erlangTypeMap[spec.resolveDomain(domain)] + return erlangize(spec.resolveDomain(domain)) def fieldTypeList(fields): return '[' + ', '.join([erlType(f.domain) for f in fields]) + ']' @@ -186,11 +174,11 @@ def genErl(spec): return p+'Len:32/unsigned, '+p+':'+p+'Len/binary' elif type == 'octet': return p+':8/unsigned' - elif type == 'shortint': + elif type == 'short': return p+':16/unsigned' - elif type == 'longint': + elif type == 'long': return p+':32/unsigned' - elif type == 'longlongint': + elif type == 'longlong': return p+':64/unsigned' elif type == 'timestamp': return p+':64/unsigned' @@ -350,8 +338,8 @@ def genErl(spec): 'table' | 'byte' | 'double' | 'float' | 'long' | 'short' | 'bool' | 'binary' | 'void' | 'array'). -type(amqp_property_type() :: - 'shortstr' | 'longstr' | 'octet' | 'shortint' | 'longint' | - 'longlongint' | 'timestamp' | 'bit' | 'table'). + 'shortstr' | 'longstr' | 'octet' | 'short' | 'long' | + 'longlong' | 'timestamp' | 'bit' | 'table'). -type(amqp_table() :: [{binary(), amqp_field_type(), amqp_value()}]). -type(amqp_array() :: [{amqp_field_type(), amqp_value()}]). @@ -497,9 +485,6 @@ shortstr_size(S) -> print "amqp_exception(_Code) -> undefined." def genHrl(spec): - def erlType(domain): - return erlangTypeMap[spec.resolveDomain(domain)] - def fieldNameList(fields): return ', '.join([erlangize(f.name) for f in fields]) diff --git a/src/rabbit_binary_generator.erl b/src/rabbit_binary_generator.erl index 6b6b395a..2ece8696 100644 --- a/src/rabbit_binary_generator.erl +++ b/src/rabbit_binary_generator.erl @@ -215,9 +215,9 @@ encode_property(shortstr, String) -> encode_property(longstr, String) -> Len = size(String), <>; encode_property(octet, Int) -> <>; -encode_property(shortint, Int) -> <>; -encode_property(longint, Int) -> <>; -encode_property(longlongint, Int) -> <>; +encode_property(short, Int) -> <>; +encode_property(long, Int) -> <>; +encode_property(longlong, Int) -> <>; encode_property(timestamp, Int) -> <>; encode_property(table, Table) -> table_to_binary(Table). -- cgit v1.2.1 From bd2bd07fd063e6ce2b0d7e8c1589fff7ac1cd2ae Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 3 Nov 2012 21:09:33 +0000 Subject: fix tests --- src/rabbit_tests.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index eb97f1d6..715aa186 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -444,10 +444,10 @@ test_content_properties() -> test_content_prop_encoding([{bit, true}, {octet, 123}, {octet, 123}, {bit, true}], <<16#F0,0,123,123>>), test_content_prop_encoding([{bit, true}, {shortstr, <<"hi">>}, {bit, true}, - {shortint, 54321}, {bit, true}], + {short, 54321}, {bit, true}], <<16#F8,0,2,"hi",16#D4,16#31>>), test_content_prop_encoding([{bit, true}, {shortstr, undefined}, {bit, true}, - {shortint, 54321}, {bit, true}], + {short, 54321}, {bit, true}], <<16#B8,0,16#D4,16#31>>), test_content_prop_encoding([{table, [{<<"a signedint">>, signedint, 12345678}, {<<"a longstr">>, longstr, <<"yes please">>}, -- cgit v1.2.1 From 829dbc813af97f23796ba30a8ecbf87be1b9acb5 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 4 Nov 2012 09:32:01 +0000 Subject: be more assertive in property decoding --- codegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen.py b/codegen.py index 9483e854..d418e76d 100644 --- a/codegen.py +++ b/codegen.py @@ -249,7 +249,7 @@ def genErl(spec): 'R' + i, 'L' + i, 'S' + i, 'X' + i)) if len(c.fields) == 0: - print "decode_properties(%d, _) ->" % (c.index,) + print "decode_properties(%d, <<>>) ->" % (c.index,) else: print ("decode_properties(%d, %s) ->" % (c.index, presentBin(c.fields))) -- cgit v1.2.1 From aa6908c906ab8d0e647c5d0963d86c3a69e38267 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 4 Nov 2012 16:48:13 +0000 Subject: handle all types in property decoder --- codegen.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/codegen.py b/codegen.py index 0adec1ab..2ff78420 100644 --- a/codegen.py +++ b/codegen.py @@ -223,8 +223,12 @@ def genErl(spec): return '<<' + ps + ', _:%d, R0/binary>>' % (16 - len(fields),) def writePropFieldLine(field): i = str(field.index) - print " {F%s, R%s} = if P%s =:= 0 -> {undefined, R%s}; true -> %s_prop(R%s) end," % \ - (i, str(field.index + 1), i, i, erlType(field.domain), i) + if field.domain == 'bit': + print " {F%s, R%s} = {P%s =/= 0, R%s}," % \ + (i, str(field.index + 1), i, i) + else: + print " {F%s, R%s} = if P%s =:= 0 -> {undefined, R%s}; true -> %s_prop(R%s) end," % \ + (i, str(field.index + 1), i, i, erlType(field.domain), i) if len(c.fields) == 0: print "decode_properties(%d, <<>>) ->" % (c.index,) @@ -407,17 +411,28 @@ shortstr_size(S) -> _ -> exit(method_field_shortstr_overflow) end. -shortstr_prop(<>) -> - {S, X}. +%% use of these functions by the codec depends on the protocol spec +-compile({nowarn_unused_function, + [{shortstr_prop, 1}, {longstr_prop, 1}, + {short_prop, 1}, {long_prop, 1}, {longlong_prop, 1}, + {octet_prop, 1}, {table_prop, 1}, {timestamp_prop, 1}]}). + +shortstr_prop(<>) -> {S, X}. + +longstr_prop(<>) -> {S, X}. + +short_prop(<>) -> {I, X}. + +long_prop(<>) -> {I, X}. + +longlong_prop(<>) -> {I, X}. + +octet_prop(<>) -> {I, X}. table_prop(<>) -> {rabbit_binary_parser:parse_table(T), X}. -octet_prop(<>) -> - {I, X}. - -timestamp_prop(<>) -> - {I, X}. +timestamp_prop(<>) -> {I, X}. """ version = "{%d, %d, %d}" % (spec.major, spec.minor, spec.revision) if version == '{8, 0, 0}': version = '{0, 8, 0}' -- cgit v1.2.1