-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A probably small bug: Instance of LabeledTextChunk ❯ .to_bytes() ❯ Exception #174
Comments
Here is the ChatGPT answer to this issue: The error is occurring due to an issue in the pack(
f"<4sIII4sHHHH{encoded_label_length}s",
self.HEADER_LABEL,
encoded_label_length + self.OFFSET_LABEL,
self.__id,
self.__sample_length,
self.__purpose,
self.__country,
self.__language,
self.__dialect,
self.__codepage,
encoded_label,
) The error is likely occurring because To fix the error, you need to ensure that you convert the string values to bytes before passing them to @word_align
def to_bytes(self) -> bytes:
encoded_label = null_terminate(encode_string(self.__label), True)
encoded_label_length = len(encoded_label)
return pack(
f"<4sIII4sHHHH{encoded_label_length}s",
self.HEADER_LABEL,
encoded_label_length + self.OFFSET_LABEL,
self.__id,
self.__sample_length,
self.__purpose.encode(), # Convert to bytes
self.__country,
self.__language,
self.__dialect,
self.__codepage,
encoded_label,
) In this revised version, With these changes, the error should be resolved, and the |
Looks like a reasonable thing to change. I'll have to dig out the spec to see what the byte encoding for this sort of chunk is and remember how it all works as I've not touched this in a while. 🙂 Either way, thanks for getting in touch and I'll report back when I get some time to have a proper go at this. |
Good evening
Important note:
Because I am not a Python programmer, I have asked what ChtaGPT would propose and the answer looks pretty good. I have added it to the next comment below so that someone who knows what is happening, can check it.
I guess I have found a small bug 😃, but I don't understand what is happening in Python.
I just create an
LabeledTextChunk
instance and then, I call.to_bytes()
:Python creates this exception:
In GitHub, here is Line 1168 of chunks.py
I hope someone can easily see this issue.
Thanks a lot, kind regards,
Thomas
The text was updated successfully, but these errors were encountered: