import struct


def unpack_sample(message):
    """Convert a binary message from the Shadow data stream into a Python dict

    message -- bytes from the data stream

    Returns dict object
    """
    #
    # Format of one sample from the configurable data service. All data is
    # little endian and 4 bytes (unsigned, float C types).
    #
    # node =
    #   [key] [N] [N values]
    #   [unsigned] [unsigned] [float, ...]
    #
    # message = [node, ...]
    #
    sample = {}

    i = 0
    while i < len(message):
        (key, length) = struct.unpack_from('<2I', message, i)
        i += 2 * 4

        sample[key] = struct.unpack_from(f'<{length}f', message, i)
        i += length * 4

    return sample