Skip to content

Commit

Permalink
Fix bounds
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carlstrom <[email protected]>
  • Loading branch information
InvincibleRMC committed Mar 29, 2024
1 parent 0c197cb commit 9a75f48
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mqtt_ros_bridge/encodings.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
from array import array
from typing import (Any, Iterable, MutableSequence, Protocol, Type, TypeAlias,
from typing import (Iterable, MutableSequence, Protocol, Type, TypeAlias,
TypeVar, cast)

from numpy import ndarray
from numpy import ndarray, floating, integer
from numpy.typing import NDArray
from rclpy.type_support import check_is_valid_msg_type

Expand All @@ -21,13 +21,15 @@ def get_fields_and_field_types(cls) -> dict[str, str]:
MsgLikeT = TypeVar("MsgLikeT", bound=MsgLike)
ArrayElementT = TypeVar('ArrayElementT', int, float, str)


RESERVED_FIELD_TYPE = '/'
ENCODING = 'latin-1'


def numpy_encoding(array_arg: NDArray[Any]) -> list[int]:
return [int(x) for x in array_arg]
def numpy_encoding(array_arg: NDArray[integer] | NDArray[floating]) -> list[int] | list[float]:
if isinstance(array_arg[0], integer):
return [int(x) for x in array_arg]
else:
return [float(x) for x in array_arg]


def array_encoding(array_arg: MutableSequence[ArrayElementT]) -> list[ArrayElementT]:
Expand Down

0 comments on commit 9a75f48

Please sign in to comment.