def deserialize(self, data): fields = msgpack.unpackb(data, raw=False) if fields[0] == RECORD_TYPE_ID: stream, value = fields[1:] record = message.Record(value) record.stream = stream return record elif fields[0] == KEY_RECORD_TYPE_ID: stream, key, value = fields[1:] key_record = message.KeyRecord(key, value) key_record.stream = stream return key_record else: raise Exception("Unsupported type id {}, type {}".format( fields[0], type(fields[0])))
def process_element(self, record): key = self.func.key_by(record.value) self.collect(message.KeyRecord(key, record.value))