Add Python 3 Binding Generation via Pybind11
* Created entry point packet/python3_module.cc to create bluetooth_packets_python3 Python module. Layer specific packets are submodules of this top layer module * Define shim layer for Builder::Create() functions to use a std::shared_ptr instead of std::unique_ptr as Python does not support explicit ownership transfer * Add py::keep_alive to make sure the shared_ptr does not get garbage collected until the returned object is garbage collected * Redefine PacketView::Create() method as a constructor for packet view and throws value errors when packet is in valid so that users don't have to call IsValid() * Redefine Builder::Serialize() method to return a Python list of bytes directly instead of using BitInserter. Python binding users need to manually concatenate sub-sections of generated packets to form a bigger packet * Add build rules to generate and build the Python 3 library Example: >>> import bluetooth_packets_python3 as bp3 >>> write_ssp_enable_builder = bp3.hci_packets.WriteSimplePairingModeBuilder(bp3.hci_packets.Enable.ENABLED) >>> write_ssp_enable_bytes = write_ssp_enable_builder.Serialize() >>> list(map(lambda b : hex(b), write_ssp_enable_bytes)) ['0x56', '0xc', '0x1', '0x1'] >>> write_ssp_enable_pkt_view = bp3.PacketViewLittleEndian(write_ssp_enable_bytes) >>> write_ssp_enable_view = bp3.hci_packets.WriteSimplePairingModeView(bp3.hci_packets.SecurityCommandView(bp3.hci_packets.CommandPacketView(write_ssp_enable_pkt_view))) >>> write_ssp_enable_view.GetOpCode() OpCode.WRITE_SIMPLE_PAIRING_MODE >>> write_ssp_enable_view.GetSimplePairingMode() Enable.ENABLED Bug: 143374372 Test: make and run locally Change-Id: I8775c2d26a393aa5c1a417b7f845f7102fe4120e
Loading
Please register or sign in to comment