Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/protobuf/decoder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,24 @@ defmodule Protobuf.DecoderTest do
assert struct.a == [-1, 1, -2, 2, -3]
end

test "decodes packed binary using UnsignedInt32Repeated for proto2" do
packed = <<10, 5, 1, 2, 3, 4, 5>>

struct = Decoder.decode(packed, TestMsg.UnsignedInt32Repeated)

assert %TestMsg.UnsignedInt32Repeated{} = struct
assert struct.a == [1, 2, 3, 4, 5]
end

test "decodes unpacked binary using UnsignedInt32RepeatedPacked for proto2" do
unpacked = <<8, 1, 8, 2, 8, 3, 8, 4, 8, 5>>

struct = Decoder.decode(unpacked, TestMsg.UnsignedInt32RepeatedPacked)

assert %TestMsg.UnsignedInt32RepeatedPacked{} = struct
assert struct.a == [1, 2, 3, 4, 5]
end

test "decodes custom default message for proto2" do
assert Decoder.decode(<<8, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0>>, TestMsg.Foo2) ==
TestMsg.Foo2.new(a: 0, b: 0)
Expand Down
14 changes: 14 additions & 0 deletions test/support/test_msg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ defmodule TestMsg do
field :a, 1, repeated: true, type: :sint32, packed: true
end

defmodule UnsignedInt32Repeated do
@moduledoc false
use Protobuf, syntax: :proto2

field :a, 1, repeated: true, type: :uint32
end

defmodule UnsignedInt32RepeatedPacked do
@moduledoc false
use Protobuf, syntax: :proto2

field :a, 1, repeated: true, type: :uint32, packed: true
end

defmodule Oneof do
@moduledoc false
use Protobuf
Expand Down