         end
     end
 
-    {fields_to_map(fields_and_values), rest}
-  end
-
-  defp fields_to_map(fields_and_values) do
+    {build_fields(fields_and_values), rest}
+  end
+
+  defp build_fields(fields_and_values) do
     for {field, value} <- fields_and_values, into: %{} do
-      {field_name(field), value}
+      {named_field(field, :name), value}
     end
   end
 

    end

    # TODO: the '7' here is the hardcoded code for the 'string' type.
    [encode_type(name, :string), <<ptr :: 32-signed>>, 7]
  end

  # Encodes an instance of `type`. Returns an iodata instead of a binary.

  defp encode_fields(fields, offset) do
    fields =
      for {name, value} <- fields do
        type = infer_type_from_term(value)
        field = named_field(name: name, data_type: type)
        value = encode_type(value, type)
        {field, value}
      end

