Skip to content

Commit

Permalink
Do not restrict payload encoding to specific input
Browse files Browse the repository at this point in the history
  • Loading branch information
Strech committed Apr 25, 2024
1 parent cba3ba8 commit fe58fab
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/avrora/codec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ defmodule Avrora.Codec do
<<72, 48, 48, 48, 48, 48, 48, 48, 48, 45, 48, 48, 48, 48, 45, 48, 48, 48, 48, 45, 48, 48, 48,
48, 45, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 123, 20, 174, 71, 225, 250, 47, 64>>
"""
# TODO: Define encodable types
@callback encode(payload :: binary() | map(), options :: keyword(Avrora.Schema.t())) ::
@callback encode(payload :: term(), options :: keyword(Avrora.Schema.t())) ::
{:ok, result :: binary()} | {:error, reason :: term()}
end
2 changes: 1 addition & 1 deletion lib/avrora/codec/object_container_file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Avrora.Codec.ObjectContainerFile do
end

@impl true
def encode(payload, schema: schema) when is_binary(payload) or is_map(payload) do
def encode(payload, schema: schema) do
with {:ok, schema} <- resolve(schema),
{:ok, body} <- Codec.Plain.encode(payload, schema: schema),
{:ok, schema} <- SchemaEncoder.to_erlavro(schema) do
Expand Down
1 change: 0 additions & 1 deletion lib/avrora/codec/plain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ defmodule Avrora.Codec.Plain do
with {:ok, schema} <- resolve(schema), do: do_decode(payload, schema)
end

# FIXME payload could be anything? We need a type!
@impl true
def encode(payload, schema: schema) do
with {:ok, schema} <- resolve(schema), do: do_encode(payload, schema)
Expand Down
2 changes: 1 addition & 1 deletion lib/avrora/codec/schema_registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule Avrora.Codec.SchemaRegistry do
end

@impl true
def encode(payload, schema: schema) when is_binary(payload) or is_map(payload) do
def encode(payload, schema: schema) do
with {:ok, schema} <- resolve(schema) do
schema = if is_nil(schema.id), do: {:error, :invalid_schema_id}, else: {:ok, schema}

Expand Down

0 comments on commit fe58fab

Please sign in to comment.