-
Notifications
You must be signed in to change notification settings - Fork 3
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
RLID helper #89
Conversation
This pull request has been linked to Shortcut Story #22091: Add RLID support to PyEnsign. |
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
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
pytest
?