From 3b5374eccaeaa9caada05f4cb18bc2e9c28ad1ac Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Sat, 1 Feb 2025 10:23:01 -0300 Subject: [PATCH] Refactoring/remove dead code --- lib/protobuf/text.ex | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/text.ex b/lib/protobuf/text.ex index 006291c0..08bc03bb 100644 --- a/lib/protobuf/text.ex +++ b/lib/protobuf/text.ex @@ -25,12 +25,12 @@ defmodule Protobuf.Text do undecodable output. """ @spec encode(struct(), Keyword.t()) :: binary() - def encode(struct, opts \\ []) do + def encode(%mod{} = struct, opts \\ []) do max_line_width = Keyword.get(opts, :max_line_width, 80) - message_props = struct.__struct__.__message_props__() + message_props = mod.__message_props__() struct - |> transform_module(struct.__struct__) + |> transform_module(mod) |> encode_struct(message_props) |> Algebra.format(max_line_width) |> IO.iodata_to_binary() @@ -42,7 +42,6 @@ defmodule Protobuf.Text do fields = struct - |> Map.from_struct() |> Map.drop([:__unknown_fields__, :__struct__, :__pb_extensions__]) |> Enum.sort() @@ -53,10 +52,6 @@ defmodule Protobuf.Text do Algebra.container_doc("{", fields, "}", inspect_opts(), fun, break: :strict) end - defp encode_struct(nil, _) do - "{}" - end - @spec encode_struct_field({atom(), term()}, :proto2 | :proto3, MessageProps.t()) :: Algebra.t() defp encode_struct_field({name, value}, syntax, message_props) do case Enum.find(message_props.field_props, fn {_, prop} -> prop.name_atom == name end) do