Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ImNotAVirus/elvengard_network
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNotAVirus committed Oct 4, 2023
2 parents 972b27c + 7b3d817 commit 9b23d71
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.1

Add `.formatter.exs` file to release for `import_deps`

## 0.1.0

Pre-release, this is not a production ready release !
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The package can be installed by adding `elvengard_network` to your list of depen
```elixir
def deps do
[
{:elvengard_network, "~> 0.1.0"}
{:elvengard_network, "~> 0.1.1"}
]
end
```
Expand Down
2 changes: 1 addition & 1 deletion guides/introduction/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To add ElvenGard.Network to this application, just add an entry to your mix.exs:
```elixir
defp deps do
[
{:elvengard_network, "~> 0.1.0"}
{:elvengard_network, "~> 0.1.1"}
]
end
```
Expand Down
27 changes: 21 additions & 6 deletions lib/elven_gard/network/packet_serializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,32 @@ defmodule ElvenGard.Network.PacketSerializer do
defp def_serialize(%{id: id, fields: fields}) do
fields_ast =
Enum.map(fields, fn %{name: name, type: type, opts: opts} ->
quote location: :keep do
case {Map.fetch!(var!(packet), unquote(name)), opts[:default]} do
{nil, value} when not is_nil(value) -> value
{value, _} -> unquote(type).encode(value, unquote(opts))
end
case Keyword.get(opts, :if) do
nil ->
quote location: :keep do
case {Map.fetch!(var!(packet), unquote(name)), opts[:default]} do
{nil, value} when not is_nil(value) -> value
{value, _} -> unquote(type).encode(value, unquote(opts))
end
end

condition ->
quote location: :keep do
if unquote(condition) in [nil, false] do
:"$drop"
else
case {Map.fetch!(var!(packet), unquote(name)), opts[:default]} do
{nil, value} when not is_nil(value) -> value
{value, _} -> unquote(type).encode(value, unquote(opts))
end
end
end
end
end)

quote location: :keep, generated: true do
def serialize(%__MODULE__{} = var!(packet)) do
{unquote(id), unquote(fields_ast)}
{unquote(id), Enum.reject(unquote(fields_ast), &match?(:"$drop", &1))}
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ElvenGard.Network.MixProject do
use Mix.Project

@app_name "ElvenGard.Network"
@version "0.1.0"
@version "0.1.1"
@github_link "https://github.com/ImNotAVirus/elvengard_network"

def project do
Expand Down Expand Up @@ -51,7 +51,7 @@ defmodule ElvenGard.Network.MixProject do
maintainers: ["ImNotAVirus"],
licenses: ["MIT"],
links: %{"GitHub" => @github_link},
files: ~w(lib CHANGELOG.md LICENSE.md mix.exs README.md)
files: ~w(lib CHANGELOG.md LICENSE.md mix.exs .formatter.exs README.md)
]
end

Expand Down

0 comments on commit 9b23d71

Please sign in to comment.