import struct


def avpair(code, data):
    """make an AVPAIR structure
    @param code: the attribute ID
    @type code: L{int}
    @param data: the value
    @type value: L{bytes}, or L{str} which is converted UTF-16
    @rtype: L{bytes}
    """
    if type(data) is str:
        data = data.encode("utf-16le")
    elif len(data) % 2 > 0:
        data += b'\0'
    return struct.pack("<HH", code, len(data)) + data