def assign(attrs)
      __beefcake_fields__.values.each do |fld|
        attribute = attrs[fld.name]

        if attribute.nil?
          self[fld.name] = nil
          next
        end

        unless fld.is_protobuf?
          self[fld.name] = attribute
          next
        end

        if fld.repeated? && attribute.is_a?(Hash)
          self[fld.name] = fld.type.new(attribute)
          next
        end

        if fld.repeated? && attribute.is_a?(fld.type)
          self[fld.name] = [attribute]
          next
        end

        if fld.repeated?
          self[fld.name] = attribute.map do |i|
            fld.matches_type?(i) ? i : fld.type.new(i)
          end
          next
        end

        if fld.matches_type? attribute
          self[fld.name] = attribute
          next
        end

        self[fld.name] = fld.type.new(attribute)
      end
      self
    end
def assign(attrs)
      __beefcake_fields__.values.each do |fld|
        attribute = attrs[fld.name]

        if attribute.nil?
          self[fld.name] = nil
          next
        end

        unless fld.is_protobuf?
          self[fld.name] = attribute
          next
        end

        if fld.repeated? && attribute.is_a?(Hash)
          self[fld.name] = fld.type.new(attribute)
          next
        end

        if fld.repeated? && attribute.is_a?(fld.type)
          self[fld.name] = [attribute]
          next
        end

        if fld.repeated?
          self[fld.name] = attribute.map do |i|
            fld.matches_type?(i) ? i : fld.type.new(i)
          end
          next
        end

        if fld.matches_type? attribute
          self[fld.name] = attribute
          next
        end

        self[fld.name] = fld.type.new(attribute)
      end
      self
    end
(see #assign)
 Handles filling a protobuf message from a hash. Embedded messages can
 be passed in two ways, by a pure hash or as an instance of embedded class(es).

 @example By a pure hash.
   {:field1 => 2, :embedded => {:embedded_f1 => 'lala'}}

 @example Repeated embedded message by a pure hash.
   {:field1 => 2, :embedded => [
     {:embedded_f1 => 'lala'},
     {:embedded_f1 => 'lulu'}
   ]}

 @example As an instance of embedded class.
   {:field1 => 2, :embedded => EmbeddedMsg.new({:embedded_f1 => 'lala'})}

 @param [Hash] data to fill a protobuf message with.