diff options
Diffstat (limited to 'kafka/protocol/struct.py')
-rw-r--r-- | kafka/protocol/struct.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/kafka/protocol/struct.py b/kafka/protocol/struct.py index 693e2a2..e9da6e6 100644 --- a/kafka/protocol/struct.py +++ b/kafka/protocol/struct.py @@ -30,6 +30,7 @@ class Struct(AbstractType): # causes instances to "leak" to garbage self.encode = WeakMethod(self._encode_self) + @classmethod def encode(cls, item): # pylint: disable=E0202 bits = [] @@ -48,6 +49,11 @@ class Struct(AbstractType): data = BytesIO(data) return cls(*[field.decode(data) for field in cls.SCHEMA.fields]) + def get_item(self, name): + if name not in self.SCHEMA.names: + raise KeyError("%s is not in the schema" % name) + return self.__dict__[name] + def __repr__(self): key_vals = [] for name, field in zip(self.SCHEMA.names, self.SCHEMA.fields): |