Rayquaza01 / nativemessaging

A Python package for interfacing with Native Messaging in WebExtensions
Mozilla Public License 2.0
28 stars 2 forks source link

struct.pack format #1

Open DamienCassou opened 5 years ago

DamienCassou commented 5 years ago

Hi,

in the code of this project, one can read:

message_length = struct.unpack("@I", raw_length)[0]

In the MDN's documentation, one can read:

message_length = struct.unpack('=I', raw_length)[0]

Would you mind telling me why you chose to use "@I" for the format instead of "=I"?

The related Python documentation is at: https://docs.python.org/2/library/struct.html

Rayquaza01 commented 5 years ago

Hello, The ping_pong.py file from MDN's webextension examples repo uses "@I" instead of "=I", which is where I got that from. I can't remember specifically why I chose to use "@I", but both seem to work the same.

Here's the edit on MDN where @ is changed to =

[...]Either works as long native int is 32-bits (which I think is everywhere Firefox runs), but using @I is misleading.

And the Google Chrome sample host just uses I, no @ or =, which is the same as @I according to the Python docs.

So, I don't think it really matters unless there's a system that has a native size for ints that's different from the standard size.

DamienCassou commented 5 years ago

Rayquaza01 notifications@github.com writes:

The ping_pong.py file from MDN's webextension examples repo uses "@I" instead of "=I", which is where I got that from. I can't remember specifically why I chose to use "@I", but both seem to work the same. […]

Thank you very much for your detailed answer.

-- Damien Cassou http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill