Skip to content

compas_pb.core ¤

Functions:¤

any_from_pb ¤

any_from_pb(proto_data: AnyData) -> Data | int | float | bool | str | bytes

Convert a protobuf message to a supported object.

Parameters:

  • proto_data (:class: `compas_pb.generated.message_pb2.AnyData`) –

    The protobuf message type of AnyData.

Returns:

any_to_pb ¤

any_to_pb(obj: Data | int | float | bool | str | bytes) -> AnyData

Convert any object to a protobuf any message.

Parameters:

  • obj (Data | list | dict | int | float | bool | str) –

    The object to convert. Can be a COMPAS Data object, list, dict, or primitive type.

Returns:

  • :class: `compas_pb.generated.message_pb2.AnyData`

    The protobuf message type of AnyData.

deserialize_message ¤

deserialize_message(binary_data) -> list | dict

Deserialize a top-level protobuf message.

Parameters:

  • binary_data (bytes) –

    The binary data to be deserialized.

Returns:

  • message ( list | dict ) –

    The deserialized protobuf message.

deserialize_message_bts ¤

deserialize_message_bts(binary_data) -> MessageData

Deserialize a binary data into bytes string.

Parameters:

  • binary_data (bytes) –

    The binary data to be deserialized.

Returns:

  • message_data ( MessageData ) –

    The protobuf message data.

deserialize_message_from_json ¤

deserialize_message_from_json(json_data: str) -> dict

Deserialize a top-level protobuf message into dictionary.

Parameters:

  • json_data (str) –

    A JSON string representation of the data.

Returns:

  • message ( dict ) –

    The deserialized protobuf message as a dictionary.

primitive_from_pb ¤

primitive_from_pb(primitive: AnyData) -> int | float | bool | str | bytes

Convert a protobuf message to a python native type.

Parameters:

  • proto_data (:class: `compas_pb.generated.message_pb2.AnyData`) –

    The protobuf message type of Anydata(contains struct_pb2.Value).

Returns:

primitive_to_pb ¤

primitive_to_pb(obj: int | float | bool | str | bytes) -> AnyData

Convert a python native type to a protobuf message.

Parameters:

  • obj (:class: `int`, `float`, `bool`, `str`, `bytes`) –

    The python native type to convert.

Returns:

  • class: `compas_pb.generated.message_pb2.AnyData`

    The protobuf message type of AnyData.

serialize_message ¤

serialize_message(data) -> MessageData

Serialize a top-level protobuf message.

Parameters:

  • data (object) –

    The data to be serialized. This can be a COMPAS object, a list of objects, or a dictionary.

Returns:

  • message ( MessageData ) –

serialize_message_bts ¤

serialize_message_bts(data) -> bytes

Serialize a top-level protobuf message.

Parameters:

  • data (object) –

    The data to be serialized. This can be a COMPAS object, a list of objects, or a dictionary.

Returns:

  • message ( bytes ) –

    The serialized protobuf message as bytes.

serialize_message_to_json ¤

serialize_message_to_json(data) -> dict

Serialize a top-level protobuf message.

Parameters:

  • data (object) –

    The data to be serialized. This can be a COMPAS object, a list of objects, or a dictionary.

Returns:

  • message ( dict ) –

    The serialized protobuf message as a dictionary.