From 5d0666f9cbeb72a315cfe5260f0a575fc9f2957d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@dronehub.ai>
Date: Wed, 26 May 2021 13:32:29 +0200
Subject: [PATCH] Add files via upload

---
 .dockerignore    |   1 +
 .gitignore       | 258 +++++++++++++++++++++++------------------------
 Dockerfile       |  17 ++++
 LICENSE          |  42 ++++----
 README.md        |  74 +++++++++++++-
 setup.cfg        |  19 ++++
 setup.py         |  24 +++++
 specification.md |  42 ++++++++
 8 files changed, 325 insertions(+), 152 deletions(-)
 create mode 100644 .dockerignore
 create mode 100644 Dockerfile
 create mode 100644 setup.cfg
 create mode 100644 setup.py
 create mode 100644 specification.md

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..46f8b9a
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1 @@
+.git
diff --git a/.gitignore b/.gitignore
index b6e4761..25ff4b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,129 +1,129 @@
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-*$py.class
-
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-build/
-develop-eggs/
-dist/
-downloads/
-eggs/
-.eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-wheels/
-pip-wheel-metadata/
-share/python-wheels/
-*.egg-info/
-.installed.cfg
-*.egg
-MANIFEST
-
-# PyInstaller
-#  Usually these files are written by a python script from a template
-#  before PyInstaller builds the exe, so as to inject date/other infos into it.
-*.manifest
-*.spec
-
-# Installer logs
-pip-log.txt
-pip-delete-this-directory.txt
-
-# Unit test / coverage reports
-htmlcov/
-.tox/
-.nox/
-.coverage
-.coverage.*
-.cache
-nosetests.xml
-coverage.xml
-*.cover
-*.py,cover
-.hypothesis/
-.pytest_cache/
-
-# Translations
-*.mo
-*.pot
-
-# Django stuff:
-*.log
-local_settings.py
-db.sqlite3
-db.sqlite3-journal
-
-# Flask stuff:
-instance/
-.webassets-cache
-
-# Scrapy stuff:
-.scrapy
-
-# Sphinx documentation
-docs/_build/
-
-# PyBuilder
-target/
-
-# Jupyter Notebook
-.ipynb_checkpoints
-
-# IPython
-profile_default/
-ipython_config.py
-
-# pyenv
-.python-version
-
-# pipenv
-#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
-#   However, in case of collaboration, if having platform-specific dependencies or dependencies
-#   having no cross-platform support, pipenv may install dependencies that don't work, or not
-#   install all needed dependencies.
-#Pipfile.lock
-
-# PEP 582; used by e.g. github.com/David-OConnor/pyflow
-__pypackages__/
-
-# Celery stuff
-celerybeat-schedule
-celerybeat.pid
-
-# SageMath parsed files
-*.sage.py
-
-# Environments
-.env
-.venv
-env/
-venv/
-ENV/
-env.bak/
-venv.bak/
-
-# Spyder project settings
-.spyderproject
-.spyproject
-
-# Rope project settings
-.ropeproject
-
-# mkdocs documentation
-/site
-
-# mypy
-.mypy_cache/
-.dmypy.json
-dmypy.json
-
-# Pyre type checker
-.pyre/
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+pip-wheel-metadata/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.python-version
+
+# pipenv
+#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+#   However, in case of collaboration, if having platform-specific dependencies or dependencies
+#   having no cross-platform support, pipenv may install dependencies that don't work, or not
+#   install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..aa2b5e4
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,17 @@
+FROM smokserwis/build:python3
+
+RUN pip install snakehouse Cython satella pytest
+
+WORKDIR /tmp/compile
+ADD minijson /tmp/compile/minijson
+ADD setup.py /tmp/compile/setup.py
+ADD README.md /tmp/compile/README.md
+ADD setup.cfg /tmp/compile/setup.cfg
+
+RUN python setup.py install
+
+WORKDIR /tmp
+
+ADD tests /tmp/tests
+
+CMD ["pytest"]
diff --git a/LICENSE b/LICENSE
index 7954b51..7ca03ba 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,21 +1,21 @@
-MIT License
-
-Copyright (c) 2021 Dronehub
-
-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.
+MIT License
+
+Copyright (c) 2021 Dronehub
+
+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.
diff --git a/README.md b/README.md
index 70c5ff1..a924bd1 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,72 @@
-# minijson
-A compact binary representation for a subset of JSON
+MiniJSON
+========
+
+Usage
+-----
+
+As usual, please [RTFM](minijson/routines.pxd).
+Here's the [specification](specification.md) of MiniJSON
+
+It works pretty the same as pyyaml or json:
+
+```python
+from minijson import dumps, loads
+
+b_bytes = dumps({'hello': 'world'})
+data = loads(b_bytes)
+assert data == {'hello': 'world'}
+
+import io
+from minijson import dump
+
+cio = io.BytesIO()
+dump({'hello': 'world'}, cio)
+```
+
+By defaults floats are encoded as IEEE 754 singles. To force them to be encoded as doubles, do:
+
+```python
+from minijson import switch_default_float, switch_default_double
+
+switch_default_double()
+# now everything is encoded as a double
+switch_default_float()
+# and now as float
+```
+
+Exceptions
+----------
+
+```python
+from minijson import MiniJSONError, EncodingError, DecodingError
+
+assert issubclass(MiniJSONError, ValueError)
+assert issubclass(DecodingError, MiniJSONError)
+assert issubclass(EncodingError, MiniJSONError)
+```
+
+Loading and dumping objects
+---------------------------
+
+Assume you have an object defined like this:
+
+```python
+class Test:
+    def __init__(self, a):
+        self.a = a
+
+    def __eq__(self, o):   
+        """Not necessary"""
+        return self.a == o.a
+```
+
+You can use provided methods to serialize and unserialize it:
+
+```python
+from minijson import loads_object, dumps_object
+
+a = Test(2)
+b = dumps_object(a)
+c = loads_object(b, Test)
+assert a == c
+```
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..5a0ad9b
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,19 @@
+# coding: utf-8
+[metadata]
+name = minijson
+long-description = file: README.md
+long-description-content-type = text/markdown; charset=UTF-8
+author = Piotr Maślanka
+author_email = piotr.maslanka@dronehub.ai
+description = A library for serializing JSON in the MINIJSON format
+url = https://git.cervirobotics.com/dronehub/minijson
+
+[pycodestyle]
+max-line-length = 100
+
+[pep8]
+max-line-length = 100
+
+[bdist_wheel]
+universal = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..3169dc6
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,24 @@
+import os
+from setuptools import find_packages
+from distutils.core import setup
+from snakehouse import Multibuild, build, monkey_patch_parallel_compilation, find_pyx
+
+monkey_patch_parallel_compilation()
+
+build_kwargs = {}
+directives = {'language_level': '3'}
+dont_snakehouse = False
+if 'DEBUG' in os.environ:
+    dont_snakehouse = True
+    build_kwargs.update(gdb_debug=True)
+    directives['embedsignature'] = True
+
+
+setup(version='1.0',
+      packages=find_packages(include=['minijson', 'minijson.*']),
+      ext_modules=build([Multibuild('minijson', find_pyx('minijson'),
+                                    dont_snakehouse=dont_snakehouse), ],
+                        compiler_directives=directives, **build_kwargs),
+      python_requires='!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,!=3.7.*',
+      zip_safe=False
+      )
diff --git a/specification.md b/specification.md
new file mode 100644
index 0000000..d6e57d0
--- /dev/null
+++ b/specification.md
@@ -0,0 +1,42 @@
+MiniJSON specification
+======================
+
+MiniJSON is a binary encoding for a subset of JSON that:
+
+* has no keys longer than 255 bytes UTF-8
+* has no string values longer than 255 bytes UTF-8
+* has no lists longer than 255 elements
+* has no dicts longer than 255 elements
+
+MiniJSON is bigger endian.
+
+Type Value consists of:
+
+* unsigned char value
+* unsigned char * data
+
+* If value's highest bit is turned on, then remains are a UTF-8 string
+with len of (value & 0x7F)
+* If value's two highest bits are 0100 or 0101, then four lowest bits encode the number of elements,
+  and the four highest bits encode type of the object:
+  * 0100 - a list
+  * 0101 - an object
+  Standard representation for an object or list follows,
+  sans the element count.
+* If value is zero, then next character is the length of the string followed by the string
+* If value is 1, then next data is signed int 
+* If value is 2, then next data is signed short
+* If value is 3, then next data is signed char
+* If value is 4, then next data is unsigned int
+* If value is 5, then next data is unsigned short
+* If value is 6, then next data is unsigned char
+* If value is 7, then next data is number of elements of a list, 
+ follows by Value of each element
+* If value is 8, the value is a NULL
+* If value is 9, then next element is a IEEE single
+* If value is 10, then next element is a IEEE double
+* If value is 11, then next element is amount of entries for
+    an object, then there goes the length of the field name,
+    followed by field name in UTF-8, and then goes the Value
+    of the element
+* If value is 12, then next data is unsigned int24
-- 
GitLab