Example #1
0
    def from_stream(cls, stream, offset=None, byte_order=LITTLE_ENDIAN):
        """Creates a ``Decimal`` object from a stream.

        :type stream: :class:`lf.dec.IStream`
        :param stream: A stream that contains the CURRENCY structure.

        :type offset: ``int`` or ``None``
        :param offset: The start of the CURRENCY structure in the stream.

        :type byte_order: constant
        :param byte_order: The byte order to use (from :mod:`lf.dtypes`)

        :rtype: ``Decimal``
        :returns: The corresponding ``Decmial`` object.

        """
        if offset is not None:
            stream.seek(offset, SEEK_SET)
        # end if

        data = stream.read(8)

        if byte_order == LITTLE_ENDIAN:
            value = int64_le.from_buffer_copy(data).value
        else:
            value = int64_be.from_buffer_copy(data).value
        # end if

        return Decimal(value) / Decimal(10000)
Example #2
0
    def int64_le(self, offset=None):
        """Reads a signed 64-bit integer (little endian).

        :type offset: :class:`int` or :keyword:`None`
        :param offset: The start of the integer.

        :except ValueError: if :attr:`stream` (starting at :attr:`offset` is
                            too small.)

        :rtype: :class:`int`
        :returns: The corresponding value.

        """
        if offset is not None:
            self.stream.seek(offset, SEEK_SET)
        # end if

        return int64_le.from_buffer_copy(self.stream.read(8)).value