diff options
-rw-r--r-- | codegen.py | 73 |
1 files changed, 49 insertions, 24 deletions
@@ -227,8 +227,8 @@ def genErl(spec): 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) + print " {F%s, R%s} = if P%s =:= 0 -> {undefined, R%s}; true -> ?%s_PROP(R%s, L%s, V%s, X%s) end," % \ + (i, str(field.index + 1), i, i, erlType(field.domain).upper(), i, i, i, i) if len(c.fields) == 0: print "decode_properties(%d, <<>>) ->" % (c.index,) @@ -411,28 +411,53 @@ shortstr_size(S) -> _ -> exit(method_field_shortstr_overflow) end. -%% 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(<<L:8/unsigned, S:L/binary, X/binary>>) -> {S, X}. - -longstr_prop(<<L:32/unsigned, S:L/binary, X/binary>>) -> {S, X}. - -short_prop(<<I:8/unsigned, X/binary>>) -> {I, X}. - -long_prop(<<I:32/unsigned, X/binary>>) -> {I, X}. - -longlong_prop(<<I:64/unsigned, X/binary>>) -> {I, X}. - -octet_prop(<<I:8/unsigned, X/binary>>) -> {I, X}. - -table_prop(<<L:32/unsigned, T:L/binary, X/binary>>) -> - {rabbit_binary_parser:parse_table(T), X}. - -timestamp_prop(<<I:64/unsigned, X/binary>>) -> {I, X}. +-define(SHORTSTR_PROP(R, L, V, X), + begin + <<L:8/unsigned, V:L/binary, X/binary>> = R, + {V, X} + end). + +-define(LONGSTR_PROP(R, L, V, X), + begin + <<L:32/unsigned, V:L/binary, X/binary>> = R, + {V, X} + end). + +-define(SHORT_PROP(R, L, V, X), + begin + <<V:8/unsigned, X/binary>> = R, + {V, X} + end). + +-define(LONG_PROP(R, L, V, X), + begin + <<V:32/unsigned, X/binary>> = R, + {V, X} + end). + +-define(LONGLONG_PROP(R, L, V, X), + begin + <<V:64/unsigned, X/binary>> = R, + {V, X} + end). + +-define(OCTET_PROP(R, L, V, X), + begin + <<V:8/unsigned, X/binary>> = R, + {V, X} + end). + +-define(TABLE_PROP(R, L, V, X), + begin + <<L:32/unsigned, V:L/binary, X/binary>> = R, + {rabbit_binary_parser:parse_table(V), X} + end). + +-define(TIMESTAMP_PROP(R, L, V, X), + begin + <<V:64/unsigned, X/binary>> = R, + {V, X} + end). """ version = "{%d, %d, %d}" % (spec.major, spec.minor, spec.revision) if version == '{8, 0, 0}': version = '{0, 8, 0}' |