code: def _assign_to_field(obj, name, val):
      'Helper to assign an arbitrary value to a protobuf field'
      target = getattr(obj, name)
  
      if isinstance(target, containers.RepeatedScalarFieldContainer):
          target.append(val)
      elif isinstance(target, containers.RepeatedCompositeFieldContainer):
          target = target.add()
          target.CopyFrom(val)
      elif isinstance(target, (int, float, bool, str, bytes)):
          setattr(obj, name, val)
      elif isinstance(target, message.Message):
          target.CopyFrom(val)
      else:
          raise RuntimeError("Unsupported type: {}".format(type(target))f _assign_to_field(obj, name, val):
      'Helper to assign an arbitrary value to a protobuf field'
      target = getattr(obj, name)
  
      if isinstance(target, containers.RepeatedScalarFieldContainer):
          target.append(val)
      elif isinstance(target, containers.RepeatedCompositeFieldContainer):
          target = target.add()
          target.CopyFrom(val)
      elif isinstance(target, (int, float, bool, str, bytes)):
          setattr(obj, name, val)
      elif isinstance(target, message.Message):
          target.CopyFrom(val)
      else:
          raise RuntimeError("Unsupported type: {}".format(type(target)))
docs: Helper to assign an arbitrary value to a protobuf field