   defp infer_type(val) when is_list(val),    do: :embedded_list
   defp infer_type(val) when is_map(val),     do: :embedded_map
   defp infer_type(val) when is_nil(val),     do: :boolean # irrelevant
-  defp infer_type({type, _value}), do: type
 
   # http://orientdb.com/docs/last/Types.html
   @types [

    [encode_value(name), <<ptr :: 32-signed>>, type_to_int(type)]
  end

  @doc false
  def encode_value(value, offset \\ 0)

  def encode_value({type, value}, offset) do
    encode_type(value, type, offset)
  end

  def encode_value(value, offset) do
    encode_type(value, infer_type(value), offset)
  end

  defp encode_type(value, type, offset)


    [Enum.reverse(fields), 0, Enum.reverse(values)]
  end

  defp header_offset(fields) do
    # The last +1 is for the `0` that signals the end of the header.
    fields
