示例#1
0
    def value(self, val):
        """
        Sets the option value.

        :param val: the value
        """
        if type(val) is str:
            val = bytearray(val, "utf-8")
        if type(val) is int and bit_len(val) != 0:
            val = val
        if type(val) is int and bit_len(val) == 0:
            val = bytearray()
        self._value = val
示例#2
0
    def value(self, val):
        """
        Sets the option value.

        :param val: the value
        """
        if type(val) is str:
            val = BitArray(bytes=val, length=len(val) * 8)
        if type(val) is int and bit_len(val) != 0:
            val = BitArray(uint=val, length=bit_len(val) * 8)
        if type(val) is int and bit_len(val) == 0:
            val = BitArray()
        assert(type(val) is BitArray)
        self._value = val
示例#3
0
    def length(self):
        """
        Get the len of the option value

        :return: the len of the option value
        """
        if isinstance(self._value, int):
            return bit_len(self._value * 8)
        return len(self._value)
示例#4
0
    def value(self):
        """
        Get the option value.


        :return: the option value as bytes
        """
        if type(self._value) is None:
            self._value = bytearray()
        name, opt_type, repeatable, defaults = defines.options[self._number]
        if opt_type == defines.INTEGER:
            if bit_len(self._value) > 0:
                return int(self._value)
            else:
                return defaults
        return self._value