-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from noaccOS/feat/elixir-gen
feat: add elixir code generation
- Loading branch information
Showing
18 changed files
with
337 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
permissions: | ||
contents: read | ||
on: | ||
workflow_call: | ||
|
||
defaults: | ||
run: | ||
working-directory: elixir/edgehog_device_forwarder_proto | ||
jobs: | ||
format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: '26' | ||
elixir-version: '1.15.7' | ||
- name: Fetch dependencies | ||
run: mix do deps.get --only test, deps.compile | ||
- name: Check formatting | ||
run: mix format --check-formatted | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: '26' | ||
elixir-version: '1.15.7' | ||
- name: Fetch dependencies | ||
run: mix do deps.get --only test, deps.compile | ||
- name: Run tests | ||
run: mix test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
import_deps: [:protobuf] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
edgehog_device_forwarder_proto-*.tar | ||
|
||
# Temporary files, for example, from tests. | ||
/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- | ||
Copyright 2023 SECO Mind Srl | ||
SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
# EdgehogDeviceForwarderProto | ||
|
||
**TODO: Add description** | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
by adding `edgehog_device_forwarder_proto` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[ | ||
{:edgehog_device_forwarder_proto, "~> 0.1.0"} | ||
] | ||
end | ||
``` | ||
|
||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
be found at <https://hexdocs.pm/edgehog_device_forwarder_proto>. |
5 changes: 5 additions & 0 deletions
5
elixir/edgehog_device_forwarder_proto/lib/edgehog_device_forwarder_proto.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
defmodule EdgehogDeviceForwarderProto do | ||
end |
72 changes: 72 additions & 0 deletions
72
...ce_forwarder_proto/lib/edgehog_device_forwarder_proto/edgehog/device/forwarder/http.pb.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Request.HeadersEntry do | ||
@moduledoc false | ||
|
||
use Protobuf, map: true, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" | ||
|
||
field(:key, 1, type: :string) | ||
field(:value, 2, type: :string) | ||
end | ||
|
||
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Request do | ||
@moduledoc false | ||
|
||
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" | ||
|
||
field(:path, 1, type: :string) | ||
field(:method, 2, type: :string) | ||
field(:query_string, 3, type: :string, json_name: "queryString") | ||
|
||
field(:headers, 4, | ||
repeated: true, | ||
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Request.HeadersEntry, | ||
map: true | ||
) | ||
|
||
field(:body, 5, type: :bytes) | ||
field(:port, 6, type: :uint32) | ||
end | ||
|
||
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Response.HeadersEntry do | ||
@moduledoc false | ||
|
||
use Protobuf, map: true, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" | ||
|
||
field(:key, 1, type: :string) | ||
field(:value, 2, type: :string) | ||
end | ||
|
||
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Response do | ||
@moduledoc false | ||
|
||
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" | ||
|
||
field(:status_code, 1, type: :uint32, json_name: "statusCode") | ||
|
||
field(:headers, 2, | ||
repeated: true, | ||
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Response.HeadersEntry, | ||
map: true | ||
) | ||
|
||
field(:body, 3, type: :bytes) | ||
end | ||
|
||
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http do | ||
@moduledoc false | ||
|
||
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" | ||
|
||
oneof(:message, 0) | ||
|
||
field(:request_id, 1, type: :bytes, json_name: "requestId") | ||
|
||
field(:request, 2, | ||
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Request, | ||
oneof: 0 | ||
) | ||
|
||
field(:response, 3, | ||
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Response, | ||
oneof: 0 | ||
) | ||
end |
10 changes: 10 additions & 0 deletions
10
...forwarder_proto/lib/edgehog_device_forwarder_proto/edgehog/device/forwarder/message.pb.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Message do | ||
@moduledoc false | ||
|
||
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" | ||
|
||
oneof(:protocol, 0) | ||
|
||
field(:http, 1, type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http, oneof: 0) | ||
field(:ws, 2, type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.WebSocket, oneof: 0) | ||
end |
27 changes: 27 additions & 0 deletions
27
...vice_forwarder_proto/lib/edgehog_device_forwarder_proto/edgehog/device/forwarder/ws.pb.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.WebSocket.Close do | ||
@moduledoc false | ||
|
||
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" | ||
|
||
field(:code, 1, type: :uint32) | ||
field(:reason, 2, type: :string) | ||
end | ||
|
||
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.WebSocket do | ||
@moduledoc false | ||
|
||
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" | ||
|
||
oneof(:message, 0) | ||
|
||
field(:socket_id, 1, type: :bytes, json_name: "socketId") | ||
field(:text, 2, type: :string, oneof: 0) | ||
field(:binary, 3, type: :bytes, oneof: 0) | ||
field(:ping, 4, type: :bytes, oneof: 0) | ||
field(:pong, 5, type: :bytes, oneof: 0) | ||
|
||
field(:close, 6, | ||
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.WebSocket.Close, | ||
oneof: 0 | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
defmodule EdgehogDeviceForwarderProto.MixProject do | ||
use Mix.Project | ||
|
||
def project do | ||
[ | ||
app: :edgehog_device_forwarder_proto, | ||
version: "0.0.1", | ||
elixir: "~> 1.15", | ||
start_permanent: Mix.env() == :prod, | ||
deps: deps() | ||
] | ||
end | ||
|
||
def application do | ||
[ | ||
extra_applications: [:logger] | ||
] | ||
end | ||
|
||
defp deps do | ||
[ | ||
{:protobuf, "~> 0.12"} | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%{ | ||
"protobuf": {:hex, :protobuf, "0.12.0", "58c0dfea5f929b96b5aa54ec02b7130688f09d2de5ddc521d696eec2a015b223", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "75fa6cbf262062073dd51be44dd0ab940500e18386a6c4e87d5819a58964dc45"}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SPDX-FileCopyrightText: 2023 SECO Mind Srl | ||
SPDX-License-Identifier: Apache-2.0 |
22 changes: 22 additions & 0 deletions
22
elixir/edgehog_device_forwarder_proto/test/edgehog_device_forwarder_proto_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
defmodule EdgehogDeviceForwarderProtoTest do | ||
use ExUnit.Case | ||
alias EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.{Message, Http, WebSocket} | ||
doctest EdgehogDeviceForwarderProto | ||
|
||
test "encode and decode test" do | ||
ws = %WebSocket{socket_id: <<>>, message: {:text, "some string"}} | ||
assert ws == ws |> WebSocket.encode() |> WebSocket.decode() | ||
|
||
http_response = %Http.Response{status_code: 200, headers: %{}, body: <<>>} | ||
http = %Http{request_id: <<>>, message: {:response, http_response}} | ||
|
||
assert http == http |> Http.encode() |> Http.decode() | ||
|
||
message = %Message{protocol: {:ws, ws}} | ||
assert message == message |> Message.encode() |> Message.decode() | ||
assert {:ws, ^ws} = message |> Message.encode() |> Message.decode() |> Map.get(:protocol) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
ExUnit.start() |
Oops, something went wrong.