Esempio n. 1
0
    def decode(self, data: ScaleBytes = None, check_remaining=True):

        if data is not None:
            self.decoded = False
            self.data = data

        if not self.decoded:

            self.data_start_offset = self.data.offset
            self.value_serialized = self.process()
            self.decoded = True

            if self.value_object is None:
                # Default for value_object if not explicitly defined
                self.value_object = self.value_serialized

            self.data_end_offset = self.data.offset

            if check_remaining and self.data.offset != self.data.length:
                raise RemainingScaleBytesNotEmptyException(
                    f'Decoding <{self.__class__.__name__}> - Current offset: {self.data.offset} / length: {self.data.length}'
                )

            if self.data.offset > self.data.length:
                raise RemainingScaleBytesNotEmptyException(
                    f'Decoding <{self.__class__.__name__}> - No more bytes available (needed: {self.data.offset} / total: {self.data.length})'
                )

        return self.value
Esempio n. 2
0
    def decode(self, check_remaining=True):
        self.value = self.process()

        if check_remaining and self.data.offset != self.data.length:
            raise RemainingScaleBytesNotEmptyException(
                'Current offset: {} / length: {}'.format(
                    self.data.offset, self.data.length))

        if self.data.offset > self.data.length:
            raise RemainingScaleBytesNotEmptyException(
                'No more bytes available (offset: {} / length: {})'.format(
                    self.data.offset, self.data.length))

        return self.value