Skip to content

Commit

Permalink
Refactoring/remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
v0idpwn committed Feb 1, 2025
1 parent a959410 commit 3b5374e
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/protobuf/text.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -42,7 +42,6 @@ defmodule Protobuf.Text do

fields =
struct
|> Map.from_struct()
|> Map.drop([:__unknown_fields__, :__struct__, :__pb_extensions__])
|> Enum.sort()

Expand All @@ -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
Expand Down

0 comments on commit 3b5374e

Please sign in to comment.