Skip to content

Commit

Permalink
Fix: int32 and int64 should use the same encoder #103
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Feb 7, 2023
1 parent 5902ed6 commit 28f8477
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## `2.2.2`

- Fix: `int32` and `int64` should use the same encoder #103

## `2.2.1`

- Fix: implement two's compliment varint encoding for `int32` and `int64` #103
Expand Down
2 changes: 1 addition & 1 deletion pure_protobuf/dataclasses_.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def get_repeated(type_: Any) -> Tuple[bool, Any]:
types.fixed64: serializers.UnsignedFixed64Serializer(),
types.sfixed32: serializers.SignedFixed32Serializer(),
types.sfixed64: serializers.SignedFixed64Serializer(),
types.int32: serializers.TwosComplimentInt32Serializer(),
types.int32: serializers.TwosComplimentInt64Serializer(),
types.int64: serializers.TwosComplimentInt64Serializer(),
types.sint32: serializers.SignedInt32Serializer(),
types.sint64: serializers.SignedInt64Serializer(),
Expand Down
6 changes: 0 additions & 6 deletions pure_protobuf/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ def load(self, io: IO) -> Any:
)


class TwosComplimentInt32Serializer(TwosComplimentVarintSerializer):
min_value = -(1 << 31)
max_value = (1 << 31) - 1
length = 4


class TwosComplimentInt64Serializer(TwosComplimentVarintSerializer):
min_value = -(1 << 63)
max_value = (1 << 63) - 1
Expand Down
20 changes: 0 additions & 20 deletions tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
"""
`pure-protobuf` contributors © 2011-2019
"""

# noinspection PyCompatibility
from dataclasses import dataclass
from enum import IntEnum
from typing import Any, List, Optional, Type
Expand All @@ -25,7 +20,6 @@
SignedInt64Serializer,
SignedVarintSerializer,
StringSerializer,
TwosComplimentInt32Serializer,
TwosComplimentInt64Serializer,
UnsignedFixed32Serializer,
UnsignedFixed64Serializer,
Expand Down Expand Up @@ -84,9 +78,7 @@ class Test3:
(UnsignedFixed64Serializer, "hello"),
(FloatSerializer, "hello"),
(DoubleSerializer, "hello"),
(TwosComplimentInt32Serializer, 1 << 31),
(TwosComplimentInt64Serializer, 1 << 63),
(TwosComplimentInt32Serializer, -(1 << 31) - 1),
(TwosComplimentInt64Serializer, -(1 << 63) - 1),
],
)
Expand Down Expand Up @@ -160,18 +152,6 @@ def test_twos_compliment_64_serializer_loads(value: int, bytes_: bytes, benchmar
]


@mark.parametrize("value, bytes_", TWOS_COMPLEMENT_32_TESTS, ids=_test_id)
def test_twos_compliment_32_serializer_dumps(value: int, bytes_: bytes, benchmark):
TwosComplimentInt32Serializer().validate(value)
assert benchmark(TwosComplimentInt32Serializer().dumps, value) == bytes_


@mark.parametrize("value, bytes_", TWOS_COMPLEMENT_32_TESTS, ids=_test_id)
def test_twos_compliment_32_serializer_loads(value: int, bytes_: bytes, benchmark):
TwosComplimentInt32Serializer().validate(value)
assert benchmark(TwosComplimentInt32Serializer().loads, bytes_) == value


@mark.parametrize(
"value, bytes_",
[
Expand Down

0 comments on commit 28f8477

Please sign in to comment.