diff --git a/src/genpy/generate_numpy.py b/src/genpy/generate_numpy.py index 0a7515c..091326e 100644 --- a/src/genpy/generate_numpy.py +++ b/src/genpy/generate_numpy.py @@ -56,11 +56,11 @@ 'byte' : 'numpy.int8', } # TODO: this doesn't explicitly specify little-endian byte order on the numpy data instance -def unpack_numpy(var, count, dtype, buff): +def unpack_numpy(var, offset, count, dtype, buff): """ create numpy deserialization code """ - return var + " = numpy.frombuffer(%s, dtype=%s, count=%s)"%(buff, dtype, count) + return var + " = numpy.frombuffer(%s, dtype=%s, count=%s, offset=%s)"%(buff, dtype, count, offset) def pack_numpy(var): """ diff --git a/src/genpy/generator.py b/src/genpy/generator.py index f4038bf..37e97b7 100644 --- a/src/genpy/generator.py +++ b/src/genpy/generator.py @@ -491,7 +491,7 @@ def array_serializer_generator(msg_context, package, type_, name, serialize, is_ yield "end += struct.calcsize(pattern)" if is_numpy: dtype = NUMPY_DTYPE[base_type] - yield unpack_numpy(var, 'length', dtype, 'str[start:end]') + yield unpack_numpy(var, 'start', 'length', dtype, 'str') else: yield unpack2(var, 'pattern', 'str[start:end]') else: @@ -506,7 +506,7 @@ def array_serializer_generator(msg_context, package, type_, name, serialize, is_ yield "end += %s"%struct.calcsize('<%s'%pattern) if is_numpy: dtype = NUMPY_DTYPE[base_type] - yield unpack_numpy(var, length, dtype, 'str[start:end]') + yield unpack_numpy(var, 'start', length, dtype, 'str') else: yield unpack(var, pattern, 'str[start:end]') if not serialize and base_type == 'bool': diff --git a/test/files/array/int16_fixed_deser_np.txt b/test/files/array/int16_fixed_deser_np.txt index 453eed4..18b6bf1 100644 --- a/test/files/array/int16_fixed_deser_np.txt +++ b/test/files/array/int16_fixed_deser_np.txt @@ -1,3 +1,3 @@ start = end end += 20 -data = numpy.frombuffer(str[start:end], dtype=numpy.int16, count=10) +data = numpy.frombuffer(str, dtype=numpy.int16, count=10, offset=start) diff --git a/test/files/array/int16_varlen_deser_np.txt b/test/files/array/int16_varlen_deser_np.txt index a8ea16b..5915f15 100644 --- a/test/files/array/int16_varlen_deser_np.txt +++ b/test/files/array/int16_varlen_deser_np.txt @@ -4,4 +4,4 @@ end += 4 pattern = '<%sh'%length start = end end += struct.calcsize(pattern) -data = numpy.frombuffer(str[start:end], dtype=numpy.int16, count=length) +data = numpy.frombuffer(str, dtype=numpy.int16, count=length, offset=start)