Skip to content
Merged
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
20 changes: 11 additions & 9 deletions lib/protobuf/wire/varint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,34 @@ defmodule Protobuf.Wire.Varint do
@max_bits 64
@mask64 bsl(1, @max_bits) - 1

# generated: true is required here to silence compilation warnings in Elixir
# 1.10 and 1.11. OK to remove once we support only 1.12+
@varints [
{
quote(do: <<0::1, value::7>>),
quote(do: value)
},
{
quote(do: <<1::1, x0::7, 0::1, x1::7>>),
quote(do: x0 + bsl(x1, 7))
quote(generated: true, do: x0 + bsl(x1, 7))
},
{
quote(do: <<1::1, x0::7, 1::1, x1::7, 0::1, x2::7>>),
quote(do: x0 + bsl(x1, 7) + bsl(x2, 14))
quote(generated: true, do: x0 + bsl(x1, 7) + bsl(x2, 14))
},
{
quote(do: <<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 0::1, x3::7>>),
quote(do: x0 + bsl(x1, 7) + bsl(x2, 14) + bsl(x3, 21))
quote(generated: true, do: x0 + bsl(x1, 7) + bsl(x2, 14) + bsl(x3, 21))
},
{
quote(do: <<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 0::1, x4::7>>),
quote(do: x0 + bsl(x1, 7) + bsl(x2, 14) + bsl(x3, 21) + bsl(x4, 28))
quote(generated: true, do: x0 + bsl(x1, 7) + bsl(x2, 14) + bsl(x3, 21) + bsl(x4, 28))
},
{
quote do
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 0::1, x5::7>>
end,
quote do
quote(generated: true) do
x0 +
bsl(x1, 7) +
bsl(x2, 14) +
Expand All @@ -87,7 +89,7 @@ defmodule Protobuf.Wire.Varint do
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 1::1, x5::7, 0::1,
x6::7>>
end,
quote do
quote(generated: true) do
x0 +
bsl(x1, 7) +
bsl(x2, 14) +
Expand All @@ -102,7 +104,7 @@ defmodule Protobuf.Wire.Varint do
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 1::1, x5::7, 1::1,
x6::7, 0::1, x7::7>>
end,
quote do
quote(generated: true) do
x0 +
bsl(x1, 7) +
bsl(x2, 14) +
Expand All @@ -118,7 +120,7 @@ defmodule Protobuf.Wire.Varint do
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 1::1, x5::7, 1::1,
x6::7, 1::1, x7::7, 0::1, x8::7>>
end,
quote do
quote(generated: true) do
x0 +
bsl(x1, 7) +
bsl(x2, 14) +
Expand All @@ -135,7 +137,7 @@ defmodule Protobuf.Wire.Varint do
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 1::1, x5::7, 1::1,
x6::7, 1::1, x7::7, 1::1, x8::7, 0::1, x9::7>>
end,
quote do
quote(generated: true) do
band(
x0 +
bsl(x1, 7) +
Expand Down