Skip to content

Commit

Permalink
Fix parse of packed repeated enums in proto3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
ahamez committed Jun 16, 2020
1 parent 728be4e commit c8a104b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/protox/parse.ex
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ defmodule Protox.Parse do
case map_entry(upper, msg_name, descriptor) do
nil ->
type = get_type(descriptor)
kind = get_kind(syntax, upper, descriptor, type)
kind = get_kind(syntax, upper, descriptor)
{descriptor.label, kind, type}

map_type ->
Expand Down Expand Up @@ -270,7 +270,7 @@ defmodule Protox.Parse do
|> Enum.map(&Macro.camelize(&1))
end

defp get_kind(syntax, upper, descriptor, type) do
defp get_kind(syntax, upper, descriptor) do
import Protox.Guards

case descriptor do
Expand All @@ -284,8 +284,9 @@ defmodule Protox.Parse do
%FieldDescriptorProto{label: :repeated, options: %FieldOptions{packed: false}} ->
:unpacked

%FieldDescriptorProto{label: :repeated} ->
case {syntax, type} do
%FieldDescriptorProto{label: :repeated, type: field_type} ->
case {syntax, field_type} do
{:proto3, :enum} -> :packed
{:proto3, ty} when is_primitive(ty) -> :packed
_ -> :unpacked
end
Expand Down
6 changes: 4 additions & 2 deletions test/protox_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ defmodule ProtoxTest do
{:oneof_2_nested_enum, {:oneof, :oneof_2}, {:enum, Abc.Def.Proto3.NestedEnum}},
9999 => {:nested_enum, {:default, :FOO}, {:enum, Abc.Def.Proto3.NestedEnum}},
200 => {:repeated_int32_packed, :packed, :int32},
201 => {:repeated_int32_unpacked, :unpacked, :int32}
201 => {:repeated_int32_unpacked, :unpacked, :int32},
51 => {:repeated_nested_enum, :packed, {:enum, Abc.Def.Proto3.NestedEnum}}
}
end

Expand Down Expand Up @@ -225,7 +226,8 @@ defmodule ProtoxTest do
9999 =>
{:nested_enum, {:default, :FOO}, {:enum, Namespace.Abc.Def.Proto3.NestedEnum}},
200 => {:repeated_int32_packed, :packed, :int32},
201 => {:repeated_int32_unpacked, :unpacked, :int32}
201 => {:repeated_int32_unpacked, :unpacked, :int32},
51 => {:repeated_nested_enum, :packed, {:enum, Namespace.Abc.Def.Proto3.NestedEnum}}
}
end

Expand Down
Binary file modified test/samples/file_descriptor_set.bin
Binary file not shown.
2 changes: 2 additions & 0 deletions test/samples/proto3.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ message Proto3 {

repeated int32 repeated_int32_packed = 200 [packed = true];
repeated int32 repeated_int32_unpacked = 201 [packed = false];

repeated NestedEnum repeated_nested_enum = 51;
}

message EmptyProto3 {
Expand Down

0 comments on commit c8a104b

Please sign in to comment.