def _add_value(self, skey, vtyp, key, val, _deser, null_allowed):
if isinstance(val, list):<EOL><INDENT>if (len(val) == <NUM_LIT:0> or val[<NUM_LIT:0>] is None) and null_allowed is False:<EOL><INDENT>return<EOL><DEDENT><DEDENT>if isinstance(vtyp, tuple):<EOL><INDENT>vtyp = vtyp[<NUM_LIT:0>]<EOL><DEDENT>if isinstance(vtyp, list):<EOL><INDENT>vtype = vtyp[<NUM_LIT:0>]<EOL>if isinstance(val, vtype):<EOL><INDENT>if issubclass(vtype, Message):<EOL><INDENT>self._dict[skey] = [val]<EOL><DEDENT>elif _deser:<EOL><INDENT>try:<EOL><INDENT>self._dict[skey] = _deser(val, sformat="<STR_LIT>")<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise DecodeError(ERRTXT % (key, exc))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>setattr(self, skey, [val])<EOL><DEDENT><DEDENT>elif isinstance(val, list):<EOL><INDENT>if _deser:<EOL><INDENT>try:<EOL><INDENT>val = _deser(val, sformat="<STR_LIT>")<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise DecodeError(ERRTXT % (key, exc))<EOL><DEDENT><DEDENT>if issubclass(vtype, Message):<EOL><INDENT>try:<EOL><INDENT>_val = []<EOL>for v in val:<EOL><INDENT>_val.append(vtype(**dict([(str(x), y) for x, y<EOL>in v.items()])))<EOL><DEDENT>val = _val<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise DecodeError(ERRTXT % (key, exc))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for v in val:<EOL><INDENT>if not isinstance(v, vtype):<EOL><INDENT>raise DecodeError(<EOL>ERRTXT % (key, "<STR_LIT>" % (<EOL>vtype, type(v))))<EOL><DEDENT><DEDENT><DEDENT>self._dict[skey] = val<EOL><DEDENT>elif isinstance(val, dict):<EOL><INDENT>try:<EOL><INDENT>val = _deser(val, sformat="<STR_LIT>")<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise DecodeError(ERRTXT % (key, exc))<EOL><DEDENT>else:<EOL><INDENT>self._dict[skey] = val<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise DecodeError(ERRTXT % (key, "<STR_LIT>" % vtype))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if val is None:<EOL><INDENT>self._dict[skey] = None<EOL><DEDENT>elif isinstance(val, bool):<EOL><INDENT>if vtyp is bool:<EOL><INDENT>self._dict[skey] = val<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(val, skey))<EOL><DEDENT><DEDENT>elif isinstance(val, vtyp):  <EOL><INDENT>self._dict[skey] = val<EOL><DEDENT>else:<EOL><INDENT>if _deser:<EOL><INDENT>try:<EOL><INDENT>val = _deser(val, sformat="<STR_LIT>")<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise DecodeError(ERRTXT % (key, exc))<EOL><DEDENT>else:<EOL><INDENT>self._dict[skey] = val<EOL><DEDENT><DEDENT>elif vtyp is int:<EOL><INDENT>try:<EOL><INDENT>self._dict[skey] = int(val)<EOL><DEDENT>except (ValueError, TypeError):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(val,<EOL>skey))<EOL><DEDENT><DEDENT>elif vtyp is bool:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(val, skey))<EOL><DEDENT>elif vtyp != type(val):<EOL><INDENT>if vtyp == Message:<EOL><INDENT>if type(val) == dict or isinstance(val, str):<EOL><INDENT>self._dict[skey] = val<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(<EOL>val, skey))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(val,<EOL>skey))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Main method for adding a value to the instance. Does all the
checking on type of value and if among allowed values.

:param skey: string version of the key 
:param vtyp: Type of value
:param key: original representation of the key
:param val: The value to add
:param _deser: A deserializer for this value type
:param null_allowed: Whether null is an allowed value for this key