def test_binary_parsing():
    """Make sure we can parse binary node descriptors."""

    bin_node = b'\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x10\x008\xff\xff\x00\n\n\x00\x00\x00'
    str_node = parse_binary_descriptor(bin_node)
    assert str_node == '(system input 0 always) => unbuffered 15 using copy_latest_a'

    bin_node = b'\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x010\x020\x02\n\x05\x00\x00\x00'
    str_node = parse_binary_descriptor(bin_node)
    assert str_node == '(input 1 always && input 2 when count >= 1) => buffered 1 using copy_all_a'
Exemple #2
0
    def add_node(self, binary_descriptor):
        """Add a node to the sensor_graph using a binary node descriptor.

        Args:
            binary_descriptor (bytes): An encoded binary node descriptor.

        Returns:
            int: A packed error code.
        """

        try:
            node_string = parse_binary_descriptor(binary_descriptor)
        except:
            self._logger.exception("Error parsing binary node descriptor: %s", binary_descriptor)
            return _pack_sgerror(SensorGraphError.INVALID_NODE_STREAM)  # FIXME: Actually provide the correct error codes here

        try:
            self.graph.add_node(node_string)
        except NodeConnectionError:
            return _pack_sgerror(SensorGraphError.STREAM_NOT_IN_USE)
        except ProcessingFunctionError:
            return _pack_sgerror(SensorGraphError.INVALID_PROCESSING_FUNCTION)
        except ResourceUsageError:
            return _pack_sgerror(SensorGraphError.NO_NODE_SPACE_AVAILABLE)

        return Error.NO_ERROR
Exemple #3
0
    def FromBinary(cls, record_data, record_count=1):
        """Create an UpdateRecord subclass from binary record data.

        This should be called with a binary record blob (NOT including the
        record type header) and it will decode it into a AddNodeRecord.

        Args:
            record_data (bytearray): The raw record data that we wish to parse
                into an UpdateRecord subclass NOT including its 8 byte record header.
            record_count (int): The number of records included in record_data.

        Raises:
            ArgumentError: If the record_data is malformed and cannot be parsed.

        Returns:
            AddNodeRecord: The decoded reflash tile record.
        """

        _cmd, address, _resp_length, payload = cls._parse_rpc_info(record_data)

        descriptor = parse_binary_descriptor(payload)
        return AddNodeRecord(descriptor, address=address)