-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
opack: implement dates #2466
base: master
Are you sure you want to change the base?
opack: implement dates #2466
Conversation
I can confirm that integer data types in OPACK are signed integers. I used the method I've described here: https://pyatv.dev/documentation/protocols/#reference-decoding To decode 0x30FF, which corresponds to an integer with one byte payload. So 0xFE is a signed integer (-2), which the application confirms:
I can also confirm that this case is broken in the OPACK implementation of pyatv:
It is because of this check: Line 50 in 80fd95e
Integers in the range of [0, 39] are encoded as [value + 8] and the check above catches negative values for this case. Integers less than or equal to -2 (as -1 has its own value of 0x07) must follow the same rules are we check for positive integers right now (as those are signed). Typically add tests that |
@@ -15,6 +14,8 @@ | |||
|
|||
_SIZED_INT_TYPES: Dict[int, Type] = {} | |||
|
|||
_OPACK_TIME_OFFSET: float = 978307200.0 |
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.
Can you add a comment (and possibly rename the constant) making it clear that this is a conversion from offset between unix time and mach absolute time? This is a very magic constant.
@@ -36,8 +36,7 @@ def test_pack_uuid(): | |||
|
|||
|
|||
def test_pack_absolute_time(): | |||
with pytest.raises(NotImplementedError): | |||
pack(datetime.now()) | |||
assert pack(datetime.fromtimestamp(978307200.0)) == b"\x06" + (b"\x00" * 8) |
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.
Same with the tests, I don't really like magic constants. I have used mach time in MRP IIRC, so you could add some kind of helper method to convert datetime
objects mach time (and possibly pack) if you like.
I'll add in a conversion function, and use ----- |
I'm not sure where we are with this right now. Can we clean it up and merge it? |
I'd also like to add support for negative integers into opack, if possible. If anyone has a mac, I'd ask if you could test this piece of code https://github.com/fabianfreyer/opack-tools/ to see whether or not opack supports negative integers in the first place.
My suspicion is that OPACK does not, in fact, have a data type for signed integers, and attempting to encode negative integer will be treated as an unsigned integer internally. (e.g.
OPACKDecode(OPACKEncode(NSNumber(-15))) = NSNumber(4294967281)
, at a high level)