Skip to content

Commit 78f1ebf

Browse files
committed
Merge branch 'pr4' into rolling
2 parents c21b523 + b008191 commit 78f1ebf

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

ros2_numpy/point_cloud2.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
__docformat__ = "restructuredtext en"
3939

40+
import sys
41+
4042
from .registry import converts_from_numpy, converts_to_numpy
4143

4244
import array
@@ -59,15 +61,6 @@
5961
pftype_to_nptype = dict(type_mappings)
6062
nptype_to_pftype = dict((nptype, pftype) for pftype, nptype in type_mappings)
6163

62-
# sizes (in bytes) of PointField types
63-
pftype_sizes = {PointField.INT8: 1,
64-
PointField.UINT8: 1,
65-
PointField.INT16: 2,
66-
PointField.UINT16: 2,
67-
PointField.INT32: 4,
68-
PointField.UINT32: 4,
69-
PointField.FLOAT32: 4,
70-
PointField.FLOAT64: 8}
7164

7265
@converts_to_numpy(PointField, plural=True)
7366
def fields_to_dtype(fields, point_step):
@@ -87,7 +80,7 @@ def fields_to_dtype(fields, point_step):
8780
dtype = np.dtype((dtype, f.count))
8881

8982
np_dtype_list.append((f.name, dtype))
90-
offset += pftype_sizes[f.datatype] * f.count
83+
offset += pftype_to_nptype[f.datatype].itemsize * f.count
9184

9285
# might be extra padding between points
9386
while offset < point_step:
@@ -160,7 +153,7 @@ def array_to_pointcloud2(cloud_arr, stamp=None, frame_id=None):
160153
cloud_msg.height = cloud_arr.shape[0]
161154
cloud_msg.width = cloud_arr.shape[1]
162155
cloud_msg.fields = dtype_to_fields(cloud_arr.dtype)
163-
cloud_msg.is_bigendian = False # assumption
156+
cloud_msg.is_bigendian = sys.byteorder != 'little'
164157
cloud_msg.point_step = cloud_arr.dtype.itemsize
165158
cloud_msg.row_step = cloud_msg.point_step*cloud_arr.shape[1]
166159
cloud_msg.is_dense = \

ros2_numpy/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import functools
2-
import collections
2+
from collections.abc import Sequence
33

44
_to_numpy = {}
55
_from_numpy = {}
@@ -21,7 +21,7 @@ def numpify(msg, *args, **kwargs):
2121
return
2222

2323
conv = _to_numpy.get((msg.__class__, False))
24-
if not conv and isinstance(msg, collections.Sequence):
24+
if not conv and isinstance(msg, Sequence):
2525
if not msg:
2626
raise ValueError("Cannot determine the type of an empty Collection")
2727
conv = _to_numpy.get((msg[0].__class__, True))

0 commit comments

Comments
 (0)