import struct


def read_prelen_string(data, offset):
    """Read a string prefixed by its length from some data"""
    length, = struct.unpack('>H', data[offset:offset + 2])
    offset += 2
    end_off = offset + length
    if end_off > len(data):
        raise ValueError("String too large: {:#x} + {:#x} > {:#x}".format(offset, length, len(data)))
    return data[offset:end_off].decode('utf-8', 'replace'), end_off