{ "info": { "author": "Ayon Lee", "author_email": "i@hyurl.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Basic Socket Protocol\n\nThis is a Python3 version of the original BSP protocol distributed in JavaScript,\nfor more detail of the protocol and supported data types, view it on GitHub:\n[bsp](https://github.com/hyurl/bsp).\n\nThe Node.js BSP was introduced, in the first place, to solve the problem that\nwhen transporting data over sockets in Node.js, the under-hood algorithm will\nautomatically split the data into segments or stick multiple data into one piece,\ntrying to optimize the network usage. Which however causes many pains and\nmistakes when transferring the data.\n\nThe purpose of BSP is two encode the data, and no matter how it may be sticked\nor splitted during the transmission, the remote end can still be able to decode\nit as-is when receiving it or them in a stream. And more over, allow the\ntransport of arbitrary data, instead of only string or binary.\n\nThe Python version of BSP, is meant to allow transmitting data between Python\nand Node.js/Browser, and any other environments that has BSP implemented.\n\n## API\n\n```py\n# Encodes any number of data into one chunk of bytearray.\ndef encode(*data) -> bytearray:\n pass\n\n# Decodes the input buffer and returns only the first item of the result.\ndef decode(buf: bytearray) -> any:\n pass\n\n# Continuously decodes input buffers and yields any decoded data during the\n# process.\ndef decode(buf: bytearray, temp: list) -> iter:\n pass\n```\n\n## Example\n\n```py\nimport bsp\n\n# encode and decode string\nbuf = bsp.encode(\"Hello, World!\")\nres = bsp.decode(buf) # Hello, World!\n\n# encode and decode number\nbuf = bsp.encode(12345)\nres = bsp.decode(buf) # 12345\n\n# encode and decode boolean and None\nbuf = bsp.encode(True)\nres = bsp.decode(buf) # True\nbuf = bsp.encode(False)\nres = bsp.decode(buf) # False\nbuf = bsp.encode(None)\nres = bsp.decode(buf) # None\n\n# encode and decode dict\nbuf = bsp.encode({ \"foo\": \"bar\" })\nres = bsp.decode(buf) # { \"foo\": \"bar\" }\n\n# encode and decode list\nbuf = bsp.encode([\"foo\", \"bar\"])\nres = bsp.decode(buf) # [\"foo\", \"bar\"]\n\n# encode and decode binary\nbuf = bsp.encode(bytearray([1, 2, 3, 4, 5]))\nres = bsp.decode(buf) # bytearray(b'\\x01\\x02\\x03\\x04\\x05')\n\n\n# encode and decode multiple data at once\nbuf = bsp.encode(\n \"Hello, World!\",\n 12345,\n 12345.678,\n 1111111111111111111111111111111111111,\n True,\n False,\n None,\n { \"foo\": \"bar\" },\n [\"foo\", \"bar\"],\n bytearray([1, 2, 3, 4, 5])\n)\n\n# temp=[None]*3 must be provided in this case\nfor item in bsp.decode(buf, [None]*3):\n print(item) # will print the data accordingly\n\n\n# Encode a large file and split it into chunks, then decode the chunks as a\n# stream.\nfile = open(\"test.bin\", \"rb\")\nsrc = bytearray(file.read()) # file.read() returns bytes, must cast to bytearray\nbuf = bsp.encode(src)\nsegments = []\ntemp = [None]*3 # use a temp outside the stream processor to keep imcomplete data\n\n# Split the file into several segments, each contians 64kb data of maximum length\nfor i in range(0, len(buf), 65535):\n segments.append(buf[i:i+65535])\n\n# simulate a stream of segments\nfor segment in segments:\n for item in bsp.decode(segment, temp):\n print(item) # only run once in this case and print the only input (src)\n```\n\n### bytes vs. bytearray\n\nAs being addressed above, when reading binary from a file, `file.read()` returns\ntype of `bytes`, and even more pratically, it's more easy for a person to create\na bytes instance than creating a bytearray, just use the `b` prefix for string.\n\nHowever, this type will not be compatibal with the original Node.js BSP, and it's\nhard to determine whether it should be encoded as string or as binary. So,\nfor more rational concerns, this package does not support `bytes` straight\nforward, a user must be explictly cast it to either a string or a bytearray\naccording to what he needs.\n\nFor more detail about BSP, see [bsp](https://github.com/hyurl/bsp).\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hyurl/bsp-py", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "bsp", "package_url": "https://pypi.org/project/bsp/", "platform": "", "project_url": "https://pypi.org/project/bsp/", "project_urls": { "Homepage": "https://github.com/hyurl/bsp-py" }, "release_url": "https://pypi.org/project/bsp/1.0.1/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Basic Socket Protocol", "version": "1.0.1", "yanked": false, "yanked_reason": null }, "last_serial": 6039614, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "856a0dbaef59f7e7205cea5a2aa8e633", "sha256": "1856d508913cc03e6ebd0058be69de146c8fdfd1bfdeafb7e2f6bd21c6d80405" }, "downloads": -1, "filename": "bsp-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "856a0dbaef59f7e7205cea5a2aa8e633", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5113, "upload_time": "2019-10-27T11:43:03", "upload_time_iso_8601": "2019-10-27T11:43:03.758138Z", "url": "https://files.pythonhosted.org/packages/a2/a7/d4e418476e9078372a96b65df7c7986dc81e7fe285da5f429445b3187811/bsp-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "49f3bb20b6b53e4a55af3e466acc76c8", "sha256": "a8ae5af7da19d0c421260567c654a90ebd32ffab7e5bec01ddde36943831c392" }, "downloads": -1, "filename": "bsp-1.0.0.tar.gz", "has_sig": false, "md5_digest": "49f3bb20b6b53e4a55af3e466acc76c8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4286, "upload_time": "2019-10-27T11:43:07", "upload_time_iso_8601": "2019-10-27T11:43:07.566888Z", "url": "https://files.pythonhosted.org/packages/20/58/81f709fd150bb508b8b5a6d134057e6973a775dcc198a97a76095e701abd/bsp-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "a037e7df92b5afc8ba15c12be8687dd0", "sha256": "47c72021ca9fe2a48974f9429879eca514df8e4e6819a9101ee0037af7436b55" }, "downloads": -1, "filename": "bsp-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "a037e7df92b5afc8ba15c12be8687dd0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5495, "upload_time": "2019-10-28T06:22:37", "upload_time_iso_8601": "2019-10-28T06:22:37.005110Z", "url": "https://files.pythonhosted.org/packages/be/85/da18cf10305669055d2cb5abf83ec10cd4273aaaa80ae388c0ad159df94e/bsp-1.0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "350773a2bcc794e2ad66cfc909fef6ed", "sha256": "2f83ca231039f77878f59276d9dc0be049aeff0ef2a7d3639ca25a83578ec1cc" }, "downloads": -1, "filename": "bsp-1.0.1.tar.gz", "has_sig": false, "md5_digest": "350773a2bcc794e2ad66cfc909fef6ed", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4491, "upload_time": "2019-10-28T06:22:38", "upload_time_iso_8601": "2019-10-28T06:22:38.307561Z", "url": "https://files.pythonhosted.org/packages/bf/01/9729203c41ff2fa5912dd36532e3c34de1461355ce10f57661c0bf2342ef/bsp-1.0.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a037e7df92b5afc8ba15c12be8687dd0", "sha256": "47c72021ca9fe2a48974f9429879eca514df8e4e6819a9101ee0037af7436b55" }, "downloads": -1, "filename": "bsp-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "a037e7df92b5afc8ba15c12be8687dd0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5495, "upload_time": "2019-10-28T06:22:37", "upload_time_iso_8601": "2019-10-28T06:22:37.005110Z", "url": "https://files.pythonhosted.org/packages/be/85/da18cf10305669055d2cb5abf83ec10cd4273aaaa80ae388c0ad159df94e/bsp-1.0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "350773a2bcc794e2ad66cfc909fef6ed", "sha256": "2f83ca231039f77878f59276d9dc0be049aeff0ef2a7d3639ca25a83578ec1cc" }, "downloads": -1, "filename": "bsp-1.0.1.tar.gz", "has_sig": false, "md5_digest": "350773a2bcc794e2ad66cfc909fef6ed", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4491, "upload_time": "2019-10-28T06:22:38", "upload_time_iso_8601": "2019-10-28T06:22:38.307561Z", "url": "https://files.pythonhosted.org/packages/bf/01/9729203c41ff2fa5912dd36532e3c34de1461355ce10f57661c0bf2342ef/bsp-1.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }