def dict2pb(cls, adict, strict=False):
    """
    Takes a class representing the ProtoBuf Message and fills it with data from
    the dict.
    """
    obj = cls()
    for field in obj.DESCRIPTOR.fields:
        if not field.label == field.LABEL_REQUIRED:
            continue
        if field.has_default_value:
            continue
        if not field.name in adict:
            # raise ConvertException('Field "%s" missing from descriptor dictionary.' % field.name)
            print('Field "%s" missing from descriptor dictionary.' % field.name)

    if strict:
        field_names = set([field.name for field in obj.DESCRIPTOR.fields])
        for key in adict.keys():
            if key not in field_names:
                # raise ConvertException('Key "%s" can not be mapped to field in %s class.' % (key, type(obj)))
                print('Key "%s" can not be mapped to field in %s class.' % (key, type(obj)))

    for field in obj.DESCRIPTOR.fields:
        if not field.name in adict and not field.has_default_value:
            continue
        cur_value = adict[field.name] if field.name in adict else field.default_value
        msg_type = field.message_type
        if field.label == FD.LABEL_REPEATED:
            if field.type == FD.TYPE_MESSAGE:
                for sub_dict in cur_value:
                    item = getattr(obj, field.name).add()
                    item.CopyFrom(dict2pb(msg_type._concrete_class, sub_dict))
            else:
                map(getattr(obj, field.name).append, cur_value)
        else:
            if field.type == FD.TYPE_MESSAGE:
                value = dict2pb(msg_type._concrete_class, cur_value)
                getattr(obj, field.name).CopyFrom(value)
            else:
                setattr(obj, field.name, cur_value)
    return obj

    Takes a class representing the ProtoBuf Message and fills it with data from
    the dict.
    
example_rpc_client.py