def METHOD_NAME(self, ty, **kwargs):
    idx = 8
    value = self.plm.types[ty]
    for field_name, field_size in self.plm.layouts[ty][1:]:
        try:
            fvalue = kwargs[field_name]
            del kwargs[field_name]
        except KeyError:
            fvalue = 0
        value = value | (fvalue << idx)
        idx += field_size
    if kwargs:
        raise ValueError
    return [
        self.packet_stb.eq(1),
        self.packet_buffer.eq(value),
        self.packet_last_n.eq(idx//self.ws-1)
    ]