233
221
def presentBin(fields):
234
222
ps = ', '.join(['P' + str(f.index) + ':1' for f in fields])
235
223
return '<<' + ps + ', _:%d, R0/binary>>' % (16 - len(fields),)
236
def mkMacroName(field):
237
return '?' + field.domain.upper() + '_PROP'
238
def writePropFieldLine(field, bin_next = None):
224
def writePropFieldLine(field):
239
225
i = str(field.index)
241
bin_next = 'R' + str(field.index + 1)
242
if field.domain in ['octet', 'timestamp']:
243
print (" {%s, %s} = %s(%s, %s, %s, %s)," %
244
('F' + i, bin_next, mkMacroName(field), 'P' + i,
245
'R' + i, 'I' + i, 'X' + i))
226
if field.domain == 'bit':
227
print " {F%s, R%s} = {P%s =/= 0, R%s}," % \
228
(i, str(field.index + 1), i, i)
247
print (" {%s, %s} = %s(%s, %s, %s, %s, %s)," %
248
('F' + i, bin_next, mkMacroName(field), 'P' + i,
249
'R' + i, 'L' + i, 'S' + i, 'X' + i))
230
print " {F%s, R%s} = if P%s =:= 0 -> {undefined, R%s}; true -> ?%s_VAL(R%s, L%s, V%s, X%s) end," % \
231
(i, str(field.index + 1), i, i, erlType(field.domain).upper(), i, i, i, i)
251
233
if len(c.fields) == 0:
252
print "decode_properties(%d, _) ->" % (c.index,)
234
print "decode_properties(%d, <<>>) ->" % (c.index,)
254
236
print ("decode_properties(%d, %s) ->" %
255
237
(c.index, presentBin(c.fields)))
256
for field in c.fields[:-1]:
238
for field in c.fields:
257
239
writePropFieldLine(field)
258
writePropFieldLine(c.fields[-1], "<<>>")
240
print " <<>> = %s," % ('R' + str(len(c.fields)))
259
241
print " #'P_%s'{%s};" % (erlangize(c.name), fieldMapList(c.fields))
261
243
def genFieldPreprocessing(packed):
283
265
print " <<%s>>;" % (', '.join([methodFieldFragment(f) for f in packedFields]))
285
267
def genEncodeProperties(c):
268
def presentBin(fields):
269
ps = ', '.join(['P' + str(f.index) + ':1' for f in fields])
270
return '<<' + ps + ', 0:%d>>' % (16 - len(fields),)
271
def writePropFieldLine(field):
273
if field.domain == 'bit':
274
print " {P%s, R%s} = {F%s =:= 1, R%s}," % \
275
(i, str(field.index + 1), i, i)
277
print " {P%s, R%s} = if F%s =:= undefined -> {0, R%s}; true -> {1, [?%s_PROP(F%s, L%s) | R%s]} end," % \
278
(i, str(field.index + 1), i, i, erlType(field.domain).upper(), i, i, i)
286
280
print "encode_properties(#'P_%s'{%s}) ->" % (erlangize(c.name), fieldMapList(c.fields))
287
print " rabbit_binary_generator:encode_properties(%s, %s);" % \
288
(fieldTypeList(c.fields), fieldTempList(c.fields))
281
if len(c.fields) == 0:
284
print " R0 = [<<>>],"
285
for field in c.fields:
286
writePropFieldLine(field)
287
print " list_to_binary([%s | lists:reverse(R%s)]);" % \
288
(presentBin(c.fields), str(len(c.fields)))
290
290
def messageConstantClass(cls):
291
291
# We do this because 0.8 uses "soft error" and 8.1 uses "soft-error".
429
429
_ -> exit(method_field_shortstr_overflow)
432
-define(SHORTSTR_PROP(P, R, L, S, X),
433
if P =:= 0 -> {undefined, R};
434
true -> <<L:8/unsigned, S:L/binary, X/binary>> = R,
437
-define(TABLE_PROP(P, R, L, T, X),
438
if P =:= 0 -> {undefined, R};
439
true -> <<L:32/unsigned, T:L/binary, X/binary>> = R,
440
{rabbit_binary_parser:parse_table(T), X}
442
-define(OCTET_PROP(P, R, I, X),
443
if P =:= 0 -> {undefined, R};
444
true -> <<I:8/unsigned, X/binary>> = R,
447
-define(TIMESTAMP_PROP(P, R, I, X),
448
if P =:= 0 -> {undefined, R};
449
true -> <<I:64/unsigned, X/binary>> = R,
432
-define(SHORTSTR_VAL(R, L, V, X),
434
<<L:8/unsigned, V:L/binary, X/binary>> = R,
438
-define(LONGSTR_VAL(R, L, V, X),
440
<<L:32/unsigned, V:L/binary, X/binary>> = R,
444
-define(SHORT_VAL(R, L, V, X),
446
<<V:8/unsigned, X/binary>> = R,
450
-define(LONG_VAL(R, L, V, X),
452
<<V:32/unsigned, X/binary>> = R,
456
-define(LONGLONG_VAL(R, L, V, X),
458
<<V:64/unsigned, X/binary>> = R,
462
-define(OCTET_VAL(R, L, V, X),
464
<<V:8/unsigned, X/binary>> = R,
468
-define(TABLE_VAL(R, L, V, X),
470
<<L:32/unsigned, V:L/binary, X/binary>> = R,
471
{rabbit_binary_parser:parse_table(V), X}
474
-define(TIMESTAMP_VAL(R, L, V, X),
476
<<V:64/unsigned, X/binary>> = R,
480
-define(SHORTSTR_PROP(X, L),
483
if L < 256 -> <<L:8, X:L/binary>>;
484
true -> exit(content_properties_shortstr_overflow)
488
-define(LONGSTR_PROP(X, L),
494
-define(OCTET_PROP(X, L), <<X:8/unsigned>>).
495
-define(SHORT_PROP(X, L), <<X:16/unsigned>>).
496
-define(LONG_PROP(X, L), <<X:32/unsigned>>).
497
-define(LONGLONG_PROP(X, L), <<X:64/unsigned>>).
498
-define(TIMESTAMP_PROP(X, L), <<X:64/unsigned>>).
500
-define(TABLE_PROP(X, T),
502
T = rabbit_binary_generator:generate_table(X),
503
<<(size(T)):32, T/binary>>
453
506
version = "{%d, %d, %d}" % (spec.major, spec.minor, spec.revision)