@classmethod<EOL><INDENT>def read(cls, data,<EOL>protocol=None,<EOL>fallback_protocol=TBinaryProtocol,<EOL>finagle_thrift=False,<EOL>max_fields=MAX_FIELDS,<EOL>max_list_size=MAX_LIST_SIZE,<EOL>max_map_size=MAX_MAP_SIZE,<EOL>max_set_size=MAX_SET_SIZE,<EOL>read_values=False):<DEDENT>
<EOL>if len(data) < cls.MIN_MESSAGE_SIZE:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if protocol is None:<EOL><INDENT>protocol = cls.detect_protocol(data, fallback_protocol)<EOL><DEDENT>trans = TTransport.TMemoryBuffer(data)<EOL>proto = protocol(trans)<EOL>header = None<EOL>if finagle_thrift:<EOL><INDENT>try:<EOL><INDENT>header = ThriftStruct.read(<EOL>proto,<EOL>max_fields,<EOL>max_list_size,<EOL>max_map_size,<EOL>max_set_size,<EOL>read_values)<EOL><DEDENT>except:<EOL><INDENT>trans = TTransport.TMemoryBuffer(data)<EOL>proto = protocol(trans)<EOL><DEDENT><DEDENT>method, mtype, seqid = proto.readMessageBegin()<EOL>mtype = cls.message_type_to_str(mtype)<EOL>if len(method) == <NUM_LIT:0> or method.isspace() or method.startswith('<STR_LIT:U+0020>'):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if len(method) > cls.MAX_METHOD_LENGTH:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>valid = range(<NUM_LIT>, <NUM_LIT>)<EOL>if any(ord(char) not in valid for char in method):<EOL><INDENT>raise ValueError('<STR_LIT>' % method)<EOL><DEDENT>args = ThriftStruct.read(<EOL>proto,<EOL>max_fields,<EOL>max_list_size,<EOL>max_map_size,<EOL>max_set_size,<EOL>read_values)<EOL>proto.readMessageEnd()<EOL>msglen = trans._buffer.tell()<EOL>return cls(method, mtype, seqid, args, header, msglen), msglen<EOL>
tries to deserialize a message, might fail if data is missing