Exemplo n.º 1
0
    def bitSizeOf(self, bitPosition):
        """
        Returns length of array stored in the bit stream in bits.

        :param bitPosition: Current bit stream position.
        :returns: Length of the array stored in the bit stream in bits.
        """

        endBitPosition = bitPosition
        size = len(self._rawArray)
        if self._isAuto:
            endBitPosition += getBitSizeOfVarSize(size)

        if self._arrayTraits.HAS_BITSIZEOF_CONSTANT and size > 0:
            elementSize = self._arrayTraits.bitSizeOf()
            if self._setOffsetMethod is None:
                endBitPosition += size * elementSize
            else:
                endBitPosition += elementSize + (size - 1) * alignTo(
                    8, elementSize)
        else:
            for element in self._rawArray:
                if self._setOffsetMethod is not None:
                    endBitPosition = alignTo(8, endBitPosition)
                endBitPosition += self._arrayTraits.bitSizeOf(
                    endBitPosition, element)

        return endBitPosition - bitPosition
Exemplo n.º 2
0
 def testAlignTo(self):
     bitPosition = 5
     self.assertEqual(5, alignTo(0, bitPosition))
     self.assertEqual(5, alignTo(1, bitPosition))
     self.assertEqual(6, alignTo(2, bitPosition))
     self.assertEqual(6, alignTo(3, bitPosition))
     self.assertEqual(8, alignTo(4, bitPosition))
     self.assertEqual(5, alignTo(5, bitPosition))
     self.assertEqual(6, alignTo(6, bitPosition))
     self.assertEqual(7, alignTo(7, bitPosition))
     self.assertEqual(8, alignTo(8, bitPosition))
Exemplo n.º 3
0
    def initializeOffsets(self, bitPosition):
        """
        Initializes indexed offsets for the array.

        :param bitPosition: Current bit stream position.
        :returns: Updated bit stream position which points to the first bit after the array.
        """

        endBitPosition = bitPosition
        size = len(self._rawArray)
        if self._isAuto:
            endBitPosition += getBitSizeOfVarUInt64(size)

        for index in range(size):
            if self._setOffsetMethod is not None:
                endBitPosition = alignTo(8, endBitPosition)
                self._setOffsetMethod(index, endBitPosition)
            endBitPosition = self._arrayTraits.initializeOffsets(endBitPosition, self._rawArray[index])

        return endBitPosition