def deserialize(cls, ori_msg, parse_content=True): """ convert a str or dict to a StreamMessage object :param ori_msg: str or list :param parse_content: whether parse content or not :return: StreamMessage object """ msg = jparser(ori_msg) # Version 28: [version, stream_id, stream_partition, timestamp, # ttl, offset, previous_offset, content_type, content] # Version 29: [version, stream_id, stream_partition, timestamp, # ttl,offset, previous_offset, content_type, content, # signature_type, address, signature] if msg[0] == 28 or msg[0] == 29: result = cls(*msg[1:]) if parse_content: result.get_parsed_content() return result else: raise UnsupportedVersionError(msg[0], 'Supported version: [ 28, 29]')
def deserialize(cls, msg): """ convert a str or dict to a StreamAndPartition object :param msg: dict :return: StreamAndPartition object """ msg = jparser(msg) stream_id = msg.get(StreamAndPartitionConstant.STREAM_ID, None) stream_partition = msg.get(StreamAndPartitionConstant.STREAM_PARTITION, None) return cls(stream_id, stream_partition)
def deserialize(cls, msg): """ convert msg to Request object :param msg: str or dict :return: Request object """ msg = jparser(msg) cls.check_version(msg) request_class = cls.response_class_by_response_type[msg[ RequestConstant.TYPE]] args = request_class.get_constructor_arguments(msg) return request_class(*args)
def deserialize(cls, msg): """ convert a str or dict to a ErrorPayload object :param msg: dict :return: ErrorPayload object """ msg = jparser(msg) if not msg.get(ErrorPayloadConstant.ERROR, False): raise ValueError('Invalid error payload. received : %s' % (json.dumps(msg))) else: return ErrorPayload(msg[ErrorPayloadConstant.ERROR])
def deserialize(cls, msg): """ convert a str or dict to a ResendResponsePayload object :param msg: dict :return: ResendResponsePayload object """ msg = jparser(msg) stream_id = msg.get(ResendResponsePayloadConstant.STREAM_ID, None) stream_partition = msg.get( ResendResponsePayloadConstant.STREAM_PARTITION, None) sub_id = msg.get(ResendResponsePayloadConstant.SUB_ID, None) return cls(stream_id, stream_partition, sub_id)
def deserialize(cls, ori_msg): """ deserialize from msg to response object :param ori_msg: str or dict :return: response object """ version, response_type, sub_id, payload_msg = jparser(ori_msg) cls.check_version(version) response_class = cls.response_class_by_response_type[response_type] payload = response_class.get_payload_class().deserialize(payload_msg) args = response_class.get_constructor_arguments(sub_id, payload) return response_class(*args)