Empty arrays of custom message types

My Environment

  1. Ubuntu 20.04
  2. Python 3.8.10
  3. Installed via pip
  4. Version: 0.9.9

The Issue

Two similar issues, potentially both related to #14 (closed)

  1. serialize_cdr doesn't seem to support empty lists (though numpy arrays work, for builtin types at least). See the float_array_msg example below.
  2. More pressing, I can't get empty arrays to serialize for custom messages. See the test_array_msg example below.

Steps to Reproduce

import numpy as np

from rosbags.serde import serialize_cdr
from rosbags.typesys import get_types_from_msg, register_types

FLOAT_ARRAY_MSG = """
float64[] float_array
"""

TEST_MSG = """
float64 test
"""

TEST_ARRAY_MSG = """
custom_msgs/Test[] test_array
"""

register_types(get_types_from_msg(FLOAT_ARRAY_MSG, 'custom_msgs/msg/FloatArray'))
register_types(get_types_from_msg(TEST_MSG, 'custom_msgs/msg/Test'))
register_types(get_types_from_msg(TEST_ARRAY_MSG, 'custom_msgs/msg/TestArray'))

# pylint: disable=no-name-in-module,wrong-import-position
from rosbags.typesys.types import custom_msgs__msg__FloatArray as FloatArray  # type: ignore  # noqa
from rosbags.typesys.types import custom_msgs__msg__Test as Test  # type: ignore  # noqa
from rosbags.typesys.types import custom_msgs__msg__TestArray as TestArray  # type: ignore  # noqa
# pylint: enable=no-name-in-module,wrong-import-position

# Doesn't work (AttributeError: 'list' object has no attribute 'view')
float_array_msg = FloatArray(float_array=[])
# But this does work
# float_array_msg = FloatArray(float_array=np.array([], dtype=np.float64))
rawdata = serialize_cdr(float_array_msg, float_array_msg.__msgtype__)

test_msg = Test(test=42.0)
test_array = []
# Works when for loop uncommented (otherwise: "in serialize_cdr \ assert pos + 4 == size \ AssertionError")
# for _ in range(3):
#     test_array.append(test_msg)
test_array_msg = TestArray(test_array=test_array)
rawdata = serialize_cdr(test_array_msg, test_array_msg.__msgtype__)