blueye.sdk.utils - Blueye SDK

Skip to content

# blueye.sdk.utils

## `` utils

Functions:

- `deserialize_any_to_message` –

  Deserialize a protobuf Any message to a concrete message type.

- `is_scalar_type` –

  Check if a message is a scalar type

- `open_local_documentation` –

  Open a pre-built local version of the SDK documentation

### `` deserialize_any_to_message

    deserialize_any_to_message(
        msg: Any,
    ) -> Tuple[MessageMeta, Message]

Deserialize a protobuf Any message to a concrete message type.

Parameters:

- `msg` (`Any`) –

  The Any message to deserialize. Needs to be a message defined in the blueye.protocol package or a well-known-type (FloatValue, Int32Value, etc) from google.protobuf.wrappers_pb2

Returns:

- `Tuple[MessageMeta, Message]` –

  A tuple with the message type and the deserialized message.

Source code in `blueye/sdk/utils.py`

    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    def deserialize_any_to_message(msg: Any) -> Tuple[proto.message.MessageMeta, proto.message.Message]:
        """Deserialize a protobuf Any message to a concrete message type.

        Args:
            msg (Any): The Any message to deserialize. Needs to be a message defined in the
                       blueye.protocol package or a well-known-type (FloatValue, Int32Value, etc) from
                       google.protobuf.wrappers_pb2

        Returns:
            A tuple with the message type and the deserialized message.
        """
        if msg.type_url.startswith("type.googleapis.com/google.protobuf"):
            payload_msg_name = msg.type_url.replace("type.googleapis.com/google.protobuf.", "")
            payload_type = wrappers.__getattribute__(payload_msg_name)
            payload_msg_deserialized = payload_type.FromString(msg.value)
            return (payload_type, payload_msg_deserialized)

        payload_msg_name = msg.type_url.replace("type.googleapis.com/blueye.protocol.", "")
        payload_type = bp.__getattribute__(payload_msg_name)
        payload_msg_deserialized = payload_type.deserialize(msg.value)
        return (payload_type, payload_msg_deserialized)

### `` is_scalar_type

    is_scalar_type(msg: Message) -> bool

Check if a message is a scalar type

Parameters:

- `msg` (`Message`) –

  The message to check

Returns:

- `bool` –

  True if the message is a scalar type, False otherwise

Source code in `blueye/sdk/utils.py`

    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    def is_scalar_type(msg: proto.message.Message) -> bool:
        """Check if a message is a scalar type

        Args:
            msg (proto.message.Message): The message to check

        Returns:
            True if the message is a scalar type, False otherwise
        """

        scalar_types = (
            FloatValue,
            Int32Value,
            Int64Value,
            UInt32Value,
            UInt64Value,
            DoubleValue,
            BoolValue,
            StringValue,
            BytesValue,
        )
        return isinstance(msg, scalar_types)

### `` open_local_documentation

    open_local_documentation()

Open a pre-built local version of the SDK documentation

Useful when you are connected to the drone wifi, and don't have access to the online version.

Source code in `blueye/sdk/utils.py`

    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    def open_local_documentation():
        """Open a pre-built local version of the SDK documentation

        Useful when you are connected to the drone wifi, and don't have access to the online version.
        """
        sdk_path = os.path.dirname(blueye.sdk.__file__)

        # The documentation is located next to the top-level package so we move up a couple of levels
        documentation_path = os.path.abspath(sdk_path + "/../../blueye.sdk_docs/index.html")

        webbrowser.open(documentation_path)