NBIN


NameNBIN JSON
Version 1.2 PyPI version JSON
download
home_page
SummaryOfficial library for working with the BIN file format
upload_time2024-02-23 18:28:16
maintainer
docs_urlNone
author
requires_python>=3.11
licenseMIT License Copyright (c) 2024 Markada Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords markada nbin file storage hisos
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## What is NBIN

NBIN is a data serialization format that aims to make it easier to create and store bytecode for arbitrary programming languages. For this purpose, it has special data types, as well as its own binary file structure

NBIN has its own binary notation format, which can be broadly described as follows:
```bnf
<i8>        ::= 00h <byte>{1}
<i16>       ::= 01h <byte>{2}
<i32>       ::= 02h <byte>{4}
<i64>       ::= 03h <byte>{8}
<u8>        ::= 05h <byte>{1}
<u16>       ::= 06h <byte>{2}
<u32>       ::= 07h <byte>{4}
<u64>       ::= 09h <byte>{8}
<float>     ::= 10h <byte>{4}
<bool>      ::= 11h <byte>
<str>       ::= 12h <lenght> <byte>+
<null>      ::= 13h
<list>      ::= 14h <lenght> <exp>+
<block>     ::= 15h <lenght> <command>+
<command>   ::= 16h <lenght> <byte>+ <lenght> <exp>+


/* unsigned int */
<lenght> ::= <byte>{4}
```

> What is written in "{ ... }" is the number of repetitions

Each version of NBIN defines its own specification, for example the current NBIN (NBIN 1) uses the following specification:
1. Supported data types:
    * i8 - 1 sign byte
    * i16 - 2 sign bytes
    * i32 - 4 sign bytes
    * i64 - 8 sign bytes
    * u8 - 1 unsigned byte
    * u16 - 2 unsigned bytes
    * u32 - 4 unsigned bytes
    * u64 - 8 unsigned bytes
    * str - UNICODE string
    * bool - logical type
    * float - 32-bit fractional number
    * command - command
    * block - block with commands
    * list - not a typed list
    * null - no value
2. The length of any collection NBIN is a 32-bit unsigned number
3. Any NBIN object can be written in a binary file (it is not necessary that everything be wrapped in a block)
4. NBIN tries to support as many types as possible
5. NBIN types should satisfy both low-level and high-level programming needs


## NBIN library

There are two functions here:
1. `load` - accepts bytes in NBIN format as input and returns a Python object
1. `dump` - takes a Python object as input and returns bytes in NBIN format

In general, these two functions deal with object conversion

Usage example:
```python
from NBIN.nbin import *


# An example of an abstract syntax tree in some programming language
code = [
    Command('PRINT', ['Hello world!']),
    [
        'FUNC',
        Block([
            Command('SET', ['a', 14]),
            Command('SET', ['b', 2]),
            Command('SUM', ['a', 'b']),
        ]),
    ],
    Command('CALL', ['FUNC'])
]


# Write to file
with open('test.bin', 'wb') as file:
    result = dump(code)
    file.write()

# Reading from a file
with open('test.bin', 'rb') as file:
    result = load( file.write() )

```


## NBIN data types in Python

NBIN ports the following types to Python:
1. `INT` - data type, for fine-tuning the integer type
2. `Command` - command type
3. `Block` - a type that describes a block


### INT

If you want to create an integer of 1 byte in size, and at the same time so that it can have a sign, then do this:
```python
number = INT('i8', 52)
```

`i8` here is the NBIN data type.
The entire list of these types is stored in the `TYPES_INT` constant, and as an annotation - `LITERAL_TYPES_INT`.
In this case, you need to observe the allowed ranges for each type; they can be taken from the `RANGES_TYPES_INT` constant.


### Command

`Command` allows you to define your variable, with its name and parameters.

Usage example:
```python
cmd = Command('echo', ['Hello world!'])
```

Here: `name` (in the example it is equal to `echo`) is the first parameter of `Command`, and the parameters are passed to the second parameter `Command` in the form of a list, and can be of any type.


### Block

`Block` allows you to combine a list of commands into one block.

Usage example:
```python
func = Block([
    Command('PRINT', ['Hello!']),
    Command('EXIT'),
])
```

**Only a list of commands can be passed into it!**

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "NBIN",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "markada,NBIN,file,storage,HisOS",
    "author": "",
    "author_email": "Markada <markada.py@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/28/84/25566ff7c73bd69775d73acc20fae5700bb4f881a243d56fc10eb3b00e08/NBIN-1.2.tar.gz",
    "platform": null,
    "description": "## What is NBIN\r\n\r\nNBIN is a data serialization format that aims to make it easier to create and store bytecode for arbitrary programming languages. For this purpose, it has special data types, as well as its own binary file structure\r\n\r\nNBIN has its own binary notation format, which can be broadly described as follows:\r\n```bnf\r\n<i8>        ::= 00h <byte>{1}\r\n<i16>       ::= 01h <byte>{2}\r\n<i32>       ::= 02h <byte>{4}\r\n<i64>       ::= 03h <byte>{8}\r\n<u8>        ::= 05h <byte>{1}\r\n<u16>       ::= 06h <byte>{2}\r\n<u32>       ::= 07h <byte>{4}\r\n<u64>       ::= 09h <byte>{8}\r\n<float>     ::= 10h <byte>{4}\r\n<bool>      ::= 11h <byte>\r\n<str>       ::= 12h <lenght> <byte>+\r\n<null>      ::= 13h\r\n<list>      ::= 14h <lenght> <exp>+\r\n<block>     ::= 15h <lenght> <command>+\r\n<command>   ::= 16h <lenght> <byte>+ <lenght> <exp>+\r\n\r\n\r\n/* unsigned int */\r\n<lenght> ::= <byte>{4}\r\n```\r\n\r\n> What is written in \"{ ... }\" is the number of repetitions\r\n\r\nEach version of NBIN defines its own specification, for example the current NBIN (NBIN 1) uses the following specification:\r\n1. Supported data types:\r\n    * i8 - 1 sign byte\r\n    * i16 - 2 sign bytes\r\n    * i32 - 4 sign bytes\r\n    * i64 - 8 sign bytes\r\n    * u8 - 1 unsigned byte\r\n    * u16 - 2 unsigned bytes\r\n    * u32 - 4 unsigned bytes\r\n    * u64 - 8 unsigned bytes\r\n    * str - UNICODE string\r\n    * bool - logical type\r\n    * float - 32-bit fractional number\r\n    * command - command\r\n    * block - block with commands\r\n    * list - not a typed list\r\n    * null - no value\r\n2. The length of any collection NBIN is a 32-bit unsigned number\r\n3. Any NBIN object can be written in a binary file (it is not necessary that everything be wrapped in a block)\r\n4. NBIN tries to support as many types as possible\r\n5. NBIN types should satisfy both low-level and high-level programming needs\r\n\r\n\r\n## NBIN library\r\n\r\nThere are two functions here:\r\n1. `load` - accepts bytes in NBIN format as input and returns a Python object\r\n1. `dump` - takes a Python object as input and returns bytes in NBIN format\r\n\r\nIn general, these two functions deal with object conversion\r\n\r\nUsage example:\r\n```python\r\nfrom NBIN.nbin import *\r\n\r\n\r\n# An example of an abstract syntax tree in some programming language\r\ncode = [\r\n    Command('PRINT', ['Hello world!']),\r\n    [\r\n        'FUNC',\r\n        Block([\r\n            Command('SET', ['a', 14]),\r\n            Command('SET', ['b', 2]),\r\n            Command('SUM', ['a', 'b']),\r\n        ]),\r\n    ],\r\n    Command('CALL', ['FUNC'])\r\n]\r\n\r\n\r\n# Write to file\r\nwith open('test.bin', 'wb') as file:\r\n    result = dump(code)\r\n    file.write()\r\n\r\n# Reading from a file\r\nwith open('test.bin', 'rb') as file:\r\n    result = load( file.write() )\r\n\r\n```\r\n\r\n\r\n## NBIN data types in Python\r\n\r\nNBIN ports the following types to Python:\r\n1. `INT` - data type, for fine-tuning the integer type\r\n2. `Command` - command type\r\n3. `Block` - a type that describes a block\r\n\r\n\r\n### INT\r\n\r\nIf you want to create an integer of 1 byte in size, and at the same time so that it can have a sign, then do this:\r\n```python\r\nnumber = INT('i8', 52)\r\n```\r\n\r\n`i8` here is the NBIN data type.\r\nThe entire list of these types is stored in the `TYPES_INT` constant, and as an annotation - `LITERAL_TYPES_INT`.\r\nIn this case, you need to observe the allowed ranges for each type; they can be taken from the `RANGES_TYPES_INT` constant.\r\n\r\n\r\n### Command\r\n\r\n`Command` allows you to define your variable, with its name and parameters.\r\n\r\nUsage example:\r\n```python\r\ncmd = Command('echo', ['Hello world!'])\r\n```\r\n\r\nHere: `name` (in the example it is equal to `echo`) is the first parameter of `Command`, and the parameters are passed to the second parameter `Command` in the form of a list, and can be of any type.\r\n\r\n\r\n### Block\r\n\r\n`Block` allows you to combine a list of commands into one block.\r\n\r\nUsage example:\r\n```python\r\nfunc = Block([\r\n    Command('PRINT', ['Hello!']),\r\n    Command('EXIT'),\r\n])\r\n```\r\n\r\n**Only a list of commands can be passed into it!**\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Markada  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Official library for working with the BIN file format",
    "version": "1.2",
    "project_urls": null,
    "split_keywords": [
        "markada",
        "nbin",
        "file",
        "storage",
        "hisos"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "942fcc1f6adb34b92a30bab551a62dae4888805989af21677cf3b85a4c91bce0",
                "md5": "945822e70e716506b5768b90ef5ff43c",
                "sha256": "109d0c36432f83ddb0be9f595d923a0d34418a0489924b0701a532b36d3a6b13"
            },
            "downloads": -1,
            "filename": "NBIN-1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "945822e70e716506b5768b90ef5ff43c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 8129,
            "upload_time": "2024-02-23T18:28:14",
            "upload_time_iso_8601": "2024-02-23T18:28:14.426087Z",
            "url": "https://files.pythonhosted.org/packages/94/2f/cc1f6adb34b92a30bab551a62dae4888805989af21677cf3b85a4c91bce0/NBIN-1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "288425566ff7c73bd69775d73acc20fae5700bb4f881a243d56fc10eb3b00e08",
                "md5": "a98fb56d0fcb2deab072e50bed7a554c",
                "sha256": "1d4e0c5817a9e0f6230c58a304220428a5ab7ac7e575c93fab472e503be5c384"
            },
            "downloads": -1,
            "filename": "NBIN-1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a98fb56d0fcb2deab072e50bed7a554c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 7325,
            "upload_time": "2024-02-23T18:28:16",
            "upload_time_iso_8601": "2024-02-23T18:28:16.188521Z",
            "url": "https://files.pythonhosted.org/packages/28/84/25566ff7c73bd69775d73acc20fae5700bb4f881a243d56fc10eb3b00e08/NBIN-1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-23 18:28:16",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nbin"
}
        
Elapsed time: 0.32450s