From 9637c6b5095e9fadc895288508888c4c54c8de91 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Sun, 14 Oct 2007 02:21:59 +0000 Subject: Enabled packed struct encoding in python, cpp, and java. Also fixed computation of required byte credit in Message.cpp. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@584474 13f79535-47bb-0310-9956-ffa450edef68 --- python/qpid/spec.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'python/qpid/spec.py') diff --git a/python/qpid/spec.py b/python/qpid/spec.py index 2542ccc3e1..31c79276aa 100644 --- a/python/qpid/spec.py +++ b/python/qpid/spec.py @@ -29,7 +29,7 @@ class so that the generated code can be reused in a variety of situations. """ -import re, textwrap, new, mllib +import re, textwrap, new, mllib, qpid class SpecContainer: @@ -115,6 +115,10 @@ class Spec(Metadata): klass, meth = parts return self.classes.byname[klass].methods.byname[meth] + def struct(self, name): + type = self.domains.byname[name].type + return qpid.Struct(type) + def define_module(self, name, doc = None): module = new.module(name, doc) module.__file__ = self.file @@ -303,14 +307,26 @@ class Field(Metadata): else: return Method.DEFAULTS[self.type] +WIDTHS = { + "octet": 1, + "short": 2, + "long": 4 + } + +def width(st, default=None): + if st in (None, "none", ""): + return default + else: + return WIDTHS[st] + def get_result(nd, spec): result = nd["result"] if not result: return None name = result["@domain"] if name != None: return spec.domains.byname[name] st_nd = result["struct"] - st = Struct(st_nd["@size"], int(result.parent.parent["@index"])*256 + - int(st_nd["@type"]), st_nd["@pack"]) + st = Struct(width(st_nd["@size"]), int(result.parent.parent["@index"])*256 + + int(st_nd["@type"]), width(st_nd["@pack"], 2)) spec.structs[st.type] = st load_fields(st_nd, st.fields, spec.domains.byname) return st @@ -366,7 +382,7 @@ def load(specfile, *errata): code = st_nd["@type"] if code not in (None, "", "none"): code = int(code) - type = Struct(st_nd["@size"], code, st_nd["@pack"]) + type = Struct(width(st_nd["@size"]), code, width(st_nd["@pack"], 2)) if type.type != None: spec.structs[type.type] = type structs.append((type, st_nd)) -- cgit v1.2.1