summaryrefslogtreecommitdiff
path: root/codegen.py
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2010-11-08 23:39:46 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2010-11-08 23:39:46 +0000
commitdbc68a83f0e65b2fb6c2e6ff3f71b23f31735c2e (patch)
tree03a2d38280600d52684ed0d8693a470beb930b43 /codegen.py
parentfec392a0b7c3f59b8f26f92fa1f65ce469596374 (diff)
downloadrabbitmq-server-git-dbc68a83f0e65b2fb6c2e6ff3f71b23f31735c2e.tar.gz
refactor: extract shortstr size check
Diffstat (limited to 'codegen.py')
-rw-r--r--codegen.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/codegen.py b/codegen.py
index 02b06f68aa..71ce8ada6a 100644
--- a/codegen.py
+++ b/codegen.py
@@ -276,8 +276,7 @@ def genErl(spec):
print " F%dTab = rabbit_binary_generator:generate_table(F%d)," % (f.index, f.index)
print " F%dLen = size(F%dTab)," % (f.index, f.index)
elif type == 'shortstr':
- print " F%dLen = size(F%d)," % (f.index, f.index)
- print " if F%dLen > 255 -> exit(method_field_shortstr_overflow); true -> ok end," % (f.index)
+ print " F%dLen = shortstr_size(F%d)," % (f.index, f.index)
elif type == 'longstr':
print " F%dLen = size(F%d)," % (f.index, f.index)
else:
@@ -424,6 +423,12 @@ def genErl(spec):
bitvalue(true) -> 1;
bitvalue(false) -> 0;
bitvalue(undefined) -> 0.
+
+shortstr_size(S) ->
+ case size(S) of
+ Len when Len =< 255 -> Len;
+ _ -> exit(method_field_shortstr_overflow)
+ end.
"""
version = "{%d, %d, %d}" % (spec.major, spec.minor, spec.revision)
if version == '{8, 0, 0}': version = '{0, 8, 0}'