     raw_decode_key(rest, result, groups)
   end
 
-  defp raw_handle_varint(:packed, <<>>, result, val, []), do: [val | result]
-  defp raw_handle_varint(:packed, <<>>, result, _val, _groups), do: result
-
-  defp raw_handle_varint(:packed, <<bin::bits>>, result, val, []) do
-    raw_decode_varint(bin, [val | result], :packed, [])
-  end
-
-  defp raw_handle_varint(:packed, <<bin::bits>>, result, _val, groups) do
-    raw_decode_varint(bin, result, :packed, groups)
-  end
-
-  defp raw_handle_key(wire_start_group(), opening, groups, bin, result) do
+  defp raw_handle_varint(:packed, <<>>, result, val, _groups), do: [val | result]
+
+  defp raw_handle_varint(:packed, <<bin::bits>>, result, val, groups) do
+    raw_decode_varint(bin, [val | result], :packed, groups)
+  end
+
+  defp raw_handle_key(wire_start_group(), opening, groups, <<bin::bits>>, result) do
     raw_decode_key(bin, result, [opening | groups])
   end
 
-  defp raw_handle_key(wire_end_group(), closing, [closing | groups], bin, result) do
+  defp raw_handle_key(wire_end_group(), closing, [closing | groups], <<bin::bits>>, result) do
     raw_decode_key(bin, result, groups)
   end
 

  end

  # packed
  defp put_packed_field(msg, %{wire_type: wire_type, type: type, name_atom: key}, val) do
    vals =
      decode_packed(wire_type, val, [])
      |> Enum.map(fn v ->
        decode_type_m(type, key, v)
      end)

    case msg do
      %{^key => nil} ->
        Map.put(msg, key, vals)

      %{^key => value} ->
        Map.put(msg, key, vals ++ value)

      %{} ->
        Map.put(msg, key, vals)
    end
  end

  defp decode_packed(_wire_type, <<>>, acc), do: acc

  defp decode_packed(wire_varint(), <<bin::bits>>, _) do
    raw_decode_varint(bin, [], :packed, [])
  end

  defp decode_packed(wire_32bits(), <<n::32, rest::bits>>, result) do
    decode_packed(wire_32bits(), rest, [<<n::32>> | result])
  end

  defp decode_packed(wire_64bits(), <<n::64, rest::bits>>, result) do
    decode_packed(wire_64bits(), rest, [<<n::64>> | result])
  end

  @doc false
  @spec decode_zigzag(integer) :: integer

    )
  end

  defp raw_handle_key(wire_type, tag, [], <<bin::bits>>, result) do
    raw_decode_value(wire_type, bin, [wire_type, tag | result], [])
  end

  defp raw_handle_key(wire_type, _tag, groups, <<bin::bits>>, result) do
    raw_decode_value(wire_type, bin, result, groups)
  end

