def test_from_ctype(self): ae = self.assertEqual data_le = b"\xBD\x42\x57\xAE" hresult = hresult_le.from_buffer_copy(data_le) hresult = HRESULT.from_ctype(hresult) ae(hresult.s, 1) ae(hresult.r, 0) ae(hresult.c, 1) ae(hresult.n, 0) ae(hresult.x, 1) ae(hresult.facility, 0x0657) ae(hresult.code, 0x42BD)
def from_stream(cls, stream, offset=None, byte_order=LITTLE_ENDIAN): """Creates a ``HRESULT`` object from a stream. :type stream: :class:`lf.dec.IStream` :param stream: A stream that contains the HRESULT structure. :type offset: ``int`` or ``None`` :param offset: The start of the HRESULT structure in the stream. :type byte_order: constant :param byte_order: The byte order to use (from :mod:`lf.dtypes`) :rtype: :class:`HRESULT` :returns: The extracted :class:`HRESULT` object. """ if offset is not None: stream.seek(offset, SEEK_SET) # end if data = stream.read(4) if byte_order == LITTLE_ENDIAN: hresult = hresult_le.from_buffer_copy(data) else: hresult = hresult_be.from_buffer_copy(data) # end if return HRESULT(( hresult.code, hresult.facility, hresult.x, hresult.n, hresult.c, hresult.r, hresult.s ))