Skip to content

Commit 7eb7e20

Browse files
committed
IncomingIntrospectionEvent holds a map
IncomingIntrospectionEvent holds now a map interface-name -> {major, minor}. Keep the old plain introspection string as a deprecated field. Signed-off-by: Arnaldo Cesco <[email protected]>
1 parent 685ca10 commit 7eb7e20

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Changed
99
- Bump Elixir to 1.15.7.
1010
- Bump Erlang/OTP to 26.1.
11+
- IncomingIntrospectionEvent holds now a interface-name -> {major, minor} map
12+
instead of the plain introspection string.
1113

1214
## [1.1.1] - 2023-10-03
1315
### Fixed
Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1+
defmodule Astarte.Core.Triggers.SimpleEvents.InterfaceVersion do
2+
@moduledoc false
3+
4+
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
5+
6+
field :major, 1, type: :int32
7+
field :minor, 2, type: :int32
8+
end
9+
10+
defmodule Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent.IntrospectionMapEntry do
11+
@moduledoc false
12+
13+
use Protobuf, map: true, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
14+
15+
field :key, 1, type: :string
16+
field :value, 2, type: Astarte.Core.Triggers.SimpleEvents.InterfaceVersion
17+
end
18+
119
defmodule Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent do
220
@moduledoc false
321

4-
use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3
22+
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
523

6-
def fully_qualified_name, do: "IncomingIntrospectionEvent"
24+
field :introspection, 1, proto3_optional: true, type: :string, deprecated: true
725

8-
field :introspection, 1, proto3_optional: true, type: :string
26+
field :introspection_map, 2,
27+
repeated: true,
28+
type: Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent.IntrospectionMapEntry,
29+
json_name: "introspectionMap",
30+
map: true
931
end

lib/astarte_core/triggers/simple_events/incoming_introspection_event.proto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
syntax = "proto3";
2020

21+
message InterfaceVersion {
22+
int32 major = 1;
23+
int32 minor = 2;
24+
}
25+
2126
message IncomingIntrospectionEvent {
22-
optional string introspection = 1;
27+
optional string introspection = 1 [deprecated = true];
28+
map<string, InterfaceVersion> introspection_map = 2;
2329
}

test/astarte_core/triggers/simple_events_test.exs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,31 @@ defmodule Astarte.Core.SimpleEventsTest do
412412
assert ValueStoredEvent.decode(serialized_event) == event
413413
end
414414
end
415+
416+
describe "IncomingIntrospectionEvent" do
417+
alias Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent
418+
419+
test "is correctly serialized when payload is a string" do
420+
introspection_string = "com.an.Interface:1:0;com.another.Interface:0:1"
421+
422+
event = %IncomingIntrospectionEvent{introspection: introspection_string}
423+
424+
assert ^event =
425+
IncomingIntrospectionEvent.encode(event) |> IncomingIntrospectionEvent.decode()
426+
end
427+
428+
test "is correctly serialized when payload is a map" do
429+
alias Astarte.Core.Triggers.SimpleEvents.InterfaceVersion
430+
431+
introspection_map = %{
432+
"com.an.Interface" => %InterfaceVersion{major: 1, minor: 0},
433+
"com.another.Interface" => %InterfaceVersion{major: 0, minor: 1}
434+
}
435+
436+
event = %IncomingIntrospectionEvent{introspection_map: introspection_map}
437+
438+
assert ^event =
439+
IncomingIntrospectionEvent.encode(event) |> IncomingIntrospectionEvent.decode()
440+
end
441+
end
415442
end

0 commit comments

Comments
 (0)