Skip to content

Conversation

cherchiga
Copy link

While trying to use this library with protobuf, we ran into an issue with the logic used to calculate the lenght of a Bytes type, BinaryValue. The function currently used accept a string and tries to encode it to UTF-8 before calculating the lenght.

def _get_string_size_in_bytes(self, s: str) -> int:
    """
    Responsible for calculating the size of a string in bytes

    :s: The string whose size is to be determined.

    """
    return len(s.encode('utf-8'))

I have created a new method specific for Bytes type that removes the encoding and it passes all the tests.

def _get_bytes_size_in_bytes(self, b: bytes) -> int:
    """
    Responsible for calculating the size of a byte collection in bytes

    :b: The byte collection whose size is to be determined.

    """
    return len(b)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant