8000 RLID helper by pdeziel · Pull Request #89 · rotationalio/pyensign · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

RLID helper #89

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

Merged
merged 4 commits into from
Nov 6, 2023
Merged

RLID helper #89

merged 4 commits into from
Nov 6, 2023

Conversation

pdeziel
Copy link
Collaborator
@pdeziel pdeziel commented Nov 3, 2023

This PR adds an RLID helper class for encoding the event IDs returned from Ensign into strings. When an event ID comes back from Ensign it should be stored properly on the Event helper class.

TODOs and questions

CHECKLIST

  • Is the commit message formatted correctly?
  • Do all of your functions and methods have docstrings?
  • Have you added/updated unit tests where appropriate?
  • Have you run the unit tests using pytest?
  • Is your code style correct (are you using PEP8, pyflakes)?

Copy link

This pull request has been linked to Shortcut Story #22091: Add RLID support to PyEnsign.

@pdeziel pdeziel requested a review from bbengfort November 3, 2023 21:58
Comment on lines +24 to +45
def __str__(self):
"""
Port of the RLID encoding method from the Go SDK.
"""
dst = [None] * ENCODED_SIZE
dst[0] = ENCODING[(self.bytes[0] & 248) >> 3]
dst[1] = ENCODING[((self.bytes[0] & 7) << 2) | ((self.bytes[1] & 192) >> 6)]
dst[2] = ENCODING[(self.bytes[1] & 62) >> 1]
dst[3] = ENCODING[((self.bytes[1] & 1) << 4) | ((self.bytes[2] & 240) >> 4)]
dst[4] = ENCODING[((self.bytes[2] & 15) << 1) | ((self.bytes[3] & 128) >> 7)]
dst[5] = ENCODING[(self.bytes[3] & 124) >> 2]
dst[6] = ENCODING[((self.bytes[3] & 3) << 3) | ((self.bytes[4] & 224) >> 5)]
dst[7] = ENCODING[self.bytes[4] & 31]
dst[8] = ENCODING[(self.bytes[5] & 248) >> 3]
dst[9] = ENCODING[((self.bytes[5] & 7) << 2) | ((self.bytes[6] & 192) >> 6)]
dst[10] = ENCODING[(self.bytes[6] & 62) > 8000 ;> 1]
dst[11] = ENCODING[((self.bytes[6] & 1) << 4) | ((self.bytes[7] & 240) >> 4)]
dst[12] = ENCODING[((self.bytes[7] & 15) << 1) | ((self.bytes[8] & 128) >> 7)]
dst[13] = ENCODING[(self.bytes[8] & 124) >> 2]
dst[14] = ENCODING[((self.bytes[8] & 3) << 3) | ((self.bytes[9] & 224) >> 5)]
dst[15] = ENCODING[self.bytes[9] & 31]
return "".join(dst)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ported from the Go SDK, we don't have any need to be able to decode or create RLIDs from pyensign yet (expect in maybe tests) so this is purely for displaying them nicely at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, in the future if we do need that ability in Python we can move this to encode/decode methods.

Copy link
Contributor
@bbengfort bbengfort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I'm not going to lie - I'm not sure I remember the encode/decode code exactly but I'm happy with the tests, and if they match what's in the Go library than. I'm good to go. Thanks for adding this to PyEnsign!

@pdeziel pdeziel merged commit 7829e0d into develop Nov 6, 2023
@pdeziel pdeziel deleted the sc-22091 branch November 6, 2023 18:19
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.

2 participants
0